diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/CollectionGameRule.java b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/CollectionGameRule.java index 01487866..7b51279b 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/CollectionGameRule.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/CollectionGameRule.java @@ -16,6 +16,7 @@ package de.erethon.dungeonsxl.api.dungeon; import de.erethon.dungeonsxl.api.DungeonsAPI; import java.util.Collection; +import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; /** @@ -31,11 +32,12 @@ public class CollectionGameRule> extends GameRule /** * @param key the configuration key of the game rule - * @param defaultValue the default value that is used when nothing is set + * @param defaultValue the default value that is used when nothing is set; not null * @param copier a method to copy the collection */ public CollectionGameRule(String key, V defaultValue, Copier copier) { super(null, key, defaultValue); + Validate.notNull(defaultValue, "defaultValue must not be null"); this.copier = copier; } diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java index f269fb9e..4d4f15c0 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java @@ -108,20 +108,20 @@ public class GameRule { * A whitelist of breakable blocks. breakBlocks is supposed to be set to "true" if this should be used. */ public static final GameRule>> BREAK_WHITELIST - = new MapGameRule<>("breakWhitelist", null, ConfigReader.TOOL_BLOCK_MAP_READER, HashMap::new); + = new MapGameRule<>("breakWhitelist", new HashMap<>(), ConfigReader.TOOL_BLOCK_MAP_READER, HashMap::new); /** * A blacklist of block types players cannot interact with. */ public static final GameRule>> INTERACTION_BLACKLIST - = new MapGameRule<>("interactionBlacklist", null, ConfigReader.TOOL_BLOCK_MAP_READER, HashMap::new); + = new MapGameRule<>("interactionBlacklist", new HashMap<>(), ConfigReader.TOOL_BLOCK_MAP_READER, HashMap::new); /** * A list of all entity types that shall be protected from damage. */ - public static final GameRule> DAMAGE_PROTECTED_ENTITIES = new CollectionGameRule<>("damageProtectedEntities", null, ConfigReader.EX_MOB_SET_READER, HashSet::new); + public static final GameRule> DAMAGE_PROTECTED_ENTITIES = new CollectionGameRule<>("damageProtectedEntities", new HashSet<>(), ConfigReader.EX_MOB_SET_READER, HashSet::new); /** * A list of all entity types that shall be protected from interaction. */ - public static final GameRule> INTERACTION_PROTECTED_ENTITIES = new CollectionGameRule<>("interactionProtectedEntities", null, ConfigReader.EX_MOB_SET_READER, HashSet::new); + public static final GameRule> INTERACTION_PROTECTED_ENTITIES = new CollectionGameRule<>("interactionProtectedEntities", new HashSet<>(), ConfigReader.EX_MOB_SET_READER, HashSet::new); /** * If blocks may be placed. */ @@ -129,13 +129,13 @@ public class GameRule { /** * A whitelist of placeable blocks. placeBlocks is supposed to be set to "true" if this should be used. */ - public static final GameRule> PLACE_WHITELIST = new CollectionGameRule<>("placeWhitelist", null, ConfigReader.EX_ITEM_SET_READER, HashSet::new); + public static final GameRule> PLACE_WHITELIST = new CollectionGameRule<>("placeWhitelist", new HashSet<>(), ConfigReader.EX_ITEM_SET_READER, HashSet::new); /** * A set of blocks that do not fade. * * @see org.bukkit.event.block.BlockFadeEvent */ - public static final GameRule> BLOCK_FADE_DISABLED = new CollectionGameRule<>("blockFadeDisabled", null, ConfigReader.EX_ITEM_SET_READER, HashSet::new); + public static final GameRule> BLOCK_FADE_DISABLED = new CollectionGameRule<>("blockFadeDisabled", new HashSet<>(), ConfigReader.EX_ITEM_SET_READER, HashSet::new); /** * This does what the doFireTick Vanilla game rule does. */ @@ -242,11 +242,11 @@ public class GameRule { /** * One of these Dungeons must be finished ("any" for any dungeon). */ - public static final GameRule> MUST_FINISH_ONE = new CollectionGameRule<>("mustFinishOne", null, ArrayList::new); + public static final GameRule> MUST_FINISH_ONE = new CollectionGameRule<>("mustFinishOne", new ArrayList<>(), ArrayList::new); /** * All of these Dungeons must be finished. If you do not want any, leave this empty. */ - public static final GameRule> MUST_FINISH_ALL = new CollectionGameRule<>("mustFinishAll", null, ArrayList::new); + public static final GameRule> MUST_FINISH_ALL = new CollectionGameRule<>("mustFinishAll", new ArrayList<>(), ArrayList::new); /** * This can be used to give rewards. The default implementation does not do this at the moment. */ diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/MapGameRule.java b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/MapGameRule.java index f1f793a3..a49d940b 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/MapGameRule.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/MapGameRule.java @@ -16,6 +16,7 @@ package de.erethon.dungeonsxl.api.dungeon; import de.erethon.dungeonsxl.api.DungeonsAPI; import java.util.Map; +import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; /** @@ -32,12 +33,13 @@ public class MapGameRule> extends GameRule { /** * @param key the configuration key of the game rule - * @param defaultValue the default value that is used when nothing is set + * @param defaultValue the default value that is used when nothing is set; not null * @param reader a functional interface that loads the value from config * @param copier a method to copy the map */ public MapGameRule(String key, V defaultValue, ConfigReader reader, Copier copier) { super(null, key, defaultValue, reader); + Validate.notNull(defaultValue, "defaultValue must not be null"); this.copier = copier; } diff --git a/core/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java index 616da56b..8e76f345 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java @@ -307,9 +307,9 @@ public class DGlobalPlayer implements GlobalPlayer { msgs.forEach(msg -> MessageUtil.sendMessage(player, msg)); } - if (rules.getState(GameRule.MUST_FINISH_ALL) != null) { + if (!rules.getState(GameRule.MUST_FINISH_ALL).isEmpty()) { List finished = new ArrayList<>(rules.getState(GameRule.MUST_FINISH_ALL)); - if (rules.getState(GameRule.MUST_FINISH_ONE) != null) { + if (!rules.getState(GameRule.MUST_FINISH_ONE).isEmpty()) { finished.addAll(rules.getState(GameRule.MUST_FINISH_ONE)); } @@ -358,7 +358,6 @@ public class DGlobalPlayer implements GlobalPlayer { if (numOfNeeded < rules.getState(GameRule.MUST_FINISH_ALL).size() || !doneTheOne) { fulfilled = false; } - } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java b/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java index 5f471d72..ffd244a5 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java @@ -602,7 +602,7 @@ public class DGameWorld extends DInstanceWorld implements GameWorld { } Set whitelist = getRules().getState(GameRule.PLACE_WHITELIST); - if (whitelist == null || whitelist.contains(VanillaItem.get(block.getType()))) { + if (whitelist.isEmpty() || whitelist.contains(VanillaItem.get(block.getType()))) { placedBlocks.add(block); return false; } diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java b/core/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java index 4ec044d3..18706fa5 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java @@ -123,7 +123,7 @@ public class DWorldListener implements Listener { } Map> blacklist = gameWorld.getDungeon().getRules().getState(GameRule.INTERACTION_BLACKLIST); - if (blacklist == null) { + if (blacklist.isEmpty()) { return; } @@ -254,7 +254,7 @@ public class DWorldListener implements Listener { } Set blockFadeDisabled = gameWorld.getGame().getRules().getState(GameRule.BLOCK_FADE_DISABLED); - if (blockFadeDisabled == null) { + if (blockFadeDisabled.isEmpty()) { return; } if (gameWorld.getGame() != null && blockFadeDisabled.contains(VanillaItem.get(event.getBlock().getType()))) {