Java 类org.bukkit.event.player.PlayerItemConsumeEvent 实例源码

项目:WC    文件:Thirst.java   
@EventHandler
public void onItemConsume(PlayerItemConsumeEvent e){
    Player p = e.getPlayer();
    ItemStack item = e.getItem();
    Material type = item != null ? item.getType() : Material.AIR;
    int thirst = p.getLevel();

    if (type == Material.POTION && item.getDurability() == 0 && p.getInventory().getItemInMainHand().isSimilar(item)){
        p.getInventory().getItemInMainHand().setType(Material.AIR);

        for (ItemStack i : p.getInventory().getContents()){
            if (i.getType() == Material.GLASS_BOTTLE){
                i.setType(Material.AIR);
            }
        }

        p.setLevel(0);
        if (thirst + 256 >= 1000){
            p.setLevel(1000);
            return;
        }
        p.setLevel(thirst + 256);
        p.sendMessage(p.getLevel() + " // " + thirst + 256);
    }
}
项目:SurvivalPlus    文件:PoisonousPotato.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
    if(event.isCancelled()) return;
    Player player = event.getPlayer();
    if(event.getItem().getType() == Material.POISONOUS_POTATO)
    {
        for (PotionEffect effect : player.getActivePotionEffects())
            player.removePotionEffect(effect.getType());

        Random rand = new Random();
        if(rand.nextInt(10) + 1 <= 6)
        {
            player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0), true);
            player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 0), true);
        }
    }
}
项目:SurvivalPlus    文件:BeetrootStrength.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
    if(event.isCancelled()) return;
    Player player = event.getPlayer();
    if(event.getItem().getType() == Material.BEETROOT)
    {
        int amp = 0;
        int dur = 200;
        for (PotionEffect effect : player.getActivePotionEffects())
        {
            if(effect.getType().equals(PotionEffectType.INCREASE_DAMAGE))
            {
                dur += effect.getDuration();
                if(dur > 600) dur = 600;
                player.removePotionEffect(effect.getType());
            }
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, dur, amp));
    }
}
项目:Thirst    文件:PlayerItemConsumeListener.java   
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{       
    for (String itemString : Thirst.getInstance().getYAMLConfig().thirstQuenchingItems)
    {
        ThirstItem item = Thirst.getInstance().getYAMLConfig().new ThirstItem(itemString);

        ItemStack is = new ItemStack(Material.valueOf(item.getItem()), 1);

        //casting due to spigot api subject to change.
        is.setData(new MaterialData(is.getType(), (byte) item.getMetaData()));

        int quenchPercent = item.getQuenchPercent();

        if (is.getType() == event.getItem().getType() && event.getItem().getData().toString().equals(is.getData().toString())) {
               if (Thirst.getInstance().getYAMLConfig().itemConsumption || ThirstManager.getThirst().getPlayerThirst(event.getPlayer()) != 100)
                   ThirstManager.getThirst().setThirst(event.getPlayer(), ThirstManager.getThirst().getPlayerThirst(event.getPlayer()) + quenchPercent);
               else {
                   event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Thirst.getInstance().getYAMLConfig().itemConsumeMessage.replace("%player%", event.getPlayer().getName())));
                   event.setCancelled(true);
               }
           }
    }
}
项目:WorldGuardExtraFlagsPlugin    文件:PlayerListener.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
    Player player = event.getPlayer();

    if (!WorldGuardUtils.hasBypass(player))
    {
        ItemMeta itemMeta = event.getItem().getItemMeta();
        if (itemMeta instanceof PotionMeta)
        {
            WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
        }
        else
        {
            Material material = event.getItem().getType();
            if (material == Material.MILK_BUCKET)
            {
                WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkMilk(player);
            }
        }
    }
}
项目:Statz    文件:FoodEatenListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEat(final PlayerItemConsumeEvent event) {

    final PlayerStat stat = PlayerStat.FOOD_EATEN;

    // Get player
    final Player player = event.getPlayer();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    final String foodName = StatzUtil.getFoodName(event.getItem());

    if (foodName == null)
        return;

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
            StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "foodEaten", foodName, "world",
                    player.getWorld().getName()));

}
项目:NoStrengthII    文件:DrinkListener.java   
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
    Player player = event.getPlayer();
    ItemStack item = event.getItem();

    // if the item is not a potion we don't want to care.
    if (item == null || item.getType() != Material.POTION) {
        return;
    }

    // if the potion has the durability of a strength 2 potion, tell them and cancel.
    if (item.getDurability() == 8233) {
        player.sendMessage(ChatColor.RED + "Strength II is disabled.");
        event.setCancelled(true);
    }
}
项目:RedProtect    文件:RPMine19.java   
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
    if(e.getItem() == null){
        return;
    }

    Player p = e.getPlayer();
    //deny potion
    if (p == null){
        return;
    }

    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (r != null && e.getItem().getType().equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)){
        RPLang.sendMessage(p, "playerlistener.region.cantuse");
        e.setCancelled(true);
    }
}
项目:RedProtect    文件:RPGlobalListener.java   
@EventHandler
  public void onConsume(PlayerItemConsumeEvent e){
      if(e.getItem() == null){
          return;
      }

      Player p = e.getPlayer();
      Location l = p.getLocation();

      Region r = RedProtect.get().rm.getTopRegion(l);

//deny item usage
List<String> items = RPConfig.getGlobalFlagList(p.getWorld().getName()+".deny-item-usage.items");
    if (e.getItem() != null && items.contains(e.getItem().getType().name())){
        if (r != null && ((!RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-claimed-rps") && r.canBuild(p)) || 
                (RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-claimed-rps") && !r.canBuild(p)))){
            RPLang.sendMessage(p, "playerlistener.region.cantuse");
            e.setCancelled(true);  
            return;
        }
        if (r == null && !RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-wilderness") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.world")){
            RPLang.sendMessage(p, "playerlistener.region.cantuse");
            e.setCancelled(true);
    }
      }
  }
项目:RedProtect    文件:RPPlayerListener.java   
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
    if(e.getItem() == null){
        return;
    }

    Player p = e.getPlayer();
    //deny potion
    if (p == null){
        return;
    }

    if(RPUtil.denyPotion(e.getItem(), p)){
        e.setCancelled(true);                    
    }
}
项目:civcraft    文件:PlayerListener.java   
@EventHandler(priority = EventPriority.LOW) 
public void onConsume(PlayerItemConsumeEvent event) {
    if (ItemManager.getId(event.getItem()) == CivData.GOLDEN_APPLE) {
        CivMessage.sendError(event.getPlayer(), "You cannot use golden apples.");
        event.setCancelled(true);
        return;
    }

    if (event.getItem().getType().equals(Material.POTION)) {
        ConfigTechPotion pot = CivSettings.techPotions.get(Integer.valueOf(event.getItem().getDurability()));
        if (pot != null) {
            if (!pot.hasTechnology(event.getPlayer())) {
                CivMessage.sendError(event.getPlayer(), "You cannot use "+pot.name+" potions. You do not have the technology yet.");
                event.setCancelled(true);
                return;
            }
            if (pot.hasTechnology(event.getPlayer())) {
                event.setCancelled(false);
            }
        } else {
            CivMessage.sendError(event.getPlayer(), "You cannot use this type of potion.");
            event.setCancelled(true);
        }
    }
}
项目:civcraft    文件:BlockListener.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void OnPlayerConsumeEvent(PlayerItemConsumeEvent event) {
    ItemStack stack = event.getItem();

    /* Disable notch apples */
    if (ItemManager.getId(event.getItem()) == ItemManager.getId(Material.GOLDEN_APPLE)) {
        if (event.getItem().getDurability() == (short)0x1) {
            CivMessage.sendError(event.getPlayer(), "You cannot use notch apples. Sorry.");
            event.setCancelled(true);
            return;
        }
    }   

    if (stack.getType().equals(Material.POTION)) {
        int effect = event.getItem().getDurability() & 0x000F;          
        if (effect == 0xE) {
            event.setCancelled(true);
            CivMessage.sendError(event.getPlayer(), "You cannot use invisibility potions for now... Sorry.");
            return;
        }
    }
}
项目:Factoid    文件:PlayerListener.java   
/**
 * On player item consume.
 *
 * @param event the event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {

    Player player = event.getPlayer();
    IPlayerConfEntry entry;

    if((entry = playerConf.get(player)) != null
            && !entry.isAdminMod()) {

        IDummyLand land = Factoid.getThisPlugin().iLands().getLandOrOutsideArea(player.getLocation());

        if (!checkPermission(land, player, PermissionList.EAT.getPermissionType())) {
            messagePermission(player);
            event.setCancelled(true);
        }
    }
}
项目:HoloAPI    文件:IndicatorListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onConsumePotion(PlayerItemConsumeEvent event) {
    if (Settings.INDICATOR_ENABLE.getValue("potion")) {
        if (event.getItem().getType() == Material.POTION) {
            Potion potion = Potion.fromItemStack(event.getItem());
            if (potion != null) {
                this.showPotionHologram(event.getPlayer(), potion.getEffects());
            }
        } else if (event.getItem().getType() == Material.GOLDEN_APPLE) {
            String msg = Settings.INDICATOR_FORMAT.getValue("potion", "goldenapple");
            if (event.getItem().getDurability() == 1) {
                msg = Settings.INDICATOR_FORMAT.getValue("potion", "godapple");
            }
            Location l = event.getPlayer().getLocation().clone();
            l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion"));
            HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, msg.replace("%effect%", "Golden Apple"));
        }
    }
}
项目:CPU    文件:EatsRedstoneApple.java   
@EventHandler
public void onPlayerEat(PlayerItemConsumeEvent e) {
    final Player player = e.getPlayer();
    ItemStack itemConsumed = e.getItem();
    if (itemConsumed.isSimilar(CraftingAndRecipes.redstoneApple())) {
        player.setVelocity(player.getVelocity().setY(0.4));
        player.sendMessage(ChatColor.RED + "[CPU] You just got shocked by eating a redstone apple!");
        player.sendMessage(ChatColor.RED + "[CPU] You can't move that well!");
        CPUPlugin.bukkitScheduler.scheduleSyncDelayedTask(CPUPlugin.plugin, new BukkitRunnable() {
            @Override
            public void run() {
                player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 2000, 1));
                player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 2000, 4));
            }
        }, 60);
    }
}
项目:TCMinigames    文件:PlayerListener.java   
@EventHandler
public void onPotionDrink(PlayerItemConsumeEvent event){
    if(Minigame.getCurrentMinigame()!=null){
        switch(Minigame.getCurrentMinigame().getMap().getType()){
        case CIRCLE_OF_BOOM:
            if(Team.getTeam(event.getPlayer()).equals(Minigame.getObservers())){
                event.setCancelled(true);
            } else {
                if(!Minigame.getCurrentMinigame().getState().equals(MatchState.STARTED)){

                }
            }
            break;
        case KEY_QUEST:
            break;
        case WATER_THE_MONUMENT:
            break;
        default:
            break;
        }
    }
}
项目:AntiPotionField    文件:PlayerEventRegionsHandler.java   
/**
 * Checks to see if the player is attempting to drink a potion, and checks
 * the potion to see if it is allowed.
 *
 * @param event The PlayerItemConsumeEvent involving the player.
 */
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
    if (event.getItem().getType() != Material.POTION) {
        return;
    }
    // Check the type of potion in the player's hand
    Potion potion = Potion.fromItemStack(event.getItem());
    Collection<PotionEffect> effects = potion.getEffects();

    for (PotionEffect e : effects) {
        if (!(Util.canUsePotion(event.getPlayer(), e.getType()))) {
            // If we get here, we cancel this event and all is done.
            event.setCancelled(true);
            event.getPlayer().sendMessage(ChatColor.RED + "You cannot use that potion here!");
            Util.removeDisallowedEffects(event.getPlayer());
            return; // We don't need to check any more.
        }
    }
}
项目:DarkerNights    文件:DarkerNights.java   
/**
 * Fires when an item is consumed. As we are not altering the event,
 * but we do want to know if it is cancelled, we run it on the Monitor
 * priority.
 * 
 * @param event Event to handle.
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onItemConsume(PlayerItemConsumeEvent event) {
    if (event.getItem().getType() == Material.MILK_BUCKET) {
        // We don't want to cancel the event, but we want to re-apply darkness after the event
        // has completed - if needed, so that the player can't cheat using the milk.
        final Player player = event.getPlayer();
        getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {

            @Override
            public void run() {
                DarkerNights.checkBlindness(player);
            }

        });
    }
}
项目:RoyalSurvivors    文件:SurvivorsListener.java   
@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);
            }
        }
    });
}
项目:RoyalSurvivors    文件:SurvivorsListener.java   
@EventHandler
public void onUseHealItem(PlayerItemConsumeEvent e) {
    final Player p = e.getPlayer();
    if (!RUtils.isInInfectedWorld(p)) return;
    final ItemStack hand = e.getItem();
    if (hand == null || hand.getType() != Material.MELON || hand.getDurability() != (short) 14) return;
    if (p.getMaxHealth() == p.getHealth() && p.getFoodLevel() >= 20) {
        e.setCancelled(true); // don't waste medpacks - should never happen, though
        return;
    }
    double newHealth = p.getHealth() + 8D;
    int newFood = p.getFoodLevel() + 8;
    if (newHealth > p.getMaxHealth()) newHealth = p.getMaxHealth();
    if (newFood > 20) newFood = 20;
    p.setHealth(newHealth);
    p.setFoodLevel(newFood);
}
项目:RoyalSurvivors    文件:ThirstListener.java   
@EventHandler
public void onDrinky(PlayerItemConsumeEvent e) {
    final Player p = e.getPlayer();
    final ItemStack hand = e.getItem();
    if (hand == null || hand.getType() != Material.POTION || hand.getDurability() != (short) 0 || !RUtils.isInInfectedWorld(p))
        return;
    PConfManager pcm = PConfManager.getPConfManager(p);
    float thirst = pcm.getFloat("thirst");
    if (!pcm.isSet("thirst")) thirst = 1F;
    if (thirst >= 1F) {
        e.setCancelled(true); // let's not waste water bottles
        return;
    }
    thirst += Config.thirstRestorePercent / 100F;
    if (thirst > 1F) thirst = 1F;
    pcm.set("thirst", thirst);
    pcm.set("thirstSaturation", (float) Config.thirstSaturationMax);
    p.setExp(thirst);
}
项目:Arcadia-Spigot    文件:PotionDropGame.java   
@EventHandler
public void onPotionUse(PlayerItemConsumeEvent event) {
    if(event.getItem().getType() == Material.POTION) {
        new BukkitRunnable() {
            public void run() {
                if(event.getPlayer().isOnline()) {
                    event.getPlayer().getInventory().remove(Material.GLASS_BOTTLE);
                }
            }
        }.runTaskLater(this.getAPI().getPlugin(), 3L);
    }
}
项目:SurvivalPlus    文件:WaterBowl.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
    if(!Survival.settings.getBoolean("Mechanics.Thirst.Enabled"))
    {
        if(event.isCancelled()) return;
        Player player = event.getPlayer();
        if(event.getItem().getType() == Material.BEETROOT_SOUP)
        {
            event.setCancelled(true);
        }
    }
}
项目:SurvivalPlus    文件:RawMeatHunger.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
    if(event.isCancelled()) return;
    Random rand = new Random();
    Player player = event.getPlayer();
    switch(event.getItem().getType())
    {
        case RAW_BEEF:
        case PORK:
        case MUTTON:
        case RAW_FISH:
        case RAW_CHICKEN:
        case ROTTEN_FLESH:
            int hungerChance = rand.nextInt(10) + 1;
            if(hungerChance >= 1 && hungerChance <= 8)
            {
                int dur = 600;
                for (PotionEffect effect : player.getActivePotionEffects())
                {
                    if(effect.getType().equals(PotionEffectType.HUNGER))
                    {
                        dur += effect.getDuration();
                        player.removePotionEffect(effect.getType());
                    }
                }
                player.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, dur, 0, false));
            }
            break;
        default:
    }
}
项目:SurvivalPlus    文件:CookieHealthBoost.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
    if(event.isCancelled()) return;
    Player player = event.getPlayer();
    if(event.getItem().getType() == Material.COOKIE)
    {
        int amp = -1;
        int dur = 600;
        for (PotionEffect effect : player.getActivePotionEffects())
        {
            if(effect.getType().equals(PotionEffectType.HEALTH_BOOST))
            {
                dur += effect.getDuration();
                if(effect.getDuration() >= 300)
                    amp++;
                if(effect.getDuration() >= 1200)
                    amp++;
                if(effect.getDuration() >= 3600)
                    amp++;
                player.removePotionEffect(effect.getType());
            }
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, dur, amp));
        player.setSaturation(player.getSaturation() + 4.6f);
    }
}
项目:Arc-v2    文件:InventoryListener.java   
@EventHandler(priority = EventPriority.LOWEST)
public void onConsume(PlayerItemConsumeEvent event) {
    Player player = event.getPlayer();
    InventoryData data = InventoryData.getData(player);

    boolean canCheckFastConsume = CHECK_MANAGER.canCheckPlayer(player, CheckType.FASTCONSUME);
    if (canCheckFastConsume) {
        // check and cancel if we failed.
        boolean cancel = FAST_CONSUME.check(player, data);
        event.setCancelled(cancel);
    }

}
项目:SurvivalAPI    文件:GameListener.java   
/**
 * Increase the Regeneration boost when a golden apple is eaten
 *
 * @param event Event
 */
