2016-05-12 19:40:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
|
|
import org.bukkit.ChatColor;
|
2018-01-07 19:33:58 +00:00
|
|
|
import org.bukkit.entity.LingeringPotion;
|
|
|
|
import org.bukkit.entity.ThrownPotion;
|
2016-05-12 19:40:39 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.entity.PotionSplashEvent;
|
2018-01-07 19:33:58 +00:00
|
|
|
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
2016-05-12 19:40:39 +00:00
|
|
|
import org.bukkit.projectiles.ProjectileSource;
|
2018-01-07 19:33:58 +00:00
|
|
|
import java.util.Collection;
|
2016-05-12 19:40:39 +00:00
|
|
|
|
|
|
|
public class PotionBlocker extends FreedomService
|
|
|
|
{
|
|
|
|
|
|
|
|
public static final int POTION_BLOCK_RADIUS_SQUARED = 20 * 20;
|
|
|
|
|
|
|
|
public PotionBlocker(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
|
|
public void onThrowPotion(PotionSplashEvent event)
|
|
|
|
{
|
2018-01-07 19:33:58 +00:00
|
|
|
ThrownPotion potion = event.getEntity();
|
|
|
|
ProjectileSource projectileSource = potion.getShooter();
|
|
|
|
Player player = null;
|
|
|
|
if (projectileSource instanceof Player)
|
|
|
|
{
|
2018-07-31 06:41:56 +00:00
|
|
|
player = (Player) projectileSource;
|
2018-01-07 19:33:58 +00:00
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
|
2018-01-07 19:33:58 +00:00
|
|
|
if (isDeathPotion(potion.getEffects()))
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2018-01-07 19:33:58 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.RED + "You are not allowed to use death potions.");
|
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2018-01-07 19:33:58 +00:00
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
|
2018-01-07 19:33:58 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
|
|
public void onThrowLingeringPotion(LingeringPotionSplashEvent event)
|
|
|
|
{
|
|
|
|
LingeringPotion potion = event.getEntity();
|
|
|
|
ProjectileSource projectileSource = potion.getShooter();
|
|
|
|
Player player = null;
|
|
|
|
if (projectileSource instanceof Player)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2018-07-31 06:41:56 +00:00
|
|
|
player = (Player) projectileSource;
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 19:33:58 +00:00
|
|
|
if (isDeathPotion(potion.getEffects()))
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2018-01-07 19:33:58 +00:00
|
|
|
if (player != null)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2018-01-07 19:33:58 +00:00
|
|
|
player.sendMessage(ChatColor.RED + "You are not allowed to use death potions.");
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
2018-01-07 19:33:58 +00:00
|
|
|
event.setCancelled(true);
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
2018-01-07 19:33:58 +00:00
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
|
2018-01-07 19:33:58 +00:00
|
|
|
public boolean isDeathPotion(Collection<PotionEffect> effects)
|
|
|
|
{
|
|
|
|
for (PotionEffect effect : effects)
|
|
|
|
{
|
|
|
|
if (effect.getType().equals(PotionEffectType.HEAL) && effect.getAmplifier() == 125)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|