mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 04:26:42 +00:00
Lombok implementation removal. I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!! Thank you!!
134 lines
3.8 KiB
Java
134 lines
3.8 KiB
Java
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
import java.util.Objects;
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
import org.bukkit.attribute.Attributable;
|
|
import org.bukkit.attribute.Attribute;
|
|
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.LivingEntity;
|
|
import org.bukkit.entity.Slime;
|
|
import org.bukkit.entity.Wither;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventPriority;
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
|
|
|
public class MobBlocker extends FreedomService
|
|
{
|
|
@Override
|
|
public void onStart()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void onStop()
|
|
{
|
|
}
|
|
|
|
//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 (Objects.requireNonNull(((Attributable)entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).getBaseValue() > 255.0)
|
|
{
|
|
Objects.requireNonNull(((Attributable)entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).setBaseValue(255.0);
|
|
}
|
|
if (Objects.requireNonNull(((Attributable)entity).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED)).getBaseValue() > 10.0)
|
|
{
|
|
Objects.requireNonNull(((Attributable)entity).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED)).setBaseValue(10.0);
|
|
}
|
|
}
|
|
}
|
|
|
|
@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;
|
|
}
|
|
}
|
|
else if (spawned instanceof Wither)
|
|
{
|
|
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)
|
|
{
|
|
event.setCancelled(true);
|
|
return;
|
|
}
|
|
|
|
int mobLimiterMax = ConfigEntry.MOB_LIMITER_MAX.getInteger();
|
|
|
|
if (mobLimiterMax <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int mobcount = 0;
|
|
for (Entity entity : Objects.requireNonNull(event.getLocation().getWorld()).getLivingEntities())
|
|
{
|
|
if (!(entity instanceof HumanEntity) && entity instanceof LivingEntity)
|
|
{
|
|
mobcount++;
|
|
}
|
|
}
|
|
|
|
if (mobcount > mobLimiterMax)
|
|
{
|
|
event.setCancelled(true);
|
|
}
|
|
}
|
|
} |