有沒有人有一個想法,爲什麼這個事件不起作用?PrepareItemCraftEvent問題 - 無法傳遞事件PrepareItemCraftEvent
OnEnable代碼:
Bukkit.getServer().getPluginManager().registerEvents(this, this);
事件代碼:
@EventHandler(priority=EventPriority.HIGH)
public void customCrafting(PrepareItemCraftEvent e){
ItemStack singleCompressed = new ItemStack(Material.COBBLESTONE, 1);
ItemStack nineCobblestone = new ItemStack(Material.COBBLESTONE, 9);
ItemMeta singleCompressedMeta = singleCompressed.getItemMeta();
singleCompressedMeta.setDisplayName("Compressed Cobblestone");
singleCompressedMeta.setLore(Arrays.asList("x9 Cobblestone"));
singleCompressed.setItemMeta(singleCompressedMeta);
if(e.getInventory() instanceof CraftingInventory){
CraftingInventory inv = (CraftingInventory) e.getInventory();
ItemStack[] itm = inv.getMatrix();
boolean canCraft = false;
if (inv.getResult().getType() == Material.COBBLESTONE) {
for (int i = 0; i < inv.getSize(); i++) {
if(itm[i].getItemMeta().getLore().toString().toLowerCase().equals(singleCompressed.getItemMeta().getLore().toString().toLowerCase())) {
canCraft = true;
}
}
if (canCraft == true) {
inv.setResult(nineCobblestone);
canCraft = false;
} else {
inv.setResult(null);
canCraft = false;
}
}
}
}
我有這些配方在公共無效的設立是由onEnable稱爲:
ShapedRecipe singleCompressedRecipe = new ShapedRecipe(singleCompressed);
singleCompressedRecipe.shape("@@@","@@@","@@@");
singleCompressedRecipe.setIngredient('@', Material.COBBLESTONE);
ItemStack nineCobblestone = new ItemStack(Material.COBBLESTONE, 9);
ShapelessRecipe decompressedRecipe = new ShapelessRecipe(nineCobblestone);
decompressedRecipe.addIngredient(Material.COBBLESTONE);
Bukkit.getServer().addRecipe(singleCompressedRecipe);
Bukkit.getServer().addRecipe(decompressedRecipe);
出於某種原因每當我嘗試相應地製作時,我都會在控制檯中看到這些錯誤:
10:00:34 PM CONSOLE: ERROR]: Could not pass event PrepareItemCraftEvent to CompressedBlocks v1.0
10:00:35 PM CONSOLE: Source) [?:1.7.0_60]
10:00:35 PM CONSOLE: Source) [?:1.7.0_60]
10:00:35 PM CONSOLE: Source) [?:1.7.0_60]
10:00:35 PM CONSOLE: Method) ~[?:1.7.0_60]
10:00:35 PM CONSOLE: Source) ~[?:1.7.0_60]
10:00:35 PM CONSOLE: Source) ~[?:1.7.0_60]
10:00:35 PM CONSOLE: Source) ~[?:1.7.0_60]
就遊戲中發生的事情而言,您可以從常規和單個壓縮鵝卵石中製作9塊鵝卵石,因此不會受到事件的影響。我試圖登錄到控制檯:itm [i] .getItemMeta()。getLore()。toString()。toLowerCase()它只是等於null。
您能否包含整個錯誤消息?這可以幫助很多。 – Jojodmo
這實際上是給出的全部錯誤消息,100%。 – Keydose
這真的很奇怪。你有沒有在服務器上使用插件加載器? – Jojodmo