From 284c03f029a3d60ea5c876f4a1d85a9fd0f633ad Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 5 Jul 2016 18:39:49 +0200 Subject: [PATCH] Several fixes --- pom.xml | 2 +- .../dre2n/dungeonsxl/command/MsgCommand.java | 9 ++- .../dre2n/dungeonsxl/config/DMessages.java | 2 +- .../dre2n/dungeonsxl/config/WorldConfig.java | 8 +-- .../io/github/dre2n/dungeonsxl/game/Game.java | 4 +- .../dre2n/dungeonsxl/game/GameRules.java | 63 ++++++++++++++----- .../dungeonsxl/listener/PlayerListener.java | 2 - .../dre2n/dungeonsxl/sign/MessageSign.java | 6 +- .../dungeonsxl/sign/SoundMessageSign.java | 2 +- 9 files changed, 62 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 602099db..3194109d 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ io.github.dre2n debukkit - 1.0 + 2.1 io.github.dre2n diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java index 99d37b66..8ca129ab 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/MsgCommand.java @@ -17,7 +17,6 @@ package io.github.dre2n.dungeonsxl.command; import io.github.dre2n.commons.command.BRCommand; -import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; @@ -60,12 +59,12 @@ public class MsgCommand extends BRCommand { } try { - int id = NumberUtil.parseInt(args[1]); + int id = Integer.parseInt(args[1]); WorldConfig config = editWorld.getResource().getConfig(); if (args.length == 2) { - String msg = config.getMsg(id, true); + String msg = config.getMessage(id); if (msg != null) { MessageUtil.sendMessage(player, ChatColor.WHITE + msg); @@ -88,7 +87,7 @@ public class MsgCommand extends BRCommand { if (splitMsg.length > 1) { msg = splitMsg[1]; - String old = config.getMsg(id, false); + String old = config.getMessage(id); if (old == null) { MessageUtil.sendMessage(player, DMessages.CMD_MSG_ADDED.getMessage(String.valueOf(id))); @@ -96,7 +95,7 @@ public class MsgCommand extends BRCommand { MessageUtil.sendMessage(player, DMessages.CMD_MSG_UPDATED.getMessage(String.valueOf(id))); } - config.setMsg(msg, id); + config.setMessage(id, msg); config.save(); } else { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 1e850c9f..0d0fad4f 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -67,7 +67,7 @@ public enum DMessages implements Messages { ERROR_LEAVE_GAME("Error_LeaveGame", "&4You have to leave your current game first!"), ERROR_LEAVE_GROUP("Error_LeaveGroup", "&4You have to leave your group first!"), ERROR_MSG_ID_NOT_EXIST("Error_MsgIdNotExist", "&4Messages with Id &6&v1&4 does not exist!"), - ERROR_MSG_FORMAT("Error_MsgFormat", "&4The Messages has to be between \"!"), + ERROR_MSG_FORMAT("Error_MsgFormat", "&4Please use &6\" &4to mark the beginning and the end of the message!"), ERROR_MSG_NO_INT("Error_MsgNoInt", "&4The argument [id] has to include a number!"), ERROR_NAME_IN_USE("Error_NameInUse", "&4The name &6&v1 &4is already in use."), ERROR_NAME_TO_LONG("Error_NameToLong", "&4The name may not be longer than 15 characters!"), 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 fe94d6eb..8099c718 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -60,9 +60,7 @@ public class WorldConfig extends GameRules { public WorldConfig(File file) { this.file = file; - FileConfiguration configFile = YamlConfiguration.loadConfiguration(file); - load(configFile); } @@ -78,7 +76,7 @@ public class WorldConfig extends GameRules { Set list = configSectionMessages.getKeys(false); for (String messagePath : list) { int messageId = NumberUtil.parseInt(messagePath); - msgs.put(messageId, configSectionMessages.getString(messagePath)); + setMessage(messageId, configSectionMessages.getString(messagePath)); } } @@ -252,11 +250,11 @@ public class WorldConfig extends GameRules { List secureObjectIds = new ArrayList<>(); - for (ItemStack item : secureObjects) { + for (ItemStack item : getSecureObjects()) { secureObjectIds.add(plugin.getCaliburnAPI().getItems().getCustomItemId(item)); } - configFile.set("secureObjects", secureObjectIds); + configFile.set("secureObjects", secureObjects); // Invited Players configFile.set("invitedPlayers", invitedPlayers); 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 b62874f7..d8d2df6a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -79,7 +79,9 @@ public class Game { dGroups.add(dGroup); started = false; DResourceWorld resource = plugin.getDWorlds().getResourceByName(worldName); - world = resource.instantiateAsGameWorld(); + if (resource != null) { + world = resource.instantiateAsGameWorld(); + } dGroup.setGameWorld(world); fetchRules(); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index 556fe5e8..98dc7654 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -16,7 +16,6 @@ */ package io.github.dre2n.dungeonsxl.game; -import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; import java.util.ArrayList; @@ -240,6 +239,9 @@ public class GameRules { * @return the requirements */ public List getRequirements() { + if (requirements == null) { + requirements = new ArrayList<>(); + } return requirements; } @@ -247,6 +249,9 @@ public class GameRules { * @return all maps needed to be finished to play this map */ public List getFinishedAll() { + if (finishedAll == null) { + finishedAll = new ArrayList<>(); + } return finishedAll; } @@ -255,6 +260,13 @@ public class GameRules { * least one has to be finished */ public List getFinished() { + if (finishedAll == null) { + finishedAll = new ArrayList<>(); + } + if (finishedOne == null) { + finishedOne = new ArrayList<>(); + } + List merge = new ArrayList<>(); merge.addAll(finishedAll); merge.addAll(finishedOne); @@ -265,6 +277,9 @@ public class GameRules { * @return the rewards */ public List getRewards() { + if (rewards == null) { + rewards = new ArrayList<>(); + } return rewards; } @@ -273,6 +288,9 @@ public class GameRules { * @return the gameCommandWhitelist */ public List getGameCommandWhitelist() { + if (gameCommandWhitelist == null) { + gameCommandWhitelist = new ArrayList<>(); + } return gameCommandWhitelist; } @@ -280,6 +298,9 @@ public class GameRules { * @return the gamePermissions */ public List getGamePermissions() { + if (gamePermissions == null) { + gamePermissions = new ArrayList<>(); + } return gamePermissions; } @@ -287,28 +308,24 @@ public class GameRules { /** * @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); + public String getMessage(int id) { + if (msgs == null) { + msgs = new HashMap<>(); } - if (returnMainConfig) { - return DungeonsXL.getInstance().getMainConfig().getDefaultWorldConfig().msgs.get(id); - } - - return null; + return msgs.get(id); } /** - * @param msg - * the message to set * @param id * the ID of the message + * @param msg + * the message to set */ - public void setMsg(String msg, int id) { + public void setMessage(int id, String msg) { + if (msgs == null) { + msgs = new HashMap<>(); + } msgs.put(id, msg); } @@ -316,6 +333,9 @@ public class GameRules { * @return the objects to get passed to another player of the group when this player leaves */ public List getSecureObjects() { + if (secureObjects == null) { + secureObjects = new ArrayList<>(); + } return secureObjects; } @@ -450,8 +470,17 @@ public class GameRules { } /* Misc */ - msgs = defaultValues.msgs; - secureObjects = defaultValues.secureObjects; + if (msgs == null) { + msgs = defaultValues.msgs; + } else if (defaultValues.msgs != null) { + msgs.putAll(defaultValues.msgs); + } + + if (secureObjects == null) { + secureObjects = defaultValues.secureObjects; + } else if (defaultValues.secureObjects != null) { + secureObjects.addAll(defaultValues.secureObjects); + } } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index f0e8df3a..2e6e82ae 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -139,7 +139,6 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onInteract(PlayerInteractEvent event) { - plugin.debug.start("PlayerListener#onInteract"); Player player = event.getPlayer(); DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player); Block clickedBlock = event.getClickedBlock(); @@ -303,7 +302,6 @@ public class PlayerListener implements Listener { event.setCancelled(true); } } - plugin.debug.end("PlayerListener#onInteract", true); } @EventHandler(priority = EventPriority.HIGH) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/MessageSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/MessageSign.java index 2e6f774c..7f35e448 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/MessageSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/MessageSign.java @@ -32,7 +32,7 @@ public class MessageSign extends DSign { private DSignType type = DSignTypeDefault.MESSAGE; // Variables - private String msg; + private String msg = "UNKNOWN MESSAGE"; private boolean initialized; private CopyOnWriteArrayList done = new CopyOnWriteArrayList<>(); @@ -52,13 +52,13 @@ public class MessageSign extends DSign { @Override public void onInit() { if (!lines[1].isEmpty()) { - String msg = getGame().getRules().getMsg(NumberUtil.parseInt(lines[1]), true); + String msg = getGame().getRules().getMessage(NumberUtil.parseInt(lines[1])); if (msg != null) { this.msg = msg; - getSign().getBlock().setType(Material.AIR); } } + getSign().getBlock().setType(Material.AIR); initialized = true; } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/SoundMessageSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/SoundMessageSign.java index 06a92083..a1cac8f0 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/SoundMessageSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/SoundMessageSign.java @@ -51,7 +51,7 @@ public class SoundMessageSign extends DSign { @Override public void onInit() { if (!lines[1].isEmpty()) { - String msg = getGame().getRules().getMsg(NumberUtil.parseInt(lines[1]), true); + String msg = getGame().getRules().getMessage(NumberUtil.parseInt(lines[1])); if (msg != null) { this.msg = msg; getSign().getBlock().setType(Material.AIR);