From 6b54fc5b8e3550d74003ed9ea5b5547d4a9012fe Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 9 Nov 2019 14:44:58 -0800 Subject: [PATCH] Fix for nulls in map. https://github.com/BentoBoxWorld/Limits/issues/50 --- .../java/bentobox/addon/limits/Settings.java | 31 ++++++++++++++++--- .../addon/limits/commands/LimitPanel.java | 27 ++-------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/main/java/bentobox/addon/limits/Settings.java b/src/main/java/bentobox/addon/limits/Settings.java index 164e0f9..197f93f 100644 --- a/src/main/java/bentobox/addon/limits/Settings.java +++ b/src/main/java/bentobox/addon/limits/Settings.java @@ -8,12 +8,35 @@ import java.util.Map; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.EntityType; -import bentobox.addon.limits.commands.LimitPanel; - public class Settings { private final Map limits = new EnumMap<>(EntityType.class); private final List gameModes; + private static final List DISALLOWED = Arrays.asList( + EntityType.PRIMED_TNT, + EntityType.EVOKER_FANGS, + EntityType.LLAMA_SPIT, + EntityType.DRAGON_FIREBALL, + EntityType.AREA_EFFECT_CLOUD, + EntityType.ENDER_SIGNAL, + EntityType.SMALL_FIREBALL, + EntityType.FIREBALL, + EntityType.THROWN_EXP_BOTTLE, + EntityType.EXPERIENCE_ORB, + EntityType.SHULKER_BULLET, + EntityType.WITHER_SKULL, + EntityType.TRIDENT, + EntityType.ARROW, + EntityType.SPECTRAL_ARROW, + EntityType.SNOWBALL, + EntityType.EGG, + EntityType.LEASH_HITCH, + EntityType.GIANT, + EntityType.ENDER_CRYSTAL, + EntityType.ENDER_PEARL, + EntityType.ENDER_DRAGON, + EntityType.ITEM_FRAME, + EntityType.PAINTING); public Settings(Limits addon) { @@ -25,9 +48,7 @@ public class Settings { for (String key : el.getKeys(false)) { EntityType type = getType(key); if (type != null) { - if (!type.equals(EntityType.PAINTING) && - !type.equals(EntityType.ITEM_FRAME) && - (!type.isSpawnable() || (LimitPanel.E2M.containsKey(type) && LimitPanel.E2M.get(type) == null))) { + if (DISALLOWED.contains(type)) { addon.logError("Entity type: " + key + " is not supported - skipping..."); } else { limits.put(type, el.getInt(key, 0)); diff --git a/src/main/java/bentobox/addon/limits/commands/LimitPanel.java b/src/main/java/bentobox/addon/limits/commands/LimitPanel.java index 9728115..15e39d0 100644 --- a/src/main/java/bentobox/addon/limits/commands/LimitPanel.java +++ b/src/main/java/bentobox/addon/limits/commands/LimitPanel.java @@ -30,7 +30,7 @@ public class LimitPanel { private final Limits addon; // This maps the entity types to the icon that should be shown in the panel // If the icon is null, then the entity type is not covered by the addon - public static final Map E2M = ImmutableMap.builder() + private static final Map E2M = ImmutableMap.builder() .put(EntityType.PIG_ZOMBIE, Material.ZOMBIE_PIGMAN_SPAWN_EGG) .put(EntityType.MUSHROOM_COW, Material.MOOSHROOM_SPAWN_EGG) .put(EntityType.SNOWMAN, Material.SNOW_BLOCK) @@ -48,32 +48,9 @@ public class LimitPanel { .put(EntityType.MINECART_FURNACE, Material.FURNACE_MINECART) .put(EntityType.MINECART_HOPPER, Material.HOPPER_MINECART) .put(EntityType.MINECART_MOB_SPAWNER, Material.MINECART) - // Disallowed - .put(EntityType.PRIMED_TNT, null) - .put(EntityType.EVOKER_FANGS, null) - .put(EntityType.LLAMA_SPIT, null) - .put(EntityType.DRAGON_FIREBALL, null) - .put(EntityType.AREA_EFFECT_CLOUD, null) - .put(EntityType.ENDER_SIGNAL, null) - .put(EntityType.SMALL_FIREBALL, null) - .put(EntityType.FIREBALL, null) - .put(EntityType.THROWN_EXP_BOTTLE, null) - .put(EntityType.EXPERIENCE_ORB, null) - .put(EntityType.SHULKER_BULLET, null) - .put(EntityType.WITHER_SKULL, null) - .put(EntityType.TRIDENT, null) - .put(EntityType.ARROW, null) - .put(EntityType.SPECTRAL_ARROW, null) - .put(EntityType.SNOWBALL, null) - .put(EntityType.EGG, null) - .put(EntityType.LEASH_HITCH, null) - .put(EntityType.GIANT, null) - .put(EntityType.ENDER_CRYSTAL, null) - .put(EntityType.ENDER_PEARL, null) - .put(EntityType.ENDER_DRAGON, null) .build(); // This is a map of blocks to Material - public static final Map B2M; + private static final Map B2M; static { ImmutableMap.Builder builder = ImmutableMap.builder() .put(Material.POTATOES, Material.POTATO)