diff --git a/src/main/java/com/songoda/ultimatestacker/entity/Check.java b/src/main/java/com/songoda/ultimatestacker/entity/Check.java index fa6e454..a8dd5df 100644 --- a/src/main/java/com/songoda/ultimatestacker/entity/Check.java +++ b/src/main/java/com/songoda/ultimatestacker/entity/Check.java @@ -1,5 +1,8 @@ package com.songoda.ultimatestacker.entity; +import java.util.HashMap; +import java.util.Map; + public enum Check { SPAWN_REASON(false), @@ -35,7 +38,14 @@ public enum Check { PHANTOM_SIZE(true), CAT_TYPE(true); - private boolean isEnabledByDefault; + private final boolean isEnabledByDefault; + private final static Map checks = new HashMap(); + + static { + for (Check c : values()) { + checks.put(c.name(), c); + } + } Check(boolean isEnabledByDefault) { this.isEnabledByDefault = isEnabledByDefault; @@ -44,4 +54,8 @@ public enum Check { public boolean isEnabledByDefault() { return isEnabledByDefault; } + + public static Check getCheck(String name) { + return name != null ? checks.get(name.toUpperCase()) : null; + } } diff --git a/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java b/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java index b82de0d..8b3839b 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java @@ -17,12 +17,12 @@ public class EntityUtils { UltimateStacker plugin = UltimateStacker.getInstance(); - private List checks = Settings.STACK_CHECKS.getStringList(); - private boolean stackFlyingDown = Settings.ONLY_STACK_FLYING_DOWN.getBoolean(); - private boolean keepFire = Settings.KEEP_FIRE.getBoolean(); - private boolean keepPotion = Settings.KEEP_POTION.getBoolean(); - private boolean stackWholeChunk = Settings.STACK_WHOLE_CHUNK.getBoolean(); - private int searchRadius = Settings.SEARCH_RADIUS.getInt(); + private final List checks = Settings.STACK_CHECKS.getStringList(); + private final boolean stackFlyingDown = Settings.ONLY_STACK_FLYING_DOWN.getBoolean(); + private final boolean keepFire = Settings.KEEP_FIRE.getBoolean(); + private final boolean keepPotion = Settings.KEEP_POTION.getBoolean(); + private final boolean stackWholeChunk = Settings.STACK_WHOLE_CHUNK.getBoolean(); + private final int searchRadius = Settings.SEARCH_RADIUS.getInt(); private final Map cachedChunks = new HashMap<>(); @@ -251,7 +251,8 @@ public class EntityUtils { entityList.removeIf(entity -> entity.getLocation().getY() > initalEntity.getLocation().getY()); for (String checkStr : checks) { - Check check = Check.valueOf(checkStr); + Check check = Check.getCheck(checkStr); + if (check == null) continue; switch (check) { case SPAWN_REASON: { if (initalEntity.hasMetadata("US_REASON"))