@EventHandler
public void onHealItemFullFood(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) return;
final Player p = e.getPlayer();
if (!RUtils.isInInfectedWorld(p) || p.getFoodLevel() < 20) return;
final ItemStack hand = e.getItem();
if (hand == null || hand.getType() != Material.MELON || hand.getDurability() != (short) 14) return;
if (p.getHealth() >= p.getMaxHealth() && p.getFoodLevel() >= 20) return; // don't waste
onUseHealItem(new PlayerItemConsumeEvent(p, hand));
// until Bukkit fixes removing the last item in interact events, workaround
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
for (int slot = 0; slot < p.getInventory().getSize(); slot++) {
ItemStack is = p.getInventory().getItem(slot);
if (is == null) continue;
if (!is.equals(hand)) continue;
is.setAmount(is.getAmount() - 1);
p.getInventory().setItem(slot, is);
}
}
});
}
SurvivorsListener.java 文件源码
java
阅读 37
收藏 0
点赞 0
评论 0
项目:RoyalSurvivors
作者:
评论列表
文章目录