PlayerEventRegionsHandler.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:AntiPotionField 作者:
/**
 * 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.
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号