2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
|
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.TotalFreedomMod;
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import org.bukkit.entity.Bat;
|
|
|
|
import org.bukkit.entity.EnderDragon;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Ghast;
|
|
|
|
import org.bukkit.entity.Giant;
|
|
|
|
import org.bukkit.entity.HumanEntity;
|
|
|
|
import org.bukkit.entity.Slime;
|
2017-10-13 18:35:11 +00:00
|
|
|
import org.bukkit.entity.Wither;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class MobBlocker extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public MobBlocker(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
2018-07-06 17:06:34 +00:00
|
|
|
|
|
|
|
//fixes crash mobs, credit to Mafrans
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onEntitySpawn(EntitySpawnEvent e)
|
|
|
|
{
|
|
|
|
if (!(e instanceof LivingEntity))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Entity entity = e.getEntity();
|
|
|
|
if (entity instanceof Attributable)
|
|
|
|
{
|
|
|
|
if (((Attributable) entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE).getBaseValue() > 255.0)
|
|
|
|
{
|
|
|
|
((Attributable) entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE).setBaseValue(255.0);
|
|
|
|
}
|
|
|
|
if (((Attributable) entity).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getBaseValue() > 10.0)
|
|
|
|
{
|
|
|
|
((Attributable) entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE).setBaseValue(10.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.NORMAL)
|
|
|
|
public void onCreatureSpawn(CreatureSpawnEvent event)
|
|
|
|
{
|
|
|
|
if (!ConfigEntry.MOB_LIMITER_ENABLED.getBoolean())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Entity spawned = event.getEntity();
|
|
|
|
if (spawned instanceof EnderDragon)
|
|
|
|
{
|
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (spawned instanceof Ghast)
|
|
|
|
{
|
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (spawned instanceof Slime)
|
|
|
|
{
|
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-10-13 18:35:11 +00:00
|
|
|
else if (spawned instanceof Wither)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (spawned instanceof Giant)
|
|
|
|
{
|
|
|
|
if (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (spawned instanceof Bat)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
int mobLimiterMax = ConfigEntry.MOB_LIMITER_MAX.getInteger();
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
if (mobLimiterMax <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
int mobcount = 0;
|
|
|
|
for (Entity entity : event.getLocation().getWorld().getLivingEntities())
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
if (!(entity instanceof HumanEntity))
|
|
|
|
{
|
|
|
|
mobcount++;
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
if (mobcount > mobLimiterMax)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|