2016-05-12 19:40:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
|
2018-07-31 07:01:29 +00:00
|
|
|
import java.util.Collection;
|
2016-05-12 19:40:39 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.entity.Player;
|
2018-07-31 07:01:29 +00:00
|
|
|
import org.bukkit.entity.ThrownPotion;
|
2016-05-12 19:40:39 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
2018-01-07 19:33:58 +00:00
|
|
|
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
2018-07-31 07:01:29 +00:00
|
|
|
import org.bukkit.event.entity.PotionSplashEvent;
|
2018-01-07 19:33:58 +00:00
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
2016-05-12 19:40:39 +00:00
|
|
|
import org.bukkit.projectiles.ProjectileSource;
|
|
|
|
|
|
|
|
public class PotionBlocker extends FreedomService
|
|
|
|
{
|
|
|
|
|
|
|
|
public static final int POTION_BLOCK_RADIUS_SQUARED = 20 * 20;
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 07:01:29 +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)
|
|
|
|
{
|
2019-07-17 19:35:36 +00:00
|
|
|
ThrownPotion potion = event.getEntity();
|
2018-01-07 19:33:58 +00:00
|
|
|
ProjectileSource projectileSource = potion.getShooter();
|
|
|
|
Player player = null;
|
|
|
|
if (projectileSource instanceof Player)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2018-07-31 07:01:29 +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)
|
|
|
|
{
|
2019-09-15 16:49:24 +00:00
|
|
|
int amplifier = effect.getAmplifier();
|
|
|
|
if (effect.getType().equals(PotionEffectType.HEAL) && (amplifier == 29 || amplifier == 61 || amplifier == 93 || amplifier == 125))
|
2018-01-07 19:33:58 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|