2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
2011-09-23 03:22:10 +00:00
|
|
|
|
2020-07-03 15:03:08 +00:00
|
|
|
import java.util.ArrayList;
|
2019-11-03 21:40:05 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2016-03-01 16:47:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
2019-11-03 21:40:05 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2019-01-28 01:49:07 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.Groups;
|
2019-07-11 02:13:57 +00:00
|
|
|
import org.bukkit.Material;
|
2018-12-29 19:41:48 +00:00
|
|
|
import org.bukkit.attribute.Attribute;
|
|
|
|
import org.bukkit.attribute.AttributeModifier;
|
2020-07-03 15:03:08 +00:00
|
|
|
import org.bukkit.block.data.AnaloguePowerable;
|
|
|
|
import org.bukkit.block.data.Powerable;
|
2014-12-21 09:23:50 +00:00
|
|
|
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;
|
2020-08-05 07:01:21 +00:00
|
|
|
import org.bukkit.event.block.BlockBurnEvent;
|
|
|
|
import org.bukkit.event.block.BlockDispenseEvent;
|
|
|
|
import org.bukkit.event.block.BlockFromToEvent;
|
|
|
|
import org.bukkit.event.block.BlockGrowEvent;
|
|
|
|
import org.bukkit.event.block.BlockIgniteEvent;
|
|
|
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
|
|
|
import org.bukkit.event.block.BlockPistonExtendEvent;
|
|
|
|
import org.bukkit.event.block.BlockPistonRetractEvent;
|
|
|
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
|
|
|
import org.bukkit.event.block.LeavesDecayEvent;
|
2018-07-31 07:05:28 +00:00
|
|
|
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;
|
2019-12-09 04:57:28 +00:00
|
|
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
2018-12-29 19:41:48 +00:00
|
|
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
2011-09-23 03:22:10 +00:00
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class EventBlocker extends FreedomService
|
2011-09-23 03:22:10 +00:00
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@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)
|
2011-09-26 15:26:52 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
2011-09-26 15:26:52 +00:00
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
event.blockList().clear();
|
2011-09-26 15:26:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-21 04:31:29 +00:00
|
|
|
|
2012-03-09 19:01:04 +00:00
|
|
|
event.setYield(0.0F);
|
2011-09-26 15:26:52 +00:00
|
|
|
}
|
|
|
|
|
2012-03-03 04:29:54 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
2011-09-26 15:26:52 +00:00
|
|
|
public void onExplosionPrime(ExplosionPrimeEvent event)
|
2011-09-23 03:22:10 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
2011-09-23 15:45:34 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2011-09-28 17:42:21 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
event.setRadius(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
|
2011-09-23 15:45:34 +00:00
|
|
|
}
|
2011-09-28 17:42:21 +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)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
2011-09-23 15:45:34 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
@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:
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
|
2013-07-11 18:51:08 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
if (ConfigEntry.ENABLE_PET_PROTECT.getBoolean())
|
2013-07-11 18:51:08 +00:00
|
|
|
{
|
|
|
|
Entity entity = event.getEntity();
|
|
|
|
if (entity instanceof Tameable)
|
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
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
|
|
|
{
|
2020-01-07 20:13:59 +00:00
|
|
|
if (!plugin.al.isAdmin(event.getPlayer()))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
2011-11-21 04:31:29 +00:00
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
return;
|
2011-11-21 04:31:29 +00:00
|
|
|
}
|
2012-09-16 17:41:41 +00:00
|
|
|
|
2020-01-07 20:13:59 +00:00
|
|
|
if (event.getPlayer().getWorld().getEntities().size() > 750)
|
2012-03-06 19:25:22 +00:00
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
event.setCancelled(true);
|
2012-03-06 19:25:22 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 19:01:04 +00:00
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
2019-01-11 17:04:32 +00:00
|
|
|
public void onLeavesDecay(LeavesDecayEvent event)
|
2012-03-09 19:01:04 +00:00
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
event.setCancelled(true);
|
2012-03-09 19:01:04 +00:00
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2020-04-08 02:20:01 +00:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onBlockGrowth(BlockGrowEvent event)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
2018-03-03 04:29:08 +00:00
|
|
|
public void onFireworkExplode(FireworkExplodeEvent event)
|
2017-10-13 18:35:11 +00:00
|
|
|
{
|
|
|
|
if (!ConfigEntry.ALLOW_FIREWORK_EXPLOSION.getBoolean())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
2018-01-01 03:43:10 +00:00
|
|
|
public void onBlockPistonRetract(BlockPistonRetractEvent event)
|
2017-10-13 18:35:11 +00:00
|
|
|
{
|
|
|
|
if (!ConfigEntry.ALLOW_REDSTONE.getBoolean())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
2018-01-01 03:43:10 +00:00
|
|
|
public void onBlockPistonExtend(BlockPistonExtendEvent event)
|
2017-10-13 18:35:11 +00:00
|
|
|
{
|
|
|
|
if (!ConfigEntry.ALLOW_REDSTONE.getBoolean())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 15:03:08 +00:00
|
|
|
//@EventHandler(priority = EventPriority.HIGH)
|
2018-01-01 03:43:10 +00:00
|
|
|
public void onBlockRedstone(BlockRedstoneEvent event)
|
2017-10-13 18:35:11 +00:00
|
|
|
{
|
|
|
|
if (!ConfigEntry.ALLOW_REDSTONE.getBoolean())
|
|
|
|
{
|
|
|
|
event.setNewCurrent(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 15:03:08 +00:00
|
|
|
// TODO: Revert back to old redstone block system when (or if) it is fixed in Bukkit, Spigot or Paper.
|
|
|
|
private ArrayList<Material> redstoneBlocks = new ArrayList<>(Arrays.asList(Material.REDSTONE, Material.DISPENSER, Material.DROPPER, Material.REDSTONE_LAMP));
|
|
|
|
@EventHandler
|
2020-07-14 19:00:22 +00:00
|
|
|
public void onBlockPhysics(BlockPhysicsEvent event)
|
|
|
|
{
|
2020-07-03 15:03:08 +00:00
|
|
|
if (!ConfigEntry.ALLOW_REDSTONE.getBoolean())
|
|
|
|
{
|
|
|
|
// Check if the block is involved with redstone.
|
|
|
|
if(event.getBlock().getBlockData() instanceof AnaloguePowerable || event.getBlock().getBlockData() instanceof Powerable || redstoneBlocks.contains(event.getBlock().getType()))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 19:41:48 +00:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onPlayerRespawn(PlayerRespawnEvent event)
|
|
|
|
{
|
|
|
|
double maxHealth = event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
|
|
|
if (maxHealth < 1)
|
|
|
|
{
|
|
|
|
for (AttributeModifier attributeModifier : event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getModifiers())
|
|
|
|
{
|
|
|
|
event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).removeModifier(attributeModifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-04 21:39:38 +00:00
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onBlockDispense(BlockDispenseEvent event)
|
|
|
|
{
|
2019-11-03 21:40:05 +00:00
|
|
|
List<Material> banned = Arrays.asList(Material.TNT_MINECART, Material.MINECART);
|
|
|
|
if (Groups.SPAWN_EGGS.contains(event.getItem().getType()) || banned.contains(event.getItem().getType()))
|
2019-01-04 21:39:38 +00:00
|
|
|
{
|
2019-08-07 07:31:05 +00:00
|
|
|
event.setCancelled(true);
|
2019-01-04 21:39:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-09 04:57:28 +00:00
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onPlayerDeath(PlayerDeathEvent event)
|
|
|
|
{
|
2019-12-14 03:17:34 +00:00
|
|
|
FUtil.fixCommandVoid(event.getEntity());
|
2019-12-09 04:57:28 +00:00
|
|
|
event.setDeathMessage(event.getDeathMessage());
|
|
|
|
}
|
2011-09-23 03:22:10 +00:00
|
|
|
}
|