TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java

198 lines
5.2 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.blocking;
2011-09-23 03:22:10 +00:00
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Tameable;
2012-03-03 04:29:54 +00:00
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
2011-09-23 03:22:10 +00:00
public class EventBlocker extends FreedomService
2011-09-23 03:22:10 +00:00
{
public EventBlocker(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBurn(BlockBurnEvent event)
{
if (!ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean())
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockIgnite(BlockIgniteEvent event)
{
if (!ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockFromTo(BlockFromToEvent event)
{
if (!ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
{
event.setCancelled(true);
}
}
2012-03-03 04:29:54 +00:00
@EventHandler(priority = EventPriority.HIGH)
2011-09-23 03:22:10 +00:00
public void onEntityExplode(EntityExplodeEvent event)
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
event.blockList().clear();
return;
}
2011-11-21 04:31:29 +00:00
event.setYield(0.0F);
}
2012-03-03 04:29:54 +00:00
@EventHandler(priority = EventPriority.HIGH)
public void onExplosionPrime(ExplosionPrimeEvent event)
2011-09-23 03:22:10 +00:00
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
2011-09-23 15:45:34 +00:00
{
event.setCancelled(true);
return;
}
event.setRadius(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
2011-09-23 15:45:34 +00:00
}
2012-03-03 04:29:54 +00:00
@EventHandler(priority = EventPriority.HIGH)
2011-09-23 15:45:34 +00:00
public void onEntityCombust(EntityCombustEvent event)
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
2011-09-23 15:45:34 +00:00
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event)
{
if (ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
{
event.setDroppedExp(0);
}
}
2012-03-03 04:29:54 +00:00
@EventHandler(priority = EventPriority.HIGH)
2018-03-03 04:29:08 +00:00
public void onEntityDamage(EntityDamageEvent event)
2011-09-23 15:45:34 +00:00
{
2012-03-03 04:29:54 +00:00
switch (event.getCause())
2011-09-23 15:45:34 +00:00
{
2012-03-03 04:29:54 +00:00
case LAVA:
{
if (!ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
{
event.setCancelled(true);
return;
}
}
}
if (ConfigEntry.ENABLE_PET_PROTECT.getBoolean())
{
Entity entity = event.getEntity();
if (entity instanceof Tameable)
{
if (((Tameable)entity).isTamed())
2012-03-03 04:29:54 +00:00
{
event.setCancelled(true);
}
}
2011-09-23 15:45:34 +00:00
}
2011-09-23 03:22:10 +00:00
}
2011-11-21 04:31:29 +00:00
2012-03-03 04:29:54 +00:00
@EventHandler(priority = EventPriority.NORMAL)
2018-03-03 04:29:08 +00:00
public void onPlayerDropItem(PlayerDropItemEvent event)
2011-11-21 04:31:29 +00:00
{
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
2011-11-21 04:31:29 +00:00
{
return;
2011-11-21 04:31:29 +00:00
}
2018-03-03 04:29:08 +00:00
if (event.getPlayer().getWorld().getEntities().size() > 750 && !plugin.al.isAdmin(event.getPlayer()))
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onLeavesDecay(LeavesDecayEvent event
)
{
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGH)
2018-03-03 04:29:08 +00:00
public void onFireworkExplode(FireworkExplodeEvent event)
{
if (!ConfigEntry.ALLOW_FIREWORK_EXPLOSION.getBoolean())
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPistonRetract(BlockPistonRetractEvent event)
{
if (!ConfigEntry.ALLOW_REDSTONE.getBoolean())
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPistonExtend(BlockPistonExtendEvent event)
{
if (!ConfigEntry.ALLOW_REDSTONE.getBoolean())
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockRedstone(BlockRedstoneEvent event)
{
if (!ConfigEntry.ALLOW_REDSTONE.getBoolean())
{
event.setNewCurrent(0);
}
}
2011-09-23 03:22:10 +00:00
}