我正在为Spigot写一个类,它定义了许多新的制作配方。但是,当我调用一个事件时,它似乎会抛出一个Assertion Error: TRAP
。
我已经研究了很多,没有找到有用的提示或其他任何内容。
Items.java
package com.myththewolf.omnomnom.lib;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
public class Items {
private static HashMap<ItemStack,Integer> items = new HashMap<ItemStack,Integer>();
private static List<ShapedRecipe> itemC = new ArrayList<ShapedRecipe>();
public ItemStack setMeta(ItemStack material, String name, List<String> lore)
{
if (((material == null) || material.getType() == Material.AIR) || ((name == null && lore == null)))
{
return null;
}
ItemMeta im = material.getItemMeta();
if (name != null)
{
im.setDisplayName(name);
}
if (lore != null)
{
im.setLore(lore);
}
material.setItemMeta(im);
return material;
}
public static void makeRecipies()
{
ItemStack skull;
skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
SkullMeta SM;
SM = (SkullMeta) skull.getItemMeta();
SM.setOwner("MHF_CHEST");
skull.setItemMeta(SM);
addRecipie(3, "CCC", "BAB", "CCC", skull, Material.COOKED_BEEF, Material.BREAD, Material.AIR);
for(ShapedRecipe sr : itemC)
{
Bukkit.getServer().addRecipe(sr);
}
}
public static HashMap<ItemStack,Integer> getItems()
{
return items;
}
public static void addRecipie(int hung,String patA, String patB, String patC, ItemStack out, Material a, Material b, Material c)
{
ShapedRecipe rec = new ShapedRecipe(out);
rec.shape(patA,patB,patC);
rec.setIngredient('A', a);
rec.setIngredient('B', b);
rec.setIngredient('C', c);
items.put(out, hung);
itemC.add(rec);
}
}
RightClickEvent.java
package com.myththewolf.omnomnom.event;
import java.util.HashMap;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.myththewolf.omnomnom.lib.Items;
public class RightClickEvent implements Listener {
@EventHandler
public void onInteractEvent(PlayerInteractEvent e)
{
Action a= e.getAction();
if(a == Action.RIGHT_CLICK_BLOCK || a== Action.RIGHT_CLICK_AIR)
{
final HashMap<ItemStack,Integer> items = Items.getItems();
if(items.containsKey(e.getItem()))
{
int foodL = e.getPlayer().getFoodLevel();
e.getPlayer().setFoodLevel(foodL + items.get(e.getItem()));
ItemStack hand = e.getPlayer().getItemInHand();
int amount = hand.getAmount();
if (amount > 1) {
hand.setAmount(amount - 1);
e.getPlayer().setItemInHand(hand);
} else {
e.getPlayer().setItemInHand(new ItemStack(Material.AIR));
}
}
}
}
}
这是堆栈跟踪:
[22:50:18 FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.AssertionError: TRAP
at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_101]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_101]
at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:47) [spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:675) [spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:574) [spigot.jar:git-Spigot-f950f8e-4f47972]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
Caused by: java.lang.AssertionError: TRAP
at net.minecraft.server.v1_11_R1.ItemStack.F(ItemStack.java:86) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemStack.setCount(ItemStack.java:814) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemStack.add(ItemStack.java:818) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemStack.subtract(ItemStack.java:822) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemSkull.a(ItemSkull.java:79) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.ItemStack.placeItem(ItemStack.java:152) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PlayerInteractManager.a(PlayerInteractManager.java:491) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:897) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:37) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_101]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_101]
at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) ~[spigot.jar:git-Spigot-f950f8e-4f47972]
... 5 more
究竟是什么错误?
我做错了吗?
答案 0 :(得分:0)
看起来你正在允许一个被放置的块被玩家的手中的空气替换。
AssertionError。解决方案是取消PlayerInteractEvent