validate check config strings

This commit is contained in:
jascotty2 2019-09-29 10:19:37 -05:00 committed by Brianna
parent 817db57ea7
commit 787cfa089b
2 changed files with 23 additions and 8 deletions

View File

@ -1,5 +1,8 @@
package com.songoda.ultimatestacker.entity; package com.songoda.ultimatestacker.entity;
import java.util.HashMap;
import java.util.Map;
public enum Check { public enum Check {
SPAWN_REASON(false), SPAWN_REASON(false),
@ -35,7 +38,14 @@ public enum Check {
PHANTOM_SIZE(true), PHANTOM_SIZE(true),
CAT_TYPE(true); CAT_TYPE(true);
private boolean isEnabledByDefault; private final boolean isEnabledByDefault;
private final static Map<String, Check> checks = new HashMap();
static {
for (Check c : values()) {
checks.put(c.name(), c);
}
}
Check(boolean isEnabledByDefault) { Check(boolean isEnabledByDefault) {
this.isEnabledByDefault = isEnabledByDefault; this.isEnabledByDefault = isEnabledByDefault;
@ -44,4 +54,8 @@ public enum Check {
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return isEnabledByDefault; return isEnabledByDefault;
} }
public static Check getCheck(String name) {
return name != null ? checks.get(name.toUpperCase()) : null;
}
} }

View File

@ -17,12 +17,12 @@ public class EntityUtils {
UltimateStacker plugin = UltimateStacker.getInstance(); UltimateStacker plugin = UltimateStacker.getInstance();
private List<String> checks = Settings.STACK_CHECKS.getStringList(); private final List<String> checks = Settings.STACK_CHECKS.getStringList();
private boolean stackFlyingDown = Settings.ONLY_STACK_FLYING_DOWN.getBoolean(); private final boolean stackFlyingDown = Settings.ONLY_STACK_FLYING_DOWN.getBoolean();
private boolean keepFire = Settings.KEEP_FIRE.getBoolean(); private final boolean keepFire = Settings.KEEP_FIRE.getBoolean();
private boolean keepPotion = Settings.KEEP_POTION.getBoolean(); private final boolean keepPotion = Settings.KEEP_POTION.getBoolean();
private boolean stackWholeChunk = Settings.STACK_WHOLE_CHUNK.getBoolean(); private final boolean stackWholeChunk = Settings.STACK_WHOLE_CHUNK.getBoolean();
private int searchRadius = Settings.SEARCH_RADIUS.getInt(); private final int searchRadius = Settings.SEARCH_RADIUS.getInt();
private final Map<CachedChunk, Entity[]> cachedChunks = new HashMap<>(); private final Map<CachedChunk, Entity[]> cachedChunks = new HashMap<>();
@ -251,7 +251,8 @@ public class EntityUtils {
entityList.removeIf(entity -> entity.getLocation().getY() > initalEntity.getLocation().getY()); entityList.removeIf(entity -> entity.getLocation().getY() > initalEntity.getLocation().getY());
for (String checkStr : checks) { for (String checkStr : checks) {
Check check = Check.valueOf(checkStr); Check check = Check.getCheck(checkStr);
if (check == null) continue;
switch (check) { switch (check) {
case SPAWN_REASON: { case SPAWN_REASON: {
if (initalEntity.hasMetadata("US_REASON")) if (initalEntity.hasMetadata("US_REASON"))