@EventHandler
public void onItemConsume(PlayerItemConsumeEvent event)
{
    if (this.game instanceof RunBasedGame && event.getItem().getType() == Material.GOLDEN_APPLE)
        event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 10 * 20, 1));
}
项目:SurvivalAPI    文件:RottenPotionsModule.java   
/**
 * Give a random potion effect when a player eat rotten flesh
 *
 * @param event Event
 */
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
    if (event.getItem().getType() == Material.ROTTEN_FLESH)
    {
        PotionEffectType effectType = PotionEffectType.values()[this.random.nextInt(PotionEffectType.values().length)];

        if (effectType != null)
            event.getPlayer().addPotionEffect(new PotionEffect(effectType, (int) this.moduleConfiguration.get("effect-time") * 20, 1));
    }
}
项目:SurvivalAPI    文件:ConstantPotionModule.java   
/**
 * Set the effect on the player when he consumes
 * a milk bucket
 *
 * @param event Event
 */
@EventHandler(ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
    if (event.getItem().getType() == Material.MILK_BUCKET && SamaGamesAPI.get().getGameManager().getMaxReconnectTime() != -1)
        this.setEffectsOnPlayer(event.getPlayer());
}
项目:SurvivalAPI    文件:RemoveItemOnUseModule.java   
/**
 * Delete the ItemStack
 *
 * @param event Event
 */
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
    if(event.getItem() == null)
        return;

    ItemStack stack = event.getItem();

    if(stack.getType().equals(Material.MUSHROOM_SOUP))
        Bukkit.getScheduler().runTask(this.plugin, () -> event.getPlayer().getInventory().remove(Material.BOWL));
}
项目:SurvivalAPI    文件:CatsEyesModule.java   
/**
 * Re-give the night vision effect if the player drinks milk
 *
 * @param event Event
 */
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
    if (event.getItem().getType() == Material.MILK_BUCKET)
        event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 255, 255));
}
项目:HCFCore    文件:GappleTimer.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
    ItemStack stack = event.getItem();
    if (stack != null && stack.getType() == Material.GOLDEN_APPLE && stack.getDurability() == 1) {
        Player player = event.getPlayer();
        if (setCooldown(player, player.getUniqueId(), defaultCooldown, false, new Predicate<Long>() {
            @Override
            public boolean apply(@Nullable Long value) {
                return false;
            }
        })) {

            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588&e\u2588\u2588&c\u2588\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588\u2588\u2588&e\u2588&c\u2588\u2588\u2588\u2588 &6&l " + this.name + ": ")));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588 &7  Consumed"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&f\u2588&6\u2588&6\u2588\u2588&c\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588&f\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &6 Cooldown Remaining:"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &7  " + DurationFormatter.getRemaining(getRemaining(player), true, false))));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
        } else {
            event.setCancelled(true);
            player.sendMessage(ChatColor.RED + "You still have a " + getDisplayName() + ChatColor.RED + " cooldown for another " + ChatColor.BOLD
                    + DurationFormatter.getRemaining(getRemaining(player), true, false) + ChatColor.RED + '.');
        }
    }
}
项目:HCFCore    文件:GappleTimer.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
    ItemStack stack = event.getItem();
    if (stack != null && stack.getType() == Material.GOLDEN_APPLE && stack.getDurability() == 1) {
        Player player = event.getPlayer();
        if (setCooldown(player, player.getUniqueId(), defaultCooldown, false, new Predicate<Long>() {
            @Override
            public boolean apply(@Nullable Long value) {
                return false;
            }
        })) {

            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588&e\u2588\u2588&c\u2588\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588\u2588\u2588&e\u2588&c\u2588\u2588\u2588\u2588 &6&l " + this.name + ": ")));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588 &7  Consumed"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&f\u2588&6\u2588&6\u2588\u2588&c\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588&f\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &6 Cooldown Remaining:"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &7  " + DurationFormatter.getRemaining(getRemaining(player), true, false))));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
        } else {
            event.setCancelled(true);
            player.sendMessage(ChatColor.RED + "You still have a " + getDisplayName() + ChatColor.RED + " cooldown for another " + ChatColor.BOLD
                    + DurationFormatter.getRemaining(getRemaining(player), true, false) + ChatColor.RED + '.');
        }
    }
}
项目:VanillaPlus    文件:ExtraManager.java   
@EventHandler
public void onEat(PlayerItemConsumeEvent event){
    String type = MinecraftUtils.getExtraType(event.getItem());
    FoodStatus food = ExtraManager.foods.get(type);
    if( food == null )
    if(event.getItem().getType() == Material.GOLDEN_APPLE){
        if(event.getItem().getDurability() == 1){
            type = "napple";
        }else{
            type = "apple";
        }
        food = ExtraManager.foods.get(type);
    }
    if( food == null )
        return;
    event.setCancelled(true);
    VPPlayer playerPlus = VanillaPlusCore.getPlayerManager().getPlayer(event.getPlayer());
    VPPConsumeFoodEvent e = new VPPConsumeFoodEvent(playerPlus, food, type);
    Bukkit.getServer().getPluginManager().callEvent(e);
    if(e.isCancelled())
        return;
    ItemStack item = event.getItem();
    if(item.getAmount() == 1)
        event.getPlayer().setItemInHand(null);
    else{
        item.setAmount(item.getAmount()-1);
        event.getPlayer().setItemInHand(item);
    }
    food.apply(e.getPlayer());

}
项目:NationZ    文件:PlayerDrinkListener.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent pice) {
    if (pice.getItem().getType().equals(Material.MILK_BUCKET)) {
        pice.setCancelled(true);
        for (PotionEffect pe : pice.getPlayer().getActivePotionEffects()) { // clear effects
            pice.getPlayer().removePotionEffect(pe.getType());
        }
        pice.getPlayer().addPotionEffects(NZPlayer.getNZPlayer(pice.getPlayer()).getNation().getEffects());  // re-add potion effects
    }
}
项目:AutomaticInventory    文件:AIEventHandler.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onConsumeItem(PlayerItemConsumeEvent event)
{
    Player player = event.getPlayer();
    PlayerInventory inventory = player.getInventory();
    EquipmentSlot slot = this.getSlotWithItemStack(inventory, event.getItem());
    tryRefillStackInHand(player, slot, true);
}
项目:BeeLogin    文件:EventCanceler.java   
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerItemConsume(PlayerItemConsumeEvent evt) {
    if (!usingBeeLoginMod)
        return;
    Player player = evt.getPlayer();
    if (!loginStatus.get(player.getName().toLowerCase())) {
        evt.setCancelled(true);
    }
}
项目:QuestGUI    文件:Eating.java   
@EventHandler
public void onEvent(PlayerItemConsumeEvent e){
    String QuestName = Main.data.getString(e.getPlayer().getName() + ".temp-questname");
    Eating ee = new Eating(e.getPlayer(), QuestName);
    Player p = e.getPlayer();
    if(ee.isGoing() && ee.isObjective()){
        if(e.getItem().getItemMeta().hasDisplayName()){
            if(e.getItem().getItemMeta().getDisplayName().equals(ee.getFood(QuestName))){
                if(ee.getNowData() < ee.getData(QuestName)){
                    Main.data.set(p.getName() + "." + ee.getQuestName() + "-data", ee.getNowData() + 1);
                    Main.saveconfig();
                }
                else if(ee.getNowData() == ee.getData(QuestName)){
                    p.sendMessage(Main.PREFIX + "§e" + ee.getQuestName() + "§6퀘스트를 완료 하였습니다! NPC에게 찾아가보세요!");
                    Main.data.set(p.getName() + "." + ee.getQuestName() + "-data", null);
                    Main.data.set(p.getName() + ".temp-questname", null);
                    Main.data.set(p.getName() + "." + ee.getQuestName() + "-ing", null);
                    Main.data.set(p.getName() + "." + ee.getQuestName() + "-done", true);
                    Main.saveconfig();
                }
            }
        }
        else{
            if(e.getItem().getTypeId() == Integer.parseInt(ee.getFood(QuestName))){
                if(ee.getNowData() < ee.getData(QuestName)){
                    Main.data.set(p.getName() + "." + ee.getQuestName() + "-data", ee.getNowData() + 1);
                    Main.saveconfig();
                }
                else if(ee.getNowData() == ee.getData(QuestName)){
                    p.sendMessage(Main.PREFIX + "§e" + ee.getQuestName() + "§6퀘스트를 완료 하였습니다! NPC에게 찾아가보세요!");
                    Main.data.set(p.getName() + "." + ee.getQuestName() + "-data", null);
                    Main.data.set(p.getName() + ".temp-questname", null);
                    Main.data.set(p.getName() + "." + ee.getQuestName() + "-ing", null);
                    Main.data.set(p.getName() + "." + ee.getQuestName() + "-done", true);
                    Main.saveconfig();
                }
            }
        }
    }
}
项目:QuestManager    文件:QuestPlayer.java   
@EventHandler
public void onFoodEat(PlayerItemConsumeEvent e) {
    if (e.getPlayer().getUniqueId().equals(getPlayer().getUniqueId())) {
        //do mana regen, if it counts as food
        if (QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getMagicEnabled()
                 && QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getMagicRegenFood() != 0)
        switch (e.getItem().getType()) {
        case RAW_BEEF:
        case COOKED_BEEF:
        case RAW_CHICKEN:
        case COOKED_CHICKEN:
        case APPLE:
        case CARROT_ITEM:
        case BAKED_POTATO:
        case POTATO_ITEM:
        case BREAD:
        case COOKED_FISH:
        case COOKED_MUTTON:
        case COOKED_RABBIT:
        case COOKIE:
        case GRILLED_PORK:
        case MELON:
        case MUSHROOM_SOUP:
        case MUTTON:
        case PORK:
        case PUMPKIN_PIE:
        case RABBIT:
        case RABBIT_STEW:
        case RAW_FISH:  
            double amt = QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getMagicRegenFood();
            regenMP(amt);   
            break;
        default:
            break;
        }
    }
}
项目:ExilePearl    文件:ExileListener.java   
/**
 * Prevent exiled players from drinking potions
 * @param e The event
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerDrinkPotion(PlayerItemConsumeEvent e) {
    if(e.getItem().getType() == Material.POTION) {
        if (pearlApi.getBrewHandler().isBrew(e.getItem())) {
            checkAndCancelRule(ExileRule.DRINK_BREWS, e, e.getPlayer());
        } else {
            checkAndCancelRule(ExileRule.USE_POTIONS, e, e.getPlayer());
        }
    }
}