Search in sources :

Example 1 with PlayerItemConsumeEvent

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;
}
Also used : PlayerItemConsumeEvent(org.bukkit.event.player.PlayerItemConsumeEvent) FoodLevelChangeEvent(org.bukkit.event.entity.FoodLevelChangeEvent)

Example 2 with PlayerItemConsumeEvent

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;
}
Also used : PlayerItemConsumeEvent(org.bukkit.event.player.PlayerItemConsumeEvent) PotionEffect(org.bukkit.potion.PotionEffect)

Aggregations

PlayerItemConsumeEvent (org.bukkit.event.player.PlayerItemConsumeEvent)2 FoodLevelChangeEvent (org.bukkit.event.entity.FoodLevelChangeEvent)1 PotionEffect (org.bukkit.potion.PotionEffect)1