所以,我正在使用Bukkit API。基本上,我正在尋找被調用的PlayerInteractEvent,然後我做了一堆事情。但是,當我得到通知我實際上已經踢掉了該塊時,即使它在我的代碼中編譯沒有錯誤,我也沒有收到任何消息。我也沒有從控制檯獲得例外。這裏是我的代碼:爲什麼PlayerInteractEvent不適用於Bukkit API?
@EventHandler(priority=EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event, final Player who, final Action action,
final ItemStack item, final Block clickedBlock, final BlockFace clickedFace) {
if (who != null) {
if (clickedBlock != null) {
if ((action == Action.LEFT_CLICK_BLOCK) && (clickedBlock.getType() == Material.ANVIL)) {
if (item == null) {
who.sendMessage(ChatColor.YELLOW + "To repair an item, hold it in your inventory and " +
ChatColor.UNDERLINE + "RIGHT CLICK" + ChatColor.RESET + "" + ChatColor.YELLOW +
" the anvil with the item.");
event.setCancelled(true);
}
else {
Material type = item.getType();
short durability = item.getDurability();
short maximum = type.getMaxDurability();
if (maximum == 0) {
who.sendMessage(ChatColor.RED + "You can " + ChatColor.UNDERLINE + "NOT" +
ChatColor.RESET + "" + ChatColor.RED + " repair that item.");
}
else {
short add = (short) Math.round(maximum * 0.03);
int result = (maximum - durability)/add;
int gems = getAmount(who, 388);
if (gems < result) {
who.sendMessage(ChatColor.RED + "You do " + ChatColor.UNDERLINE + "NOT" +
ChatColor.RESET + "" + ChatColor.RED + " have enough Gems to repair "
+ "that item.");
who.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Gems Needed: " + result);
}
else {
who.sendMessage(ChatColor.YELLOW + "It will cost " + ChatColor.WHITE +
result + "g " + ChatColor.GREEN + "to repair this item.");
who.sendMessage(ChatColor.YELLOW + "Continue repairing? " + ChatColor.GREEN +
"" + ChatColor.BOLD + "Y" + ChatColor.RESET + "" + ChatColor.WHITE +
"/" + ChatColor.RESET + "" + ChatColor.RED + "" + ChatColor.BOLD +
"N");
map.put(who, item);
}
}
}
}
}
}
}
我已經這樣做了,所以我不確定還有什麼可能是問題。 – user2646941