diff --git a/build.gradle b/build.gradle index 7b93cd6..a6ccd0b 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,9 @@ repositories { maven { url = 'https://repo.codemc.org/repository/maven-public/' } + maven { + url = 'https://jitpack.io' + } } dependencies { @@ -35,7 +38,7 @@ dependencies { compileOnly 'dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT' compileOnly 'me.clip:placeholderapi:2.10.9' implementation 'org.jooq:joor-java-8:0.9.14' - implementation 'com.froobworld:nab-configuration:1.0.2' + implementation 'com.github.froobynooby:nab-configuration:master-SNAPSHOT' //'com.froobworld:nab-configuration:1.0.2' implementation 'org.bstats:bstats-bukkit:2.2.1' } diff --git a/src/main/java/com/froobworld/farmcontrol/command/StatusCommand.java b/src/main/java/com/froobworld/farmcontrol/command/StatusCommand.java index 505930d..82b3780 100644 --- a/src/main/java/com/froobworld/farmcontrol/command/StatusCommand.java +++ b/src/main/java/com/froobworld/farmcontrol/command/StatusCommand.java @@ -1,6 +1,7 @@ package com.froobworld.farmcontrol.command; import com.froobworld.farmcontrol.FarmControl; +import com.froobworld.farmcontrol.controller.FarmController; import com.froobworld.farmcontrol.data.FcData; import com.froobworld.farmcontrol.hook.scheduler.ScheduledTask; import org.bukkit.Bukkit; @@ -9,8 +10,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import org.bukkit.entity.*; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -48,7 +48,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command Map actionCount = new HashMap<>(); CompletableFuture completableFuture = CompletableFuture.completedFuture(null); - for (LivingEntity entity : world.getLivingEntities()) { + for (Entity entity : world.getEntitiesByClasses(FarmController.ENTITY_CLASSES)) { entityCount.incrementAndGet(); CompletableFuture entityFuture = new CompletableFuture(); ScheduledTask scheduledTask = farmControl.getHookManager().getSchedulerHook().runEntityTaskAsap(() -> { diff --git a/src/main/java/com/froobworld/farmcontrol/controller/CompatibilityListener.java b/src/main/java/com/froobworld/farmcontrol/controller/CompatibilityListener.java index cd3c4cc..e76c312 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/CompatibilityListener.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/CompatibilityListener.java @@ -42,6 +42,9 @@ public void onEntityDamage(EntityDamageEvent event) { @EventHandler public void onEntityTarget(EntityTargetLivingEntityEvent event) { + if (event.getTarget() == null) { + return; + } Actioner.undoActions(event.getTarget(), action -> { return farmControl.getFcConfig().worldSettings.of(event.getEntity().getWorld()).actionSettings.undoOn.of(action).target.get(); }, farmControl); diff --git a/src/main/java/com/froobworld/farmcontrol/controller/FarmController.java b/src/main/java/com/froobworld/farmcontrol/controller/FarmController.java index e4c9194..e006485 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/FarmController.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/FarmController.java @@ -1,7 +1,9 @@ package com.froobworld.farmcontrol.controller; import com.froobworld.farmcontrol.FarmControl; -import com.froobworld.farmcontrol.controller.task.*; +import com.froobworld.farmcontrol.controller.task.ActionPerformTask; +import com.froobworld.farmcontrol.controller.task.TriggerCheckTask; +import com.froobworld.farmcontrol.controller.task.UntriggerPerformTask; import com.froobworld.farmcontrol.controller.tracker.CycleHistoryManager; import com.froobworld.farmcontrol.controller.trigger.Trigger; import com.froobworld.farmcontrol.hook.scheduler.RegionisedSchedulerHook; @@ -9,11 +11,16 @@ import com.froobworld.farmcontrol.utils.Actioner; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.entity.Entity; +import org.bukkit.entity.*; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.List; public class FarmController { + public static final Class[] ENTITY_CLASSES = List.of(Mob.class, Vehicle.class, Projectile.class, Item.class).toArray(new Class[0]); private final FarmControl farmControl; private final CycleHistoryManager cycleHistoryManager; private final Map>> worldTriggerProfilesMap = new HashMap<>(); @@ -81,7 +88,7 @@ public void addWorld(World world) { public void removeWorld(World world) { worldTriggerProfilesMap.remove(world); - for (Entity entity : world.getLivingEntities()) { + for (Entity entity : world.getEntities()) { farmControl.getHookManager().getSchedulerHook().runEntityTaskAsap( () -> Actioner.undoAllActions(entity, farmControl), null, entity); diff --git a/src/main/java/com/froobworld/farmcontrol/controller/action/Action.java b/src/main/java/com/froobworld/farmcontrol/controller/action/Action.java index 982a3f6..c89486e 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/action/Action.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/action/Action.java @@ -1,17 +1,19 @@ package com.froobworld.farmcontrol.controller.action; -import org.bukkit.entity.Mob; +import org.bukkit.entity.Entity; public abstract class Action { private final String name; + private final Class entityClass; private final boolean removes; private final boolean persistent; private final boolean undoOnUnload; - public Action(String name, boolean removes, boolean persistent, boolean undoOnUnload) { + public Action(String name, Class entityClass, boolean removes, boolean persistent, boolean undoOnUnload) { if (!name.matches("[a-z-]+")) { throw new IllegalArgumentException("Name must match [a-z-]+"); } + this.entityClass = entityClass; this.name = name; this.removes = removes; this.persistent = persistent; @@ -34,7 +36,11 @@ public boolean undoOnUnload() { return undoOnUnload; } - public abstract void doAction(Mob mob); + public abstract void doAction(Entity entity); - public abstract void undoAction(Mob mob); + public abstract void undoAction(Entity entity); + + public Class getEntityClass() { + return entityClass; + } } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/action/DisableBreedingAction.java b/src/main/java/com/froobworld/farmcontrol/controller/action/DisableBreedingAction.java index e2a0663..4e0c0b4 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/action/DisableBreedingAction.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/action/DisableBreedingAction.java @@ -1,23 +1,30 @@ package com.froobworld.farmcontrol.controller.action; import com.froobworld.farmcontrol.controller.breeding.BreedingBlocker; +import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; public class DisableBreedingAction extends Action { private final BreedingBlocker breedingBlocker; public DisableBreedingAction(BreedingBlocker breedingBlocker) { - super("disable-breeding", false, true, false); + super("disable-breeding", Mob.class, false, true, false); this.breedingBlocker = breedingBlocker; } @Override - public void doAction(Mob mob) { - breedingBlocker.setBreedingDisabled(mob, true); + public void doAction(Entity entity) { + if (!(entity instanceof Mob)) { + return; + } + breedingBlocker.setBreedingDisabled(entity, true); } @Override - public void undoAction(Mob mob) { + public void undoAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } breedingBlocker.setBreedingDisabled(mob, false); } } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/action/DisableCollisionsAction.java b/src/main/java/com/froobworld/farmcontrol/controller/action/DisableCollisionsAction.java index dfd014c..e613aa9 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/action/DisableCollisionsAction.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/action/DisableCollisionsAction.java @@ -1,20 +1,28 @@ package com.froobworld.farmcontrol.controller.action; +import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; public class DisableCollisionsAction extends Action { public DisableCollisionsAction() { - super("disable-collisions", false, false, true); + super("disable-collisions", Mob.class, false, false, true); } @Override - public void doAction(Mob mob) { + public void doAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } + mob.setCollidable(false); } @Override - public void undoAction(Mob mob) { + public void undoAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } mob.setCollidable(true); } } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/action/KillAction.java b/src/main/java/com/froobworld/farmcontrol/controller/action/KillAction.java index f060886..8cb5e57 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/action/KillAction.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/action/KillAction.java @@ -1,18 +1,22 @@ package com.froobworld.farmcontrol.controller.action; +import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; public class KillAction extends Action { public KillAction() { - super("kill", true, false, false); + super("kill", Mob.class, true, false, false); } @Override - public void doAction(Mob mob) { + public void doAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } mob.setHealth(0); } @Override - public void undoAction(Mob mob) {} + public void undoAction(Entity entity) {} } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAction.java b/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAction.java index 7b8b0fd..0915c4b 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAction.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAction.java @@ -1,18 +1,18 @@ package com.froobworld.farmcontrol.controller.action; -import org.bukkit.entity.Mob; +import org.bukkit.entity.Entity; public class RemoveAction extends Action { public RemoveAction() { - super("remove", true, false, false); + super("remove", Entity.class, true, false, false); } @Override - public void doAction(Mob mob) { - mob.remove(); + public void doAction(Entity entity) { + entity.remove(); } @Override - public void undoAction(Mob mob) {} + public void undoAction(Entity entity) {} } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAiAction.java b/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAiAction.java index 1c0f3b9..9d5128d 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAiAction.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAiAction.java @@ -1,21 +1,28 @@ package com.froobworld.farmcontrol.controller.action; +import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; import org.bukkit.util.Vector; public class RemoveAiAction extends Action { public RemoveAiAction() { - super("remove-ai", false, true, true); + super("remove-ai", Mob.class, false, true, true); } @Override - public void doAction(Mob mob) { + public void doAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } mob.setAI(false); } @Override - public void undoAction(Mob mob) { + public void undoAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } mob.setAI(true); mob.setVelocity(new Vector(0, 0, 0)); } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAwarenessAction.java b/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAwarenessAction.java index 2d44571..8060437 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAwarenessAction.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveAwarenessAction.java @@ -1,20 +1,27 @@ package com.froobworld.farmcontrol.controller.action; +import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; public class RemoveAwarenessAction extends Action { public RemoveAwarenessAction() { - super("remove-awareness", false, true, true); + super("remove-awareness", Mob.class, false, true, true); } @Override - public void doAction(Mob mob) { + public void doAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } mob.setAware(false); } @Override - public void undoAction(Mob mob) { + public void undoAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } mob.setAware(true); } } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveRandomMovementAction.java b/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveRandomMovementAction.java index 042cc22..db50cd2 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveRandomMovementAction.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/action/RemoveRandomMovementAction.java @@ -3,6 +3,7 @@ import com.froobworld.farmcontrol.utils.NmsUtils; import com.google.common.collect.MapMaker; import com.google.common.collect.Sets; +import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; import java.util.*; @@ -29,11 +30,15 @@ public static void cleanUp() { } public RemoveRandomMovementAction() { - super("remove-random-movement", false, false, true); + super("remove-random-movement", Mob.class, false, false, true); } @Override - public void doAction(Mob mob) { + public void doAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } + Object entityObject = on(mob).call("getHandle").get(); Set wrappedGoals = on(entityObject) .field(NmsUtils.GoalSelectorHelper.getGoalSelectorFieldName()) @@ -55,7 +60,10 @@ public void doAction(Mob mob) { } @Override - public void undoAction(Mob mob) { + public void undoAction(Entity entity) { + if (!(entity instanceof Mob mob)) { + return; + } Object entityObject = on(mob).call("getHandle").get(); Set wrappedGoals = on(entityObject) .field(NmsUtils.GoalSelectorHelper.getGoalSelectorFieldName()) diff --git a/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java b/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java index 0da02c2..87c73bc 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java @@ -10,7 +10,7 @@ import java.util.List; public class SnapshotEntity { - private final Mob entity; + private final Entity entity; private final int entityId; private final Vector location; private final FcData fcData; @@ -22,12 +22,12 @@ public class SnapshotEntity { private final int ticksLived; private final List classifications = new ArrayList<>(); - public SnapshotEntity(Mob entity) { + public SnapshotEntity(Entity entity) { this.entity = entity; this.entityId = entity.getEntityId(); this.location = entity.getLocation().toVector(); this.fcData = FcData.get(entity); - this.leashed = entity.isLeashed(); + this.leashed = entity instanceof Mob && ((Mob) entity).isLeashed(); this.loveMode = entity instanceof Animals && ((Animals) entity).isLoveMode(); this.customName = entity.getCustomName() != null; this.tamed = entity instanceof Tameable && ((Tameable) entity).isTamed(); @@ -45,7 +45,7 @@ public SnapshotEntity(Mob entity) { } } - public Class getEntityClass() { + public Class getEntityClass() { return entity.getClass(); } @@ -65,7 +65,7 @@ public FcData getFcData() { return fcData; } - public Mob getEntity() { + public Entity getEntity() { return entity; } @@ -100,4 +100,5 @@ public int getTicksLived() { public List getClassifications() { return classifications; } + } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/task/ActionAllocationTask.java b/src/main/java/com/froobworld/farmcontrol/controller/task/ActionAllocationTask.java index ca8c128..7165a9f 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/task/ActionAllocationTask.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/task/ActionAllocationTask.java @@ -68,6 +68,9 @@ public void run() { Set triggerActionPairs = triggerActionMap.computeIfAbsent(next, e -> new HashSet<>()); Set unTriggerActionPairs = unTriggerActionMap.getOrDefault(next, Collections.emptySet()); for (Action action : triggerProfilePair.actionProfile.getActions()) { + if (!action.getEntityClass().isAssignableFrom(next.getEntityClass())) { + continue; + } TriggerActionPair triggerActionPair = new TriggerActionPair(triggerProfilePair.trigger, action); triggerActionPairs.add(triggerActionPair); unTriggerActionPairs.remove(triggerActionPair); diff --git a/src/main/java/com/froobworld/farmcontrol/controller/task/ActionPerformTask.java b/src/main/java/com/froobworld/farmcontrol/controller/task/ActionPerformTask.java index 469ee04..6e4dbe5 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/task/ActionPerformTask.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/task/ActionPerformTask.java @@ -7,7 +7,7 @@ import com.froobworld.farmcontrol.hook.scheduler.ScheduledTask; import com.froobworld.farmcontrol.hook.scheduler.SchedulerHook; import org.bukkit.World; -import org.bukkit.entity.Mob; +import org.bukkit.entity.Entity; import java.util.Map; import java.util.Set; @@ -32,7 +32,7 @@ public ActionPerformTask(World world, SchedulerHook schedulerHook, Map future = CompletableFuture.completedFuture(null); for (SnapshotEntity snapshotEntity : triggerActionMap.keySet()) { - Mob entity = snapshotEntity.getEntity(); + Entity entity = snapshotEntity.getEntity(); CompletableFuture entityFuture = new CompletableFuture<>(); ScheduledTask scheduledTask = schedulerHook.runEntityTaskAsap(() -> { try { @@ -57,7 +57,7 @@ public void run() { } } for (SnapshotEntity snapshotEntity : unTriggerActionMap.keySet()) { - Mob entity = snapshotEntity.getEntity(); + Entity entity = snapshotEntity.getEntity(); schedulerHook.runEntityTaskAsap(() -> { if (!entity.isValid()) { return; diff --git a/src/main/java/com/froobworld/farmcontrol/controller/task/TriggerCheckTask.java b/src/main/java/com/froobworld/farmcontrol/controller/task/TriggerCheckTask.java index 6b7921c..b5bdd36 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/task/TriggerCheckTask.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/task/TriggerCheckTask.java @@ -10,7 +10,7 @@ import com.froobworld.farmcontrol.hook.scheduler.ScheduledTask; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.bukkit.World; -import org.bukkit.entity.Mob; +import org.bukkit.entity.*; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -62,7 +62,7 @@ public void run() { List snapshotEntities = new ArrayList<>(); CompletableFuture completableFuture = CompletableFuture.completedFuture(null); if (!profilesToRun.isEmpty() || !untriggerStrategyMap.isEmpty()) { - for (Mob entity : world.getEntitiesByClass(Mob.class)) { + for (Entity entity : world.getEntitiesByClasses(FarmController.ENTITY_CLASSES)) { CompletableFuture entityFuture = new CompletableFuture<>(); ScheduledTask scheduledTask = farmControl.getHookManager().getSchedulerHook().runEntityTaskAsap(() -> { try { diff --git a/src/main/java/com/froobworld/farmcontrol/controller/task/UntriggerPerformTask.java b/src/main/java/com/froobworld/farmcontrol/controller/task/UntriggerPerformTask.java index 7270d72..b4e2431 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/task/UntriggerPerformTask.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/task/UntriggerPerformTask.java @@ -4,6 +4,7 @@ import com.froobworld.farmcontrol.controller.entity.SnapshotEntity; import com.froobworld.farmcontrol.data.FcData; import com.froobworld.farmcontrol.hook.scheduler.SchedulerHook; +import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; import java.util.Map; @@ -21,9 +22,9 @@ public UntriggerPerformTask(SchedulerHook schedulerHook, Map { - if (!entity.isValid()) { + if (!(entity instanceof Mob mob) || !entity.isValid()) { return; } FcData fcData = FcData.get(entity); @@ -32,7 +33,7 @@ public void run() { } for (TriggerActionPair triggerActionPair : actionsToUndo.get(snapshotEntity)) { if (fcData.remove(triggerActionPair.trigger, triggerActionPair.action)) { - triggerActionPair.action.undoAction(entity); + triggerActionPair.action.undoAction(mob); } } fcData.save(entity); diff --git a/src/main/java/com/froobworld/farmcontrol/group/GroupDefinition.java b/src/main/java/com/froobworld/farmcontrol/group/GroupDefinition.java index 2e68a3d..19ea1c3 100644 --- a/src/main/java/com/froobworld/farmcontrol/group/GroupDefinition.java +++ b/src/main/java/com/froobworld/farmcontrol/group/GroupDefinition.java @@ -63,7 +63,7 @@ public static GroupDefinition fromConfigurationSection(ConfigurationSection sect Predicate typePredicate = section.getStringList("types").stream() .map(EntityTypeUtils::fromString) .reduce(Predicate::or) - .orElse(snapshotEntity -> true); + .orElse(snapshotEntity -> false); // require explicit specification of types by defaulting to false Predicate excludeTypePredicate = section.getStringList("exclude-types").stream() .map(EntityTypeUtils::fromString) .reduce(Predicate::or) diff --git a/src/main/java/com/froobworld/farmcontrol/utils/Actioner.java b/src/main/java/com/froobworld/farmcontrol/utils/Actioner.java index f9d0885..551d9ee 100644 --- a/src/main/java/com/froobworld/farmcontrol/utils/Actioner.java +++ b/src/main/java/com/froobworld/farmcontrol/utils/Actioner.java @@ -4,7 +4,6 @@ import com.froobworld.farmcontrol.controller.action.Action; import com.froobworld.farmcontrol.data.FcData; import org.bukkit.entity.Entity; -import org.bukkit.entity.Mob; import java.util.function.Predicate; @@ -17,9 +16,6 @@ public static void undoAllActions(Entity entity, FarmControl farmControl) { } public static void undoActions(Entity entity, Predicate actionUndoPredicate, FarmControl farmControl) { - if (!(entity instanceof Mob)) { - return; - } FcData fcData = FcData.get(entity); if (fcData == null) { return; @@ -27,7 +23,7 @@ public static void undoActions(Entity entity, Predicate actionUndoPredic for (Action action : farmControl.getActionManager().getActions()) { if (actionUndoPredicate.test(action)) { if (fcData.removeAction(action)) { - action.undoAction((Mob) entity); + action.undoAction(entity); } } } diff --git a/src/main/java/com/froobworld/farmcontrol/utils/EntityTypeUtils.java b/src/main/java/com/froobworld/farmcontrol/utils/EntityTypeUtils.java index e0b0305..e5cf24b 100644 --- a/src/main/java/com/froobworld/farmcontrol/utils/EntityTypeUtils.java +++ b/src/main/java/com/froobworld/farmcontrol/utils/EntityTypeUtils.java @@ -12,20 +12,17 @@ private EntityTypeUtils(){} public static Predicate fromString(String string) { if (string.toLowerCase().startsWith("category:")) { String category = string.split(":")[1]; - if (category.equalsIgnoreCase("animal")) { - return entity -> Animals.class.isAssignableFrom(entity.getEntityClass()); - } else if (category.equalsIgnoreCase("monster")) { - return entity -> Monster.class.isAssignableFrom(entity.getEntityClass()); - } else if (category.equalsIgnoreCase("golem")) { - return entity -> Golem.class.isAssignableFrom(entity.getEntityClass()); - } else if (category.equalsIgnoreCase("ambient")) { - return entity -> Ambient.class.isAssignableFrom(entity.getEntityClass()); - } else if (category.equalsIgnoreCase("fish")) { - return entity -> Fish.class.isAssignableFrom(entity.getEntityClass()); - } else if (category.equalsIgnoreCase("tameable")) { - return entity -> Tameable.class.isAssignableFrom(entity.getEntityClass()); - } else if (category.equalsIgnoreCase("raider")) { - return entity -> Raider.class.isAssignableFrom(entity.getEntityClass()); + switch (category.toLowerCase()) { + case "animal" -> {return entity -> Animals.class.isAssignableFrom(entity.getEntityClass());} + case "monster" -> {return entity -> Monster.class.isAssignableFrom(entity.getEntityClass());} + case "golem" -> {return entity -> Golem.class.isAssignableFrom(entity.getEntityClass());} + case "ambient" -> {return entity -> Ambient.class.isAssignableFrom(entity.getEntityClass());} + case "fish" -> {return entity -> Fish.class.isAssignableFrom(entity.getEntityClass());} + case "tameable" -> {return entity -> Tameable.class.isAssignableFrom(entity.getEntityClass());} + case "raider" -> {return entity -> Raider.class.isAssignableFrom(entity.getEntityClass());} + case "mob" -> {return entity -> Mob.class.isAssignableFrom(entity.getEntityClass());} + case "vehicle" -> {return entity -> Vehicle.class.isAssignableFrom(entity.getEntityClass());} + case "projectile" -> {return entity -> Projectile.class.isAssignableFrom(entity.getEntityClass());} } } return entity -> entity.getEntityType().toString().equalsIgnoreCase(string); diff --git a/src/main/resources/resources/config.yml b/src/main/resources/resources/config.yml index 06945ec..1f3a013 100644 --- a/src/main/resources/resources/config.yml +++ b/src/main/resources/resources/config.yml @@ -83,6 +83,8 @@ world-settings: # Which types of mobs should we not perform actions on? type: + - chest_boat + - minecart_chest # - villager # For which metadata should we not perform actions on a mob?