From 63c572c4f0214877e84d82d430e3b18792b06798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Wed, 28 Feb 2018 23:01:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E8=87=B3?= =?UTF-8?q?=203.71?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复:物品列表点击报错 新增:自用 Skript 语法 “taboocode itemcache %string%” --- .../itemlist/listener/ItemLibraryPatch.java | 2 +- .../skymc/taboolib/skript/SkriptHandler.java | 3 ++ .../expression/ExpressionItemCache.java | 3 +- .../expression/ExpressionTabooCodeItem.java | 48 +++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/main/src/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java diff --git a/src/main/src/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java b/src/main/src/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java index e9f5fba..46651dc 100644 --- a/src/main/src/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java +++ b/src/main/src/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java @@ -31,7 +31,7 @@ public class ItemLibraryPatch implements Listener { if (e.getInventory().getHolder() instanceof ItemLibraryHolder) { e.setCancelled(true); - if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR)) { + if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) { return; } diff --git a/src/main/src/me/skymc/taboolib/skript/SkriptHandler.java b/src/main/src/me/skymc/taboolib/skript/SkriptHandler.java index 12cdab8..e2fdb8f 100644 --- a/src/main/src/me/skymc/taboolib/skript/SkriptHandler.java +++ b/src/main/src/me/skymc/taboolib/skript/SkriptHandler.java @@ -1,10 +1,12 @@ package me.skymc.taboolib.skript; +import org.bukkit.Sound; import org.bukkit.inventory.ItemStack; import ch.njol.skript.Skript; import ch.njol.skript.lang.ExpressionType; import me.skymc.taboolib.skript.expression.ExpressionItemCache; +import me.skymc.taboolib.skript.expression.ExpressionTabooCodeItem; /** * @author sky @@ -16,6 +18,7 @@ public class SkriptHandler { private SkriptHandler() { Skript.registerExpression(ExpressionItemCache.class, ItemStack.class, ExpressionType.SIMPLE, "taboolib itemcache %string%"); + Skript.registerExpression(ExpressionTabooCodeItem.class, ItemStack.class, ExpressionType.SIMPLE, "taboocode itemcache %string%"); } public static SkriptHandler getInst() { diff --git a/src/main/src/me/skymc/taboolib/skript/expression/ExpressionItemCache.java b/src/main/src/me/skymc/taboolib/skript/expression/ExpressionItemCache.java index f8ba05c..747114f 100644 --- a/src/main/src/me/skymc/taboolib/skript/expression/ExpressionItemCache.java +++ b/src/main/src/me/skymc/taboolib/skript/expression/ExpressionItemCache.java @@ -41,6 +41,7 @@ public class ExpressionItemCache extends SimpleExpression { @Override protected ItemStack[] get(Event e) { - return new ItemStack[] { ItemUtils.getCacheItem(name.getSingle(e)) }; + ItemStack item = ItemUtils.getCacheItem(name.getSingle(e)); + return new ItemStack[] { item == null ? null : item.clone() }; } } diff --git a/src/main/src/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java b/src/main/src/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java new file mode 100644 index 0000000..637583d --- /dev/null +++ b/src/main/src/me/skymc/taboolib/skript/expression/ExpressionTabooCodeItem.java @@ -0,0 +1,48 @@ +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.taboocode.TabooCodeItem; +import me.skymc.taboolib.inventory.ItemUtils; + +/** + * @author sky + * @since 2018-02-28 15:45:49 + */ +public class ExpressionTabooCodeItem extends SimpleExpression { + + private Expression name; + + @Override + public Class 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) args[0]; + return true; + } + + @Override + public String toString(Event e, boolean arg1) { + return this.getClass().getName(); + } + + @Override + protected ItemStack[] get(Event e) { + ItemStack item = TabooCodeItem.getItem(name.getSingle(e), false); + return new ItemStack[] { item == null ? null : item.clone() }; + } +}