版本更新至 3.7

新增:Skript 扩展语法 "taboolib itemcache %string%" 获取缓存物品
修复:ItemUtils 工具内 setAttribute() 方法的语法错误。
master
坏黑 2018-02-28 16:07:21 +08:00
parent 13a9bb5f75
commit a73115f277
4 changed files with 85 additions and 2 deletions

View File

@ -47,6 +47,7 @@ import me.skymc.taboolib.message.ChatCatcher;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.mysql.protect.MySQLConnection;
import me.skymc.taboolib.sign.SignUtils;
import me.skymc.taboolib.skript.SkriptHandler;
import me.skymc.taboolib.string.StringUtils;
import me.skymc.taboolib.string.language2.Language2;
import me.skymc.taboolib.support.SupportPlaceholder;
@ -194,6 +195,8 @@ public class Main extends JavaPlugin implements Listener {
JavaShell.javaShellSetup();
// 载入语言文件
exampleLangauge2 = new Language2("Language2", this);
// 注册脚本
SkriptHandler.getInst();
// 启动数据库储存方法
if (getStorageType() == StorageType.SQL) {

View File

@ -569,13 +569,16 @@ public class ItemUtils {
NBTList attr = nbt.getList("AttributeModifiers", NBTType.NBTTagCompound);
if (asAttribute(name) != null) {
try {
NBTListCompound _attr = attr.addCompound();
NBTListCompound _attr = null;
for (int i = 0 ; i < attr.size() ; i++) {
NBTListCompound nlc = attr.getCompound(i);
if (nlc.getString("AttributeName").equals("name")) {
if (nlc.getString("AttributeName").equals(asAttribute(name))) {
_attr = nlc;
}
}
if (_attr == null) {
_attr = attr.addCompound();
}
if (num.toString().contains("%")) {
_attr.setDouble("Amount", Double.valueOf(num.toString().replace("%", "")) / 100D);
_attr.setInteger("Operation", 1);

View File

@ -0,0 +1,31 @@
package me.skymc.taboolib.skript;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.ExpressionType;
import me.skymc.taboolib.skript.expression.ExpressionItemCache;
/**
* @author sky
* @since 2018-02-28 15:40:55
*/
public class SkriptHandler {
private static SkriptHandler inst = null;
private SkriptHandler() {
Skript.registerExpression(ExpressionItemCache.class, ItemStack.class, ExpressionType.SIMPLE, "taboolib itemcache %string%");
}
public static SkriptHandler getInst() {
if (inst == null) {
synchronized (SkriptHandler.class) {
if (inst == null) {
inst = new SkriptHandler();
}
}
}
return inst;
}
}

View File

@ -0,0 +1,46 @@
package me.skymc.taboolib.skript.expression;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import me.skymc.taboolib.inventory.ItemUtils;
/**
* @author sky
* @since 2018-02-28 15:45:49
*/
public class ExpressionItemCache extends SimpleExpression<ItemStack> {
private Expression<String> name;
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] args, int arg1, Kleenean arg2, ParseResult arg3) {
name = (Expression<String>) args[0];
return true;
}
@Override
public String toString(Event e, boolean arg1) {
return this.getClass().getName();
}
@Override
protected ItemStack[] get(Event e) {
return new ItemStack[] { ItemUtils.getCacheItem(name.getSingle(e)) };
}
}