Skip to content

Commit 149aa4c

Browse files
committed
版本更新至 3.7
新增:Skript 扩展语法 "taboolib itemcache %string%" 获取缓存物品 修复:ItemUtils 工具内 setAttribute() 方法的语法错误。
1 parent 47a26ba commit 149aa4c

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

src/main/src/me/skymc/taboolib/Main.java

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import me.skymc.taboolib.message.MsgUtils;
4848
import me.skymc.taboolib.mysql.protect.MySQLConnection;
4949
import me.skymc.taboolib.sign.SignUtils;
50+
import me.skymc.taboolib.skript.SkriptHandler;
5051
import me.skymc.taboolib.string.StringUtils;
5152
import me.skymc.taboolib.string.language2.Language2;
5253
import me.skymc.taboolib.support.SupportPlaceholder;
@@ -194,6 +195,8 @@ public void onEnable() {
194195
JavaShell.javaShellSetup();
195196
// 载入语言文件
196197
exampleLangauge2 = new Language2("Language2", this);
198+
// 注册脚本
199+
SkriptHandler.getInst();
197200

198201
// 启动数据库储存方法
199202
if (getStorageType() == StorageType.SQL) {

src/main/src/me/skymc/taboolib/inventory/ItemUtils.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,16 @@ public static NBTItem setAttribute(NBTItem nbt, String name, Object num, String
569569
NBTList attr = nbt.getList("AttributeModifiers", NBTType.NBTTagCompound);
570570
if (asAttribute(name) != null) {
571571
try {
572-
NBTListCompound _attr = attr.addCompound();
572+
NBTListCompound _attr = null;
573573
for (int i = 0 ; i < attr.size() ; i++) {
574574
NBTListCompound nlc = attr.getCompound(i);
575-
if (nlc.getString("AttributeName").equals("name")) {
575+
if (nlc.getString("AttributeName").equals(asAttribute(name))) {
576576
_attr = nlc;
577577
}
578578
}
579+
if (_attr == null) {
580+
_attr = attr.addCompound();
581+
}
579582
if (num.toString().contains("%")) {
580583
_attr.setDouble("Amount", Double.valueOf(num.toString().replace("%", "")) / 100D);
581584
_attr.setInteger("Operation", 1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.skymc.taboolib.skript;
2+
3+
import org.bukkit.inventory.ItemStack;
4+
5+
import ch.njol.skript.Skript;
6+
import ch.njol.skript.lang.ExpressionType;
7+
import me.skymc.taboolib.skript.expression.ExpressionItemCache;
8+
9+
/**
10+
* @author sky
11+
* @since 2018-02-28 15:40:55
12+
*/
13+
public class SkriptHandler {
14+
15+
private static SkriptHandler inst = null;
16+
17+
private SkriptHandler() {
18+
Skript.registerExpression(ExpressionItemCache.class, ItemStack.class, ExpressionType.SIMPLE, "taboolib itemcache %string%");
19+
}
20+
21+
public static SkriptHandler getInst() {
22+
if (inst == null) {
23+
synchronized (SkriptHandler.class) {
24+
if (inst == null) {
25+
inst = new SkriptHandler();
26+
}
27+
}
28+
}
29+
return inst;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package me.skymc.taboolib.skript.expression;
2+
3+
import org.bukkit.event.Event;
4+
import org.bukkit.inventory.ItemStack;
5+
6+
import ch.njol.skript.lang.Expression;
7+
import ch.njol.skript.lang.SkriptParser.ParseResult;
8+
import ch.njol.skript.lang.util.SimpleExpression;
9+
import ch.njol.util.Kleenean;
10+
import me.skymc.taboolib.inventory.ItemUtils;
11+
12+
/**
13+
* @author sky
14+
* @since 2018-02-28 15:45:49
15+
*/
16+
public class ExpressionItemCache extends SimpleExpression<ItemStack> {
17+
18+
private Expression<String> name;
19+
20+
@Override
21+
public Class<? extends ItemStack> getReturnType() {
22+
return ItemStack.class;
23+
}
24+
25+
@Override
26+
public boolean isSingle() {
27+
return true;
28+
}
29+
30+
@SuppressWarnings("unchecked")
31+
@Override
32+
public boolean init(Expression<?>[] args, int arg1, Kleenean arg2, ParseResult arg3) {
33+
name = (Expression<String>) args[0];
34+
return true;
35+
}
36+
37+
@Override
38+
public String toString(Event e, boolean arg1) {
39+
return this.getClass().getName();
40+
}
41+
42+
@Override
43+
protected ItemStack[] get(Event e) {
44+
return new ItemStack[] { ItemUtils.getCacheItem(name.getSingle(e)) };
45+
}
46+
}

0 commit comments

Comments
 (0)