mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Don't set Coll/MapGameRules to null by default; resolves #1004
This commit is contained in:
parent
228345ece0
commit
39bd207302
@ -16,6 +16,7 @@ package de.erethon.dungeonsxl.api.dungeon;
|
|||||||
|
|
||||||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
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 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
|
* @param copier a method to copy the collection
|
||||||
*/
|
*/
|
||||||
public CollectionGameRule(String key, V defaultValue, Copier<V> copier) {
|
public CollectionGameRule(String key, V defaultValue, Copier<V> copier) {
|
||||||
super(null, key, defaultValue);
|
super(null, key, defaultValue);
|
||||||
|
Validate.notNull(defaultValue, "defaultValue must not be null");
|
||||||
this.copier = copier;
|
this.copier = copier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
* 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
|
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.
|
* A blacklist of block types players cannot interact with.
|
||||||
*/
|
*/
|
||||||
public static final GameRule<Map<ExItem, HashSet<ExItem>>> INTERACTION_BLACKLIST
|
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.
|
* 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.
|
* 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.
|
* 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.
|
* 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.
|
* 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>
|
* @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.
|
* 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).
|
* 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.
|
* 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.
|
* This can be used to give rewards. The default implementation does not do this at the moment.
|
||||||
*/
|
*/
|
||||||
|
@ -16,6 +16,7 @@ package de.erethon.dungeonsxl.api.dungeon;
|
|||||||
|
|
||||||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
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 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 reader a functional interface that loads the value from config
|
||||||
* @param copier a method to copy the map
|
* @param copier a method to copy the map
|
||||||
*/
|
*/
|
||||||
public MapGameRule(String key, V defaultValue, ConfigReader<V> reader, Copier<V> copier) {
|
public MapGameRule(String key, V defaultValue, ConfigReader<V> reader, Copier<V> copier) {
|
||||||
super(null, key, defaultValue, reader);
|
super(null, key, defaultValue, reader);
|
||||||
|
Validate.notNull(defaultValue, "defaultValue must not be null");
|
||||||
this.copier = copier;
|
this.copier = copier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,9 +307,9 @@ public class DGlobalPlayer implements GlobalPlayer {
|
|||||||
msgs.forEach(msg -> MessageUtil.sendMessage(player, msg));
|
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));
|
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));
|
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) {
|
if (numOfNeeded < rules.getState(GameRule.MUST_FINISH_ALL).size() || !doneTheOne) {
|
||||||
fulfilled = false;
|
fulfilled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,7 +602,7 @@ public class DGameWorld extends DInstanceWorld implements GameWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<ExItem> whitelist = getRules().getState(GameRule.PLACE_WHITELIST);
|
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);
|
placedBlocks.add(block);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class DWorldListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<ExItem, HashSet<ExItem>> blacklist = gameWorld.getDungeon().getRules().getState(GameRule.INTERACTION_BLACKLIST);
|
Map<ExItem, HashSet<ExItem>> blacklist = gameWorld.getDungeon().getRules().getState(GameRule.INTERACTION_BLACKLIST);
|
||||||
if (blacklist == null) {
|
if (blacklist.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ public class DWorldListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<ExItem> blockFadeDisabled = gameWorld.getGame().getRules().getState(GameRule.BLOCK_FADE_DISABLED);
|
Set<ExItem> blockFadeDisabled = gameWorld.getGame().getRules().getState(GameRule.BLOCK_FADE_DISABLED);
|
||||||
if (blockFadeDisabled == null) {
|
if (blockFadeDisabled.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (gameWorld.getGame() != null && blockFadeDisabled.contains(VanillaItem.get(event.getBlock().getType()))) {
|
if (gameWorld.getGame() != null && blockFadeDisabled.contains(VanillaItem.get(event.getBlock().getType()))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user