版本更新至 3.71

修复:物品列表点击报错
新增:自用 Skript 语法 “taboocode itemcache %string%”
This commit is contained in:
坏黑 2018-02-28 23:01:08 +08:00
parent a73115f277
commit 63c572c4f0
4 changed files with 54 additions and 2 deletions

View File

@ -31,7 +31,7 @@ public class ItemLibraryPatch implements Listener {
if (e.getInventory().getHolder() instanceof ItemLibraryHolder) { if (e.getInventory().getHolder() instanceof ItemLibraryHolder) {
e.setCancelled(true); 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; return;
} }

View File

@ -1,10 +1,12 @@
package me.skymc.taboolib.skript; package me.skymc.taboolib.skript;
import org.bukkit.Sound;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript; import ch.njol.skript.Skript;
import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.ExpressionType;
import me.skymc.taboolib.skript.expression.ExpressionItemCache; import me.skymc.taboolib.skript.expression.ExpressionItemCache;
import me.skymc.taboolib.skript.expression.ExpressionTabooCodeItem;
/** /**
* @author sky * @author sky
@ -16,6 +18,7 @@ public class SkriptHandler {
private SkriptHandler() { private SkriptHandler() {
Skript.registerExpression(ExpressionItemCache.class, ItemStack.class, ExpressionType.SIMPLE, "taboolib itemcache %string%"); 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() { public static SkriptHandler getInst() {

View File

@ -41,6 +41,7 @@ public class ExpressionItemCache extends SimpleExpression<ItemStack> {
@Override @Override
protected ItemStack[] get(Event e) { 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() };
} }
} }

View File

@ -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<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) {
ItemStack item = TabooCodeItem.getItem(name.getSingle(e), false);
return new ItemStack[] { item == null ? null : item.clone() };
}
}