use of org.bukkit.event.player.PlayerItemConsumeEvent in project Glowstone by GlowstoneMC.
the class ItemFood method eat.
public boolean eat(GlowPlayer player, ItemStack item) {
PlayerItemConsumeEvent event1 = new PlayerItemConsumeEvent(player, item);
EventFactory.callEvent(event1);
if (event1.isCancelled())
return false;
FoodLevelChangeEvent event2 = new FoodLevelChangeEvent(player, getFoodLevel(item) + player.getFoodLevel());
EventFactory.callEvent(event2);
if (!event2.isCancelled()) {
player.setFoodLevelAndSaturation(event2.getFoodLevel(), getSaturation(item));
}
player.setUsageItem(null);
player.setUsageTime(0);
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
} else {
player.getInventory().clear(player.getInventory().getHeldItemSlot());
}
return true;
}
use of org.bukkit.event.player.PlayerItemConsumeEvent in project Glowstone by GlowstoneMC.
the class ItemMilk method eat.
@Override
public boolean eat(GlowPlayer player, ItemStack item) {
PlayerItemConsumeEvent event1 = new PlayerItemConsumeEvent(player, item);
EventFactory.callEvent(event1);
if (event1.isCancelled())
return false;
player.setUsageItem(null);
player.setUsageTime(0);
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
player.removePotionEffect(potionEffect.getType());
}
player.getInventory().getItemInHand().setType(Material.BUCKET);
return true;
}
Aggregations