/**
* 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.
}
}
}
PlayerEventRegionsHandler.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:AntiPotionField
作者:
评论列表
文章目录