2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.listener;
|
2011-09-23 03:22:10 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
|
|
import net.pravian.aero.component.PluginListener;
|
2014-12-21 09:23:50 +00:00
|
|
|
import org.bukkit.entity.Bat;
|
|
|
|
import org.bukkit.entity.EnderDragon;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.Ghast;
|
|
|
|
import org.bukkit.entity.Giant;
|
|
|
|
import org.bukkit.entity.HumanEntity;
|
|
|
|
import org.bukkit.entity.Projectile;
|
|
|
|
import org.bukkit.entity.Slime;
|
|
|
|
import org.bukkit.entity.Tameable;
|
2012-03-03 04:29:54 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
2014-12-21 09:23:50 +00:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
|
|
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.ProjectileHitEvent;
|
2011-09-23 03:22:10 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public class EntityListener extends PluginListener<TotalFreedomMod>
|
2011-09-23 03:22:10 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
|
|
|
|
public EntityListener(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
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-10-19 17:43:46 +00:00
|
|
|
event.setRadius((float) ConfigEntry.EXPLOSIVE_RADIUS.getDouble().doubleValue());
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-03 04:29:54 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
2011-09-23 15:45:34 +00:00
|
|
|
public void onEntityDamage(EntityDamageEvent event)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
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)
|
2011-11-21 04:31:29 +00:00
|
|
|
public void onCreatureSpawn(CreatureSpawnEvent event)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (ConfigEntry.MOB_LIMITER_ENABLED.getBoolean())
|
2011-11-21 04:31:29 +00:00
|
|
|
{
|
2012-11-18 03:57:24 +00:00
|
|
|
if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.EGG))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-28 22:44:51 +00:00
|
|
|
Entity spawned = event.getEntity();
|
|
|
|
|
|
|
|
if (spawned instanceof EnderDragon)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean())
|
2011-11-28 22:44:51 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (spawned instanceof Ghast)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean())
|
2011-11-28 22:44:51 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (spawned instanceof Slime)
|
2011-11-21 05:54:11 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean())
|
2011-11-28 22:44:51 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-21 05:54:11 +00:00
|
|
|
}
|
2011-11-28 22:44:51 +00:00
|
|
|
else if (spawned instanceof Giant)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean())
|
2011-11-28 22:44:51 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-11-18 03:57:24 +00:00
|
|
|
else if (spawned instanceof Bat)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-28 22:44:51 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
int mobLimiterMax = ConfigEntry.MOB_LIMITER_MAX.getInteger().intValue();
|
2013-08-18 19:27:17 +00:00
|
|
|
|
|
|
|
if (mobLimiterMax > 0)
|
2011-11-21 04:31:29 +00:00
|
|
|
{
|
2011-11-21 05:54:11 +00:00
|
|
|
int mobcount = 0;
|
2011-11-28 22:44:51 +00:00
|
|
|
|
2013-08-12 02:02:18 +00:00
|
|
|
for (Entity entity : event.getLocation().getWorld().getLivingEntities())
|
2011-11-21 05:54:11 +00:00
|
|
|
{
|
2013-08-12 02:02:18 +00:00
|
|
|
if (!(entity instanceof HumanEntity))
|
2011-11-21 05:54:11 +00:00
|
|
|
{
|
2012-03-03 04:29:54 +00:00
|
|
|
mobcount++;
|
2011-11-21 05:54:11 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-28 22:44:51 +00:00
|
|
|
|
2013-08-18 19:27:17 +00:00
|
|
|
if (mobcount > mobLimiterMax)
|
2011-11-21 04:31:29 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-16 17:41:41 +00:00
|
|
|
|
2012-03-06 19:25:22 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onEntityDeath(EntityDeathEvent event)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
2012-03-06 19:25:22 +00:00
|
|
|
{
|
|
|
|
event.setDroppedExp(0);
|
|
|
|
}
|
|
|
|
}
|
2012-03-09 19:01:04 +00:00
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onProjectileHit(ProjectileHitEvent event)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
2012-03-09 19:01:04 +00:00
|
|
|
{
|
|
|
|
Projectile entity = event.getEntity();
|
2014-07-20 01:02:00 +00:00
|
|
|
if (event.getEntityType() == EntityType.ARROW)
|
2012-03-09 19:01:04 +00:00
|
|
|
{
|
|
|
|
entity.getWorld().createExplosion(entity.getLocation(), 2F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-23 03:22:10 +00:00
|
|
|
}
|