Don't set Coll/MapGameRules to null by default; resolves #1004

This commit is contained in:
Tim Daniel Saukel 2021-04-15 17:26:23 +02:00
parent 228345ece0
commit 39bd207302
6 changed files with 19 additions and 16 deletions

View File

@ -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<T, V extends Collection<T>> extends GameRule<V>
/**
* @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<V> copier) {
super(null, key, defaultValue);
Validate.notNull(defaultValue, "defaultValue must not be null");
this.copier = copier;
}

View File

@ -108,20 +108,20 @@ public class GameRule<V> {
* A whitelist of breakable blocks. breakBlocks is supposed to be set to "true" if this should be used.
*/
public static final GameRule<Map<ExItem, HashSet<ExItem>>> 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<Map<ExItem, HashSet<ExItem>>> 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<Set<ExMob>> DAMAGE_PROTECTED_ENTITIES = new CollectionGameRule<>("damageProtectedEntities", null, ConfigReader.EX_MOB_SET_READER, HashSet::new);
public static final GameRule<Set<ExMob>> 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<Set<ExMob>> INTERACTION_PROTECTED_ENTITIES = new CollectionGameRule<>("interactionProtectedEntities", null, ConfigReader.EX_MOB_SET_READER, HashSet::new);
public static final GameRule<Set<ExMob>> 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<V> {
/**
* A whitelist of placeable blocks. placeBlocks is supposed to be set to "true" if this should be used.
*/
public static final GameRule<Set<ExItem>> PLACE_WHITELIST = new CollectionGameRule<>("placeWhitelist", null, ConfigReader.EX_ITEM_SET_READER, HashSet::new);
public static final GameRule<Set<ExItem>> PLACE_WHITELIST = new CollectionGameRule<>("placeWhitelist", new HashSet<>(), ConfigReader.EX_ITEM_SET_READER, HashSet::new);
/**
* A set of blocks that do not fade.
*
* @see <a href="https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/block/BlockFadeEvent.html">org.bukkit.event.block.BlockFadeEvent</a>
*/
public static final GameRule<Set<ExItem>> BLOCK_FADE_DISABLED = new CollectionGameRule<>("blockFadeDisabled", null, ConfigReader.EX_ITEM_SET_READER, HashSet::new);
public static final GameRule<Set<ExItem>> 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<V> {
/**
* One of these Dungeons must be finished ("any" for any dungeon).
*/
public static final GameRule<List<String>> MUST_FINISH_ONE = new CollectionGameRule<>("mustFinishOne", null, ArrayList::new);
public static final GameRule<List<String>> 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<List<String>> MUST_FINISH_ALL = new CollectionGameRule<>("mustFinishAll", null, ArrayList::new);
public static final GameRule<List<String>> 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.
*/

View File

@ -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<TK, TV, V extends Map<TK, TV>> extends GameRule<V> {
/**
* @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<V> reader, Copier<V> copier) {
super(null, key, defaultValue, reader);
Validate.notNull(defaultValue, "defaultValue must not be null");
this.copier = copier;
}

View File

@ -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<String> 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;
}
}
}

View File

@ -602,7 +602,7 @@ public class DGameWorld extends DInstanceWorld implements GameWorld {
}
Set<ExItem> 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;
}

View File

@ -123,7 +123,7 @@ public class DWorldListener implements Listener {
}
Map<ExItem, HashSet<ExItem>> 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<ExItem> 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()))) {