所以,我正在使用 Bukkit API。基本上,我正在寻找要调用的 PlayerInteractEvent,然后我会做很多事情。但是,当我收到通知说我实际上踢了该块时,我没有收到任何消息,即使它在我的代码中编译时没有错误。我也没有从控制台获得任何例外。这是我的代码:
@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);
}
}
}
}
}
}
}