From 24314e9c7f2acc59f7927457b4c687b5bd5771c7 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Fri, 5 Jun 2020 18:44:01 -0400 Subject: [PATCH 1/8] update gamerule command --- .../commands/GameruleCommand.java | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java index 01eddae6b..340ef96c5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java @@ -10,6 +10,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.GameRule; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -24,7 +25,7 @@ public class GameruleCommand extends MultiverseCommand { public GameruleCommand(MultiverseCore plugin) { super(plugin); - this.setName("Set a Minecraft Game Rule for a World."); + this.setName("Set a Minecraft gamerule for a World."); this.setCommandUsage("/mv gamerule " + ChatColor.GREEN + "{RULE} {VALUE}" + ChatColor.GOLD + " [WORLD]"); this.setArgRange(2, 3); this.addKey("mv gamerule"); @@ -55,7 +56,7 @@ public void runCommand(CommandSender sender, List args) { return; } - final String gameRule = args.get(0); + final GameRule gameRule = GameRule.getByName(args.get(0)); final String value = args.get(1); final World world; if (args.size() == 2) { @@ -64,17 +65,38 @@ public void runCommand(CommandSender sender, List args) { world = Bukkit.getWorld(args.get(2)); if (world == null) { sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(2) - + ChatColor.WHITE + " does not exist."); + + ChatColor.WHITE + " does not exist."); return; } } - if (world.setGameRuleValue(gameRule, value)) { - sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule - + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value); + if (gameRule == null) { + sender.sendMessage(ChatColor.RED + "Failure! " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + + " is not a valid gamerule."); } else { - sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule - + ChatColor.WHITE + " cannot be set to " + ChatColor.RED + value); + boolean success = false; + + try { + if (gameRule.getType() == Boolean.class) { + if (value.equalsIgnoreCase("true")) success = world.setGameRule(gameRule, true); + else if (value.equalsIgnoreCase("false")) success = world.setGameRule(gameRule, false); + } else if (gameRule.getType() == Integer.class) { + success = world.setGameRule(gameRule, Integer.parseInt(value)); + } else { + sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() + + ChatColor.WHITE + " isn't supported yet, please let us know about it."); + return; + } + } catch (NumberFormatException ignored) {} + + if (success) { + sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() + + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value + ChatColor.WHITE + "."); + } else { + sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() + + ChatColor.WHITE + " cannot be set to " + ChatColor.RED + value + ChatColor.WHITE + ", it can only be set to type " + + gameRule.getType().getSimpleName() + "."); + } } } -} +} \ No newline at end of file From d9454f661e1936b6941c57e133353c4f51f15455 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Sat, 6 Jun 2020 20:35:27 -0400 Subject: [PATCH 2/8] fix NPE in gamerules command and remove deprecated method --- .../MultiverseCore/commands/GamerulesCommand.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java index 321ac0907..62b3e0607 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java @@ -10,6 +10,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.GameRule; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -60,6 +61,11 @@ public void runCommand(CommandSender sender, List args) { world = p.getWorld(); } else { world = Bukkit.getWorld(args.get(0)); + if (world == null) { + sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(0) + + ChatColor.WHITE + " does not exist."); + return; + } } final StringBuilder gameRules = new StringBuilder(); @@ -68,7 +74,7 @@ public void runCommand(CommandSender sender, List args) { gameRules.append(ChatColor.WHITE).append(", "); } gameRules.append(ChatColor.AQUA).append(gameRule).append(ChatColor.WHITE).append(": "); - gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(gameRule)); + gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(GameRule.getByName(gameRule))); } sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ==="); sender.sendMessage(gameRules.toString()); From 8e277dda4a1e8d2e33cd8d5757ea304a15bdaa99 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Mon, 8 Jun 2020 07:42:26 -0400 Subject: [PATCH 3/8] catch buscript initialization errors --- .../onarandombox/MultiverseCore/MultiverseCore.java | 11 ++++++++--- .../MultiverseCore/commands/ScriptCommand.java | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 43820a5af..b4168ae02 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -350,9 +350,14 @@ private void setupMetrics() { * Initializes the buscript javascript library. */ private void initializeBuscript() { - buscript = new Buscript(this); - // Add global variable "multiverse" to javascript environment - buscript.setScriptVariable("multiverse", this); + try { + buscript = new Buscript(this); + // Add global variable "multiverse" to javascript environment + buscript.setScriptVariable("multiverse", this); + } catch (NullPointerException e) { + buscript = null; + Logging.warning("Buscript failed to load! The script command will be disabled!"); + } } private void initializeDestinationFactory() { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java index 2896a8e70..665f6aa71 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java @@ -35,6 +35,10 @@ public ScriptCommand(MultiverseCore plugin) { @Override public void runCommand(CommandSender sender, List args) { + if (plugin.getScriptAPI() == null) { + sender.sendMessage("Buscript failed to load while the server was starting. Scripts cannot be run."); + return; + } File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0)); if (!file.exists()) { sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!"); From 152530cddd262ebe98f34cf764787fe9ffcfb7ca Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Sat, 13 Jun 2020 12:30:16 -0400 Subject: [PATCH 4/8] update gamerule command to be more descriptive --- .../commands/GameruleCommand.java | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java index 340ef96c5..865b49317 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java @@ -74,29 +74,43 @@ public void runCommand(CommandSender sender, List args) { sender.sendMessage(ChatColor.RED + "Failure! " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " is not a valid gamerule."); } else { - boolean success = false; - - try { - if (gameRule.getType() == Boolean.class) { - if (value.equalsIgnoreCase("true")) success = world.setGameRule(gameRule, true); - else if (value.equalsIgnoreCase("false")) success = world.setGameRule(gameRule, false); - } else if (gameRule.getType() == Integer.class) { - success = world.setGameRule(gameRule, Integer.parseInt(value)); + if (gameRule.getType() == Boolean.class) { + if (value.equalsIgnoreCase("true")) { + if (!world.setGameRule(gameRule, true)) { + sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong."); + return; + } + } else if (value.equalsIgnoreCase("false")) { + if (!world.setGameRule(gameRule, false)) { + sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong."); + return; + } } else { - sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() - + ChatColor.WHITE + " isn't supported yet, please let us know about it."); + sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to true or false."); + return; + } + } else if (gameRule.getType() == Integer.class) { + try { + if (!world.setGameRule(gameRule, Integer.parseInt(value))) { + throw new NumberFormatException(); + } + } catch (NumberFormatException e) { + sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to a positive integer."); return; } - } catch (NumberFormatException ignored) {} - - if (success) { - sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() - + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value + ChatColor.WHITE + "."); } else { sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() - + ChatColor.WHITE + " cannot be set to " + ChatColor.RED + value + ChatColor.WHITE + ", it can only be set to type " - + gameRule.getType().getSimpleName() + "."); - } + + ChatColor.WHITE + " isn't supported yet, please let us know about it."); + return; + } + + sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() + + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value + ChatColor.WHITE + "."); } } + + private String getErrorMessage(String gameRule, String value) { + return ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule + + ChatColor.WHITE + " could not be set to " + ChatColor.RED + value + ChatColor.WHITE + ", "; + } } \ No newline at end of file From 131cd4dae95e28f8f88f6b8ab80bfa61d49a3cb0 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Mon, 20 Jul 2020 20:36:31 -0400 Subject: [PATCH 5/8] undo GameruleCommand style changes --- .../onarandombox/MultiverseCore/commands/GameruleCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java index 865b49317..b1e01cdbb 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java @@ -25,7 +25,7 @@ public class GameruleCommand extends MultiverseCommand { public GameruleCommand(MultiverseCore plugin) { super(plugin); - this.setName("Set a Minecraft gamerule for a World."); + this.setName("Set a Minecraft Game Rule for a World."); this.setCommandUsage("/mv gamerule " + ChatColor.GREEN + "{RULE} {VALUE}" + ChatColor.GOLD + " [WORLD]"); this.setArgRange(2, 3); this.addKey("mv gamerule"); @@ -113,4 +113,4 @@ private String getErrorMessage(String gameRule, String value) { return ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule + ChatColor.WHITE + " could not be set to " + ChatColor.RED + value + ChatColor.WHITE + ", "; } -} \ No newline at end of file +} From 665be9e93519b5cc17e34ff72b80e7dc586a935a Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Tue, 28 Jul 2020 22:21:02 -0400 Subject: [PATCH 6/8] update legacy version reporting to include all config options --- .../commands/VersionCommand.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java index 3f4b26f52..6235723f1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java @@ -61,16 +61,22 @@ private String getLegacyString() { "[Multiverse-Core] Economy being used: " + plugin.getEconomist().getEconomyName() + System.lineSeparator() + "[Multiverse-Core] Permissions Plugin: " + this.plugin.getMVPerms().getType() + System.lineSeparator() + "[Multiverse-Core] Dumping Config Values: (version " + this.plugin.getMVConfig().getVersion() + ")" + System.lineSeparator() + - "[Multiverse-Core] messagecooldown: " + plugin.getMessaging().getCooldown() + System.lineSeparator() + - "[Multiverse-Core] teleportcooldown: " + plugin.getMVConfig().getTeleportCooldown() + System.lineSeparator() + - "[Multiverse-Core] worldnameprefix: " + plugin.getMVConfig().getPrefixChat() + System.lineSeparator() + - "[Multiverse-Core] worldnameprefixFormat: " + plugin.getMVConfig().getPrefixChatFormat() + System.lineSeparator() + "[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + System.lineSeparator() + - "[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + System.lineSeparator() + + "[Multiverse-Core] prefixchat: " + plugin.getMVConfig().getPrefixChat() + System.lineSeparator() + + "[Multiverse-Core] prefixchatformat: " + plugin.getMVConfig().getPrefixChatFormat() + System.lineSeparator() + + "[Multiverse-Core] useasyncchat: " + plugin.getMVConfig().getUseAsyncChat() + System.lineSeparator() + "[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + System.lineSeparator() + "[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + System.lineSeparator() + + "[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + System.lineSeparator() + + "[Multiverse-Core] globaldebug: " + plugin.getMVConfig().getGlobalDebug() + System.lineSeparator() + + "[Multiverse-Core] silentstart: " + plugin.getMVConfig().getSilentStart() + System.lineSeparator() + + "[Multiverse-Core] messagecooldown: " + plugin.getMessaging().getCooldown() + System.lineSeparator() + + "[Multiverse-Core] version: " + plugin.getMVConfig().getVersion() + System.lineSeparator() + "[Multiverse-Core] firstspawnworld: " + plugin.getMVConfig().getFirstSpawnWorld() + System.lineSeparator() + - "[Multiverse-Core] debug: " + plugin.getMVConfig().getGlobalDebug() + System.lineSeparator() + + "[Multiverse-Core] teleportcooldown: " + plugin.getMVConfig().getTeleportCooldown() + System.lineSeparator() + + "[Multiverse-Core] defaultportalsearch: " + plugin.getMVConfig().isUsingDefaultPortalSearch() + System.lineSeparator() + + "[Multiverse-Core] portalsearchradius: " + plugin.getMVConfig().getPortalSearchRadius() + System.lineSeparator() + + "[Multiverse-Core] autopurge: " + plugin.getMVConfig().isAutoPurgeEnabled() + System.lineSeparator() + "[Multiverse-Core] Special Code: FRN002" + System.lineSeparator(); } From 546b85b1a8859c88d654323e04edcb543b357111 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Tue, 28 Jul 2020 22:29:15 -0400 Subject: [PATCH 7/8] use LF line ending for files being pasted to the web --- .../onarandombox/MultiverseCore/commands/VersionCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java index 6235723f1..29ac54d43 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java @@ -116,7 +116,7 @@ private String readFile(final String filename) { String line; result = new StringBuilder(); while ((line = bufferedReader.readLine()) != null) { - result.append(line).append(System.lineSeparator()); + result.append(line).append("\n"); } } catch (FileNotFoundException e) { Logging.severe("Unable to find %s. Here's the traceback: %s", filename, e.getMessage()); From c15ca90bf573abaa6dae0e5f576393790a3f3177 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Sat, 19 Sep 2020 14:37:00 -0400 Subject: [PATCH 8/8] avoid duplicate code --- .../MultiverseCore/commands/GameruleCommand.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java index b1e01cdbb..ca0e1e076 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java @@ -75,20 +75,20 @@ public void runCommand(CommandSender sender, List args) { + " is not a valid gamerule."); } else { if (gameRule.getType() == Boolean.class) { + boolean booleanValue; if (value.equalsIgnoreCase("true")) { - if (!world.setGameRule(gameRule, true)) { - sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong."); - return; - } + booleanValue = true; } else if (value.equalsIgnoreCase("false")) { - if (!world.setGameRule(gameRule, false)) { - sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong."); - return; - } + booleanValue = false; } else { sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to true or false."); return; } + + if (!world.setGameRule(gameRule, booleanValue)) { + sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong."); + return; + } } else if (gameRule.getType() == Integer.class) { try { if (!world.setGameRule(gameRule, Integer.parseInt(value))) {