diff --git a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 22730eb6..260ba62a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -26,7 +26,6 @@ import io.github.dre2n.dungeonsxl.command.*; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.DataConfig; import io.github.dre2n.dungeonsxl.config.MainConfig; -import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.Dungeons; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.game.GameTypes; @@ -532,13 +531,6 @@ public class DungeonsXL extends BRPlugin { return editWorlds; } - /** - * @return the defaultConfig - */ - public WorldConfig getDefaultConfig() { - return WorldConfig.defaultConfig;// TODO - } - /** * @return the gameWorlds */ diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java index 86383c78..af3d7e4f 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DungeonConfig.java @@ -16,57 +16,33 @@ */ package io.github.dre2n.dungeonsxl.config; +import io.github.dre2n.commons.config.BRConfig; import java.io.File; import java.util.ArrayList; import java.util.List; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; /** * @author Daniel Saukel */ -public class DungeonConfig extends WorldConfig { +public class DungeonConfig extends BRConfig { + + public static final int CONFIG_VERSION = 1; private String startFloor; private String endFloor; private List floors = new ArrayList<>(); private int floorCount; private boolean removeWhenPlayed; + private WorldConfig overrideValues; + private WorldConfig defaultValues; public DungeonConfig(File file) { - super(file); - load(YamlConfiguration.loadConfiguration(file)); - } + super(file, CONFIG_VERSION); - public DungeonConfig(ConfigurationSection configFile) { - super(configFile); - load(configFile); - } - - @Override - public void load(ConfigurationSection configFile) { - super.load(configFile); - - /* Floors */ - if (configFile.contains("floors")) { - floors = configFile.getStringList("floors"); - } - - if (configFile.contains("startFloor")) { - startFloor = configFile.getString("startFloor"); - } - - if (configFile.contains("endFloor")) { - endFloor = configFile.getString("endFloor"); - } - - if (configFile.contains("floorCount")) { - floorCount = configFile.getInt("floorCount"); - } - - if (configFile.contains("removeWhenPlayed")) { - removeWhenPlayed = configFile.getBoolean("removeWhenPlayed"); + if (initialize) { + initialize(); } + load(); } /** @@ -152,4 +128,105 @@ public class DungeonConfig extends WorldConfig { this.removeWhenPlayed = removeWhenPlayed; } + /** + * The values from this WorldConfig will override all values of the + * WorldConfigs of inherited maps. + * + * @return the override values + */ + public WorldConfig getOverrideValues() { + return overrideValues; + } + + /** + * @param worldConfig + * the WorldConfig to set + */ + public void setOverrideValues(WorldConfig worldConfig) { + overrideValues = worldConfig; + } + + /** + * The values from this WorldConfig will get overriden by values of the + * WorldConfigs of inherited maps. + * They will still override the values from the main config, though. + * + * @return the default values + */ + public WorldConfig getDefaultValues() { + return defaultValues; + } + + /** + * @param worldConfig + * the WorldConfig to set + */ + public void setDefaultValues(WorldConfig worldConfig) { + defaultValues = worldConfig; + } + + @Override + public void initialize() { + if (!config.contains("floors")) { + config.set("floors", floors); + } + + if (!config.contains("startFloor")) { + config.set("startFloor", startFloor); + } + + if (!config.contains("endFloor")) { + config.set("endFloor", endFloor); + } + + if (!config.contains("floorCount")) { + config.set("floorCount", floorCount); + } + + if (!config.contains("removeWhenPlayed")) { + config.set("removeWhenPlayed", removeWhenPlayed); + } + + if (!config.contains("overrideValues")) { + config.createSection("overrideValues"); + } + + if (!config.contains("defaultValues")) { + config.createSection("defaultValues"); + } + + save(); + } + + @Override + public void load() { + if (config.contains("floors")) { + floors = config.getStringList("floors"); + } + + if (config.contains("startFloor")) { + startFloor = config.getString("startFloor"); + } + + if (config.contains("endFloor")) { + endFloor = config.getString("endFloor"); + } + + if (config.contains("floorCount")) { + floorCount = config.getInt("floorCount"); + } + + if (config.contains("removeWhenPlayed")) { + removeWhenPlayed = config.getBoolean("removeWhenPlayed"); + } + + if (config.contains("overrideValues")) { + overrideValues = new WorldConfig(config.getConfigurationSection("overrideValues")); + } + + if (config.contains("defaultValues")) { + defaultValues = new WorldConfig(config.getConfigurationSection("defaultValues")); + } + } + } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index 9f25cf0b..8cb7120e 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -301,7 +301,6 @@ public class MainConfig extends BRConfig { ConfigurationSection configSection = config.getConfigurationSection("default"); if (configSection != null) { defaultWorldConfig = new WorldConfig(configSection); - WorldConfig.defaultConfig = defaultWorldConfig;// TODO } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index a560b5fa..336ca752 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -19,20 +19,17 @@ package io.github.dre2n.dungeonsxl.config; import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.mob.DMobType; import io.github.dre2n.dungeonsxl.player.DClass; import io.github.dre2n.dungeonsxl.requirement.FeeLevelRequirement; import io.github.dre2n.dungeonsxl.requirement.FeeMoneyRequirement; import io.github.dre2n.dungeonsxl.requirement.Requirement; -import io.github.dre2n.dungeonsxl.reward.Reward; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.GameMode; @@ -46,58 +43,15 @@ import org.bukkit.inventory.ItemStack; /** * @author Frank Baumann, Milan Albrecht, Daniel Saukel */ -public class WorldConfig { +public class WorldConfig extends GameRules { DungeonsXL plugin = DungeonsXL.getInstance(); - @Deprecated - public static WorldConfig defaultConfig = new WorldConfig(); - private File file; private List invitedPlayers = new ArrayList<>(); - - private boolean keepInventory = false; - private boolean keepInventoryOnEnter = false; - private boolean keepInventoryOnEscape = false; - private boolean keepInventoryOnFinish = false; - private boolean keepInventoryOnDeath = true; - - private GameMode gameMode = GameMode.SURVIVAL; - private boolean build = false; - - private boolean playerVersusPlayer = false; - private boolean friendlyFire = false; - - private List dClasses = new ArrayList<>(); - private Map msgs = new HashMap<>(); - - private List secureObjects = new ArrayList<>(); - - private int initialLives = 3; - - private boolean isLobbyDisabled = false; - private int timeToNextPlay = 0; - private int timeToNextLoot = 0; - private int timeToNextWave = 10; - - private int timeUntilKickOfflinePlayer = -1; - private int timeToFinish = -1; - - private List requirements = new ArrayList<>(); - private List rewards = new ArrayList<>(); - - private List finishedOne; - private List finishedAll; - private int timeLastPlayed = 0; - private GameType forcedGameType; - private Set mobTypes = new HashSet<>(); - - private List gameCommandWhitelist = new ArrayList<>(); - private List gamePermissions = new ArrayList<>(); - public WorldConfig() { } @@ -208,41 +162,27 @@ public class WorldConfig { if (!configFile.contains("keepInventoryOnFinish")) { keepInventoryOnFinish = configFile.getBoolean("keepInventory"); } - } else if (plugin.getDefaultConfig().keepInventory) { - keepInventoryOnEnter = plugin.getDefaultConfig().keepInventory; - keepInventoryOnEscape = plugin.getDefaultConfig().keepInventory; - keepInventoryOnFinish = plugin.getDefaultConfig().keepInventory; } if (configFile.contains("keepInventoryOnEnter")) { keepInventoryOnEnter = configFile.getBoolean("keepInventoryOnEnter"); - } else { - keepInventoryOnEnter = plugin.getDefaultConfig().keepInventoryOnEnter; } if (configFile.contains("keepInventoryOnEscape")) { keepInventoryOnEscape = configFile.getBoolean("keepInventoryOnEscape"); - } else { - keepInventoryOnEscape = plugin.getDefaultConfig().keepInventoryOnEscape; } if (configFile.contains("keepInventoryOnFinish")) { keepInventoryOnFinish = configFile.getBoolean("keepInventoryOnFinish"); - } else { - keepInventoryOnFinish = plugin.getDefaultConfig().keepInventoryOnFinish; } if (configFile.contains("keepInventoryOnDeath")) { keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath"); - } else { - keepInventoryOnDeath = plugin.getDefaultConfig().keepInventoryOnDeath; } /* Build */ if (configFile.contains("build")) { build = configFile.getBoolean("build"); - } else { - build = plugin.getDefaultConfig().build; } /* GameMode */ @@ -252,67 +192,47 @@ public class WorldConfig { } else { gameMode = GameMode.getByValue(configFile.getInt("gameMode")); } - } else { - gameMode = plugin.getDefaultConfig().gameMode; } /* PvP */ if (configFile.contains("playerVersusPlayer")) { playerVersusPlayer = configFile.getBoolean("playerVersusPlayer"); - } else { - playerVersusPlayer = plugin.getDefaultConfig().playerVersusPlayer; } /* Friendly fire */ if (configFile.contains("friendlyFire")) { friendlyFire = configFile.getBoolean("friendlyFire"); - } else { - friendlyFire = plugin.getDefaultConfig().friendlyFire; } /* Lives */ if (configFile.contains("initialLives")) { initialLives = configFile.getInt("initialLives"); - } else { - initialLives = plugin.getDefaultConfig().getInitialLives(); } /* Lobby */ if (configFile.contains("isLobbyDisabled")) { - isLobbyDisabled = configFile.getBoolean("isLobbyDisabled"); - } else { - isLobbyDisabled = plugin.getDefaultConfig().isLobbyDisabled; + lobbyDisabled = configFile.getBoolean("isLobbyDisabled"); } /* Times */ if (configFile.contains("timeToNextPlay")) { timeToNextPlay = configFile.getInt("timeToNextPlay"); - } else { - timeToNextPlay = plugin.getDefaultConfig().timeToNextPlay; } if (configFile.contains("timeToNextLoot")) { timeToNextLoot = configFile.getInt("timeToNextLoot"); - } else { - timeToNextLoot = plugin.getDefaultConfig().timeToNextLoot; } if (configFile.contains("timeToNextWave")) { timeToNextWave = configFile.getInt("timeToNextWave"); - } else { - timeToNextWave = plugin.getDefaultConfig().timeToNextWave; } if (configFile.contains("timeUntilKickOfflinePlayer")) { timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer"); - } else { - timeUntilKickOfflinePlayer = plugin.getDefaultConfig().timeUntilKickOfflinePlayer; } if (configFile.contains("timeToFinish")) { timeToFinish = configFile.getInt("timeToFinish"); - } else { - timeToFinish = plugin.getDefaultConfig().timeToFinish; } /* Dungeon Requirements */ @@ -330,8 +250,6 @@ public class WorldConfig { requirements.add(requirement); } - } else { - requirements = plugin.getDefaultConfig().requirements; } if (configFile.contains("mustFinishOne")) { @@ -356,14 +274,10 @@ public class WorldConfig { if (configFile.contains("gameCommandWhitelist")) { gameCommandWhitelist = configFile.getStringList("gameCommandWhitelist"); - } else { - gameCommandWhitelist = plugin.getDefaultConfig().gameCommandWhitelist; } if (configFile.contains("gamePermissions")) { gamePermissions = configFile.getStringList("gamePermissions"); - } else { - gamePermissions = plugin.getDefaultConfig().gamePermissions; } if (configFile.contains("forcedGameType")) { @@ -408,14 +322,12 @@ public class WorldConfig { } } - // Getters and Setters /** * @return the UUIDs or names of the players invited to edit the map */ public CopyOnWriteArrayList getInvitedPlayers() { CopyOnWriteArrayList tmpInvitedPlayers = new CopyOnWriteArrayList<>(); tmpInvitedPlayers.addAll(invitedPlayers); - tmpInvitedPlayers.addAll(plugin.getDefaultConfig().invitedPlayers); return tmpInvitedPlayers; } @@ -439,248 +351,6 @@ public class WorldConfig { invitedPlayers.remove(name); } - /** - * @return the classes - */ - public List getClasses() { - if (dClasses != null) { - if (!dClasses.isEmpty()) { - return dClasses; - } - } - - return plugin.getDefaultConfig().dClasses; - } - - /** - * @param name - * the name of the class - */ - public DClass getClass(String name) { - for (DClass dClass : dClasses) { - if (dClass.getName().equals(name)) { - return dClass; - } - } - - for (DClass dClass : plugin.getDefaultConfig().dClasses) { - if (dClass.getName().equals(name)) { - return dClass; - } - } - return null; - } - - /** - * @param id - * the id of the message - * @param returnMainConfig - * if a default value shall be returned - */ - public String getMsg(int id, boolean returnMainConfig) { - String msg = msgs.get(id); - if (msg != null) { - return msgs.get(id); - } - if (returnMainConfig) { - return plugin.getDefaultConfig().msgs.get(id); - } - - return null; - } - - /** - * @param msg - * the message to set - * @param id - * the ID of the message - */ - public void setMsg(String msg, int id) { - msgs.put(id, msg); - } - - /** - * @return the objects to get passed to another player of the group when this player leaves - */ - public CopyOnWriteArrayList getSecureObjects() { - CopyOnWriteArrayList tmpSecureObjects = new CopyOnWriteArrayList<>(); - tmpSecureObjects.addAll(secureObjects); - tmpSecureObjects.addAll(plugin.getDefaultConfig().secureObjects); - return tmpSecureObjects; - } - - /** - * @return if the inventory shall be kept when the player enters the dungeon - */ - public boolean getKeepInventoryOnEnter() { - return keepInventoryOnEnter; - } - - /** - * @return if the inventory shall be kept when the player leaves the dungeon successlessly - */ - public boolean getKeepInventoryOnEscape() { - return keepInventoryOnEscape; - } - - /** - * @return if the inventory shall be kept when the player finishs the dungeon - */ - public boolean getKeepInventoryOnFinish() { - return keepInventoryOnFinish; - } - - /** - * @return if the inventory shall be kept on death - */ - public boolean getKeepInventoryOnDeath() { - return keepInventoryOnDeath; - } - - /** - * @return the gameMode - */ - public GameMode getGameMode() { - return gameMode; - } - - /** - * @return if players may build - */ - public boolean canBuild() { - return build; - } - - /** - * @return if players may attack each other - */ - public boolean isPlayerVersusPlayer() { - return playerVersusPlayer; - } - - /** - * @return if players may attack group members - */ - public boolean isFriendlyFire() { - return friendlyFire; - } - - /** - * @return the initial amount of lives - */ - public int getInitialLives() { - return initialLives; - } - - /** - * @return if the lobby is disabled - */ - public boolean isLobbyDisabled() { - return isLobbyDisabled; - } - - /** - * @return the time until a player can play again - */ - public int getTimeToNextPlay() { - return timeToNextPlay; - } - - /** - * @return the time until a player can get loot again - */ - public int getTimeToNextLoot() { - return timeToNextLoot; - } - - /** - * @return the break between two waves - */ - public int getTimeToNextWave() { - return timeToNextWave; - } - - /** - * @return the time until a player gets kicked from his group if he is offline - */ - public int getTimeUntilKickOfflinePlayer() { - return timeUntilKickOfflinePlayer; - } - - /** - * @return if the game is "time is running" - */ - public boolean isTimeIsRunning() { - return timeToFinish != -1; - } - - /** - * @return the time until a player gets kicked from his group - */ - public int getTimeToFinish() { - return timeToFinish; - } - - /** - * @return the requirements - */ - public List getRequirements() { - return requirements; - } - - /** - * @return the rewards - */ - public List getRewards() { - return rewards; - } - - /** - * @return the timeLastPlayed - */ - public int getTimeLastPlayed() { - return timeLastPlayed; - } - - /** - * @return all maps needed to be finished to play this map - */ - public List getFinishedAll() { - return finishedAll; - } - - /** - * @return all maps needed to be finished to play this map and a collection of maps of which at - * least one has to be finished - */ - public List getFinished() { - List merge = new ArrayList<>(); - merge.addAll(finishedAll); - merge.addAll(finishedOne); - return merge; - } - - /** - * @return the mobTypes - */ - public Set getMobTypes() { - return mobTypes; - } - - /** - * @return the gameCommandWhitelist - */ - public List getGameCommandWhitelist() { - return gameCommandWhitelist; - } - - /** - * @return the gamePermissions - */ - public List getGamePermissions() { - return gamePermissions; - } - /** * @return the forcedGameType */ diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index c3b0d514..a120c122 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -19,6 +19,8 @@ package io.github.dre2n.dungeonsxl.game; import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.config.DungeonConfig; +import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.global.GameSign; import io.github.dre2n.dungeonsxl.player.DGroup; @@ -47,6 +49,7 @@ public class Game { private boolean started; private GameType type; private GameWorld world; + private GameRules rules; private int waveCount; private Map gameKills = new HashMap<>(); private Map waveKills = new HashMap<>(); @@ -136,13 +139,71 @@ public class Game { } /** - * @param gameWorld + * @param world * the GameWorld to connect to the Game */ public void setWorld(GameWorld world) { this.world = world; } + /** + * @return the GameRules + */ + public GameRules getRules() { + return rules; + } + + /** + * @param rules + * the GameRules to set + */ + public void setRules(GameRules rules) { + this.rules = rules; + } + + /** + * Fetchs the rules with the following priority: + * 1. Game type + * 2. Dungeon config: Override values + * 3. Floor config + * 4. Dungeon config: Default values + * 5. Main config: Default values + * 6. The default values + */ + public void fetchRules() { + DungeonConfig dungeonConfig = null; + if (getDungeon() != null) { + dungeonConfig = getDungeon().getConfig(); + } + + WorldConfig floorConfig = null; + if (world != null) { + floorConfig = world.getConfig(); + } + + GameRules finalRules = new GameRules(); + + if (type != null) { + finalRules.apply(type); + } + + if (dungeonConfig != null) { + finalRules.apply(dungeonConfig.getOverrideValues()); + } + + if (floorConfig != null) { + finalRules.apply(floorConfig); + } + + if (getDungeon() != null) { + finalRules.apply(dungeonConfig.getDefaultValues()); + } + + finalRules.apply(plugin.getMainConfig().getDefaultWorldConfig()); + + finalRules.apply(GameRules.DEFAULT_VALUES); + } + /** * Refers to the DGroup with the best progress. * diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java new file mode 100644 index 00000000..9ca4cd4e --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -0,0 +1,520 @@ +/* + * Copyright (C) 2016 Daniel Saukel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.game; + +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.mob.DMobType; +import io.github.dre2n.dungeonsxl.player.DClass; +import io.github.dre2n.dungeonsxl.requirement.Requirement; +import io.github.dre2n.dungeonsxl.reward.Reward; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; +import org.bukkit.GameMode; +import org.bukkit.Material; + +/** + * @author Daniel Saukel + */ +public class GameRules { + + public static final GameRules DEFAULT_VALUES = new GameRules(); + + static { + /* keepInventory */ + DEFAULT_VALUES.keepInventoryOnEnter = false; + DEFAULT_VALUES.keepInventoryOnEscape = false; + DEFAULT_VALUES.keepInventoryOnFinish = false; + DEFAULT_VALUES.keepInventoryOnDeath = true; + DEFAULT_VALUES.lobbyDisabled = false; + + /* World interaction */ + DEFAULT_VALUES.gameMode = GameMode.SURVIVAL; + DEFAULT_VALUES.build = false; + + /* Fighting */ + DEFAULT_VALUES.playerVersusPlayer = false; + DEFAULT_VALUES.friendlyFire = false; + DEFAULT_VALUES.initialLives = 3; + + /* Timer */ + DEFAULT_VALUES.timeLastPlayed = 0; + DEFAULT_VALUES.timeToNextPlay = 0; + DEFAULT_VALUES.timeToNextLoot = 0; + DEFAULT_VALUES.timeToNextWave = 10; + DEFAULT_VALUES.timeToFinish = -1; + DEFAULT_VALUES.timeUntilKickOfflinePlayer = -1; + + /* Requirements and rewards */ + DEFAULT_VALUES.requirements = new ArrayList<>(); + DEFAULT_VALUES.finishedOne = null; + DEFAULT_VALUES.finishedAll = null; + DEFAULT_VALUES.rewards = new ArrayList<>(); + + /* Scripts */ + DEFAULT_VALUES.dClasses = new ArrayList<>(); + DEFAULT_VALUES.mobTypes = new HashSet<>(); + + /* Commands and permissions */ + DEFAULT_VALUES.gameCommandWhitelist = new ArrayList<>(); + DEFAULT_VALUES.gamePermissions = new ArrayList<>(); + + /* Misc */ + DEFAULT_VALUES.msgs = new HashMap<>(); + DEFAULT_VALUES.secureObjects = new ArrayList<>(); + } + + /* keepInventory */ + protected Boolean keepInventoryOnEnter; + protected Boolean keepInventoryOnEscape; + protected Boolean keepInventoryOnFinish; + protected Boolean keepInventoryOnDeath; + protected Boolean lobbyDisabled; + + /* World interaction */ + protected GameMode gameMode; + protected Boolean build; + + /* Fighting */ + protected Boolean playerVersusPlayer; + protected Boolean friendlyFire; + protected Integer initialLives; + + /* Timer */ + protected Integer timeLastPlayed; + protected Integer timeToNextPlay; + protected Integer timeToNextLoot; + protected Integer timeToNextWave; + protected Integer timeToFinish; + protected Integer timeUntilKickOfflinePlayer; + + /* Requirements and rewards */ + protected List requirements; + protected List finishedOne; + protected List finishedAll; + protected List rewards; + + /* Scripts */ + protected List dClasses; + protected Set mobTypes; + + /* Commands and permissions */ + protected List gameCommandWhitelist; + protected List gamePermissions; + + /* Misc */ + protected Map msgs; + protected List secureObjects; + + /* Getters and setters */ + /** + * @return the classes + */ + public List getClasses() { + if (dClasses != null) { + if (!dClasses.isEmpty()) { + return dClasses; + } + } + + return new ArrayList<>(); + } + + /** + * @param name + * the name of the class + */ + public DClass getClass(String name) { + for (DClass dClass : dClasses) { + if (dClass.getName().equals(name)) { + return dClass; + } + } + + return null; + } + + // keepInventory + /** + * @return if the inventory shall be kept when the player enters the dungeon + */ + public boolean getKeepInventoryOnEnter() { + return keepInventoryOnEnter; + } + + /** + * @return if the inventory shall be kept when the player leaves the dungeon successlessly + */ + public boolean getKeepInventoryOnEscape() { + return keepInventoryOnEscape; + } + + /** + * @return if the inventory shall be kept when the player finishs the dungeon + */ + public boolean getKeepInventoryOnFinish() { + return keepInventoryOnFinish; + } + + /** + * @return if the inventory shall be kept on death + */ + public boolean getKeepInventoryOnDeath() { + return keepInventoryOnDeath; + } + + /** + * @return if the lobby is disabled + */ + public boolean isLobbyDisabled() { + return lobbyDisabled; + } + + // World interaction + /** + * @return the gameMode + */ + public GameMode getGameMode() { + return gameMode; + } + + /** + * @return if players may build + */ + public boolean canBuild() { + return build; + } + + // Fight + /** + * @return if players may attack each other + */ + public boolean isPlayerVersusPlayer() { + return playerVersusPlayer; + } + + /** + * @return if players may attack group members + */ + public boolean isFriendlyFire() { + return friendlyFire; + } + + /** + * @return the initial amount of lives + */ + public int getInitialLives() { + return initialLives; + } + + // Timer + /** + * @return the timeLastPlayed + */ + public int getTimeLastPlayed() { + return timeLastPlayed; + } + + /** + * @return the time until a player can play again + */ + public int getTimeToNextPlay() { + return timeToNextPlay; + } + + /** + * @return the time until a player can get loot again + */ + public int getTimeToNextLoot() { + return timeToNextLoot; + } + + /** + * @return the break between two waves + */ + public int getTimeToNextWave() { + return timeToNextWave; + } + + /** + * @return the time until a player gets kicked from his group + */ + public int getTimeToFinish() { + return timeToFinish; + } + + /** + * @return the time until a player gets kicked from his group if he is offline + */ + public int getTimeUntilKickOfflinePlayer() { + return timeUntilKickOfflinePlayer; + } + + /** + * @return if the game is "time is running" + */ + public boolean isTimeIsRunning() { + return timeToFinish != -1; + } + + // Requirements and rewards + /** + * @return the requirements + */ + public List getRequirements() { + return requirements; + } + + /** + * @return all maps needed to be finished to play this map + */ + public List getFinishedAll() { + return finishedAll; + } + + /** + * @return all maps needed to be finished to play this map and a collection of maps of which at + * least one has to be finished + */ + public List getFinished() { + List merge = new ArrayList<>(); + merge.addAll(finishedAll); + merge.addAll(finishedOne); + return merge; + } + + /** + * @return the rewards + */ + public List getRewards() { + return rewards; + } + + // Scripts + /** + * @return the mobTypes + */ + public Set getMobTypes() { + return mobTypes; + } + + // Commands and permissions + /** + * @return the gameCommandWhitelist + */ + public List getGameCommandWhitelist() { + return gameCommandWhitelist; + } + + /** + * @return the gamePermissions + */ + public List getGamePermissions() { + return gamePermissions; + } + + // Misc + /** + * @param id + * the id of the message + * @param returnMainConfig + * if a default value shall be returned + */ + public String getMsg(int id, boolean returnMainConfig) { + String msg = msgs.get(id); + if (msg != null) { + return msgs.get(id); + } + if (returnMainConfig) { + return DungeonsXL.getInstance().getMainConfig().getDefaultWorldConfig().msgs.get(id); + } + + return null; + } + + /** + * @param msg + * the message to set + * @param id + * the ID of the message + */ + public void setMsg(String msg, int id) { + msgs.put(id, msg); + } + + /** + * @return the objects to get passed to another player of the group when this player leaves + */ + public CopyOnWriteArrayList getSecureObjects() { + CopyOnWriteArrayList tmpSecureObjects = new CopyOnWriteArrayList<>(); + tmpSecureObjects.addAll(secureObjects); + return tmpSecureObjects; + } + + /* Actions */ + /** + * @param defaultValues + * the GameType that overrides the values that are null. + */ + public void apply(GameType defaultValues) { + if (playerVersusPlayer == null) { + playerVersusPlayer = defaultValues.isPlayerVersusPlayer(); + } + + if (friendlyFire == null) { + friendlyFire = defaultValues.isFriendlyFire(); + } + + if (timeToFinish == null) { + timeToFinish = defaultValues.getShowTime() ? null : -1; + } + + if (build == null) { + build = defaultValues.canBuild(); + } + + if (gameMode == null) { + gameMode = defaultValues.getGameMode(); + } + } + + /** + * @param defaultValues + * the GameRules that override the values that are null. + */ + public void apply(GameRules defaultValues) { + /* keepInventory */ + if (keepInventoryOnEnter == null) { + keepInventoryOnEnter = defaultValues.keepInventoryOnEnter; + } + + if (keepInventoryOnEscape == null) { + keepInventoryOnEscape = defaultValues.keepInventoryOnEscape; + } + + if (keepInventoryOnFinish == null) { + keepInventoryOnFinish = defaultValues.keepInventoryOnFinish; + } + + if (keepInventoryOnDeath == null) { + keepInventoryOnDeath = defaultValues.keepInventoryOnDeath; + } + + if (lobbyDisabled == null) { + lobbyDisabled = defaultValues.lobbyDisabled; + } + + /* World interaction */ + if (gameMode == null) { + gameMode = defaultValues.gameMode; + } + + if (build == null) { + build = defaultValues.build; + } + + /* Fighting */ + if (playerVersusPlayer == null) { + playerVersusPlayer = defaultValues.playerVersusPlayer; + } + + if (friendlyFire == null) { + friendlyFire = defaultValues.friendlyFire; + } + + if (initialLives == null) { + initialLives = defaultValues.initialLives; + } + + /* Timer */ + if (timeLastPlayed == null) { + timeLastPlayed = defaultValues.timeLastPlayed; + } + + if (timeToNextPlay == null) { + timeToNextPlay = defaultValues.timeToNextPlay; + } + + if (timeToNextLoot == null) { + timeToNextLoot = defaultValues.timeToNextLoot; + } + + if (timeToNextWave == null) { + timeToNextWave = defaultValues.timeToNextWave; + } + + if (timeToFinish == null) { + timeToFinish = defaultValues.timeToFinish; + } + + if (timeUntilKickOfflinePlayer == null) { + timeUntilKickOfflinePlayer = defaultValues.timeUntilKickOfflinePlayer; + } + + /* Requirements and rewards */ + if (requirements == null) { + requirements = defaultValues.requirements; + } + + if (finishedOne == null) { + finishedOne = defaultValues.finishedOne; + } + + if (finishedAll == null) { + finishedAll = defaultValues.finishedAll; + } + + if (rewards == null) { + rewards = defaultValues.rewards; + } + + /* Scripts */ + if (dClasses == null) { + dClasses = defaultValues.dClasses; + } else if (defaultValues.dClasses != null) { + dClasses.addAll(defaultValues.dClasses); + } + + if (mobTypes == null) { + mobTypes = defaultValues.mobTypes; + } else if (defaultValues.mobTypes != null) { + mobTypes.addAll(defaultValues.mobTypes); + } + + /* Commands and permissions */ + if (gameCommandWhitelist == null) { + gameCommandWhitelist = defaultValues.gameCommandWhitelist; + } else if (defaultValues.gameCommandWhitelist != null) { + gameCommandWhitelist.addAll(defaultValues.gameCommandWhitelist); + } + + if (gamePermissions == null) { + gamePermissions = defaultValues.gamePermissions; + } else if (defaultValues.gamePermissions != null) { + gamePermissions.addAll(defaultValues.gamePermissions); + } + + /* Misc */ + msgs = defaultValues.msgs; + secureObjects = defaultValues.secureObjects; + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java index f8a96cf4..fb14bc4b 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java @@ -361,7 +361,7 @@ public class GameWorld { */ public WorldConfig getConfig() { if (worldConfig == null) { - return plugin.getDefaultConfig(); + return plugin.getMainConfig().getDefaultWorldConfig(); } return worldConfig;