mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-16 20:36:12 +00:00
4f339b29b8
Blocks all known death potions as it's possible to use amplifier 29, 61, 93 and 125 to get the same effect from it.
93 lines
2.6 KiB
Java
93 lines
2.6 KiB
Java
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
import java.util.Collection;
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.entity.ThrownPotion;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventPriority;
|
|
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
|
import org.bukkit.event.entity.PotionSplashEvent;
|
|
import org.bukkit.potion.PotionEffect;
|
|
import org.bukkit.potion.PotionEffectType;
|
|
import org.bukkit.projectiles.ProjectileSource;
|
|
|
|
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)
|
|
{
|
|
ThrownPotion potion = event.getEntity();
|
|
ProjectileSource projectileSource = potion.getShooter();
|
|
Player player = null;
|
|
if (projectileSource instanceof Player)
|
|
{
|
|
player = (Player)projectileSource;
|
|
}
|
|
|
|
if (isDeathPotion(potion.getEffects()))
|
|
{
|
|
if (player != null)
|
|
{
|
|
player.sendMessage(ChatColor.RED + "You are not allowed to use death potions.");
|
|
}
|
|
event.setCancelled(true);
|
|
}
|
|
}
|
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
public void onThrowLingeringPotion(LingeringPotionSplashEvent event)
|
|
{
|
|
ThrownPotion potion = event.getEntity();
|
|
ProjectileSource projectileSource = potion.getShooter();
|
|
Player player = null;
|
|
if (projectileSource instanceof Player)
|
|
{
|
|
player = (Player)projectileSource;
|
|
}
|
|
|
|
if (isDeathPotion(potion.getEffects()))
|
|
{
|
|
if (player != null)
|
|
{
|
|
player.sendMessage(ChatColor.RED + "You are not allowed to use death potions.");
|
|
}
|
|
event.setCancelled(true);
|
|
}
|
|
}
|
|
|
|
public boolean isDeathPotion(Collection<PotionEffect> effects)
|
|
{
|
|
for (PotionEffect effect : effects)
|
|
{
|
|
int amplifier = effect.getAmplifier();
|
|
if (effect.getType().equals(PotionEffectType.HEAL) && (amplifier == 29 || amplifier == 61 || amplifier == 93 || amplifier == 125))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|