diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 43820a5a..b4168ae0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -350,9 +350,14 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { * 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/GameruleCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java index 01eddae6..ca0e1e07 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 @@ package com.onarandombox.MultiverseCore.commands; 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; @@ -55,7 +56,7 @@ public class GameruleCommand extends MultiverseCommand { 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,52 @@ public class GameruleCommand extends MultiverseCommand { 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); + if (gameRule.getType() == Boolean.class) { + boolean booleanValue; + if (value.equalsIgnoreCase("true")) { + booleanValue = true; + } else if (value.equalsIgnoreCase("false")) { + 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))) { + throw new NumberFormatException(); + } + } catch (NumberFormatException e) { + sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to a positive integer."); + 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."); + 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 + ", "; + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java index 321ac090..62b3e060 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 @@ package com.onarandombox.MultiverseCore.commands; 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 class GamerulesCommand extends MultiverseCommand { 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 class GamerulesCommand extends MultiverseCommand { 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()); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java index 2896a8e7..665f6aa7 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 class ScriptCommand extends MultiverseCommand { @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!"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java index 3f4b26f5..29ac54d4 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 @@ public class VersionCommand extends MultiverseCommand { "[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(); } @@ -110,7 +116,7 @@ public class VersionCommand extends MultiverseCommand { 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());