diff --git a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/GroovierScriptLoader.groovy b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/GroovierScriptLoader.groovy index 565723c..d7f7112 100644 --- a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/GroovierScriptLoader.groovy +++ b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/GroovierScriptLoader.groovy @@ -69,7 +69,7 @@ class GroovierScriptLoader { CompletableFuture reloadAllScripts() { if (loading.get()) { - return CompletableFuture.failedFuture(new IllegalStateException("Scripts are still loading.")) + return CompletableFuture.failedFuture(new ScriptLoadingException()) } this.unloadAllScripts() return this.loadAllScripts() diff --git a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/ScriptLoadingException.java b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/ScriptLoadingException.java new file mode 100644 index 0000000..9c26eed --- /dev/null +++ b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/ScriptLoadingException.java @@ -0,0 +1,7 @@ +package com.ericlam.mc.groovier; + +public class ScriptLoadingException extends RuntimeException { + public ScriptLoadingException() { + super(); + } +} diff --git a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/bungee/BungeeCommandInvoker.groovy b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/bungee/BungeeCommandInvoker.groovy index 71b3d69..4797f1e 100644 --- a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/bungee/BungeeCommandInvoker.groovy +++ b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/bungee/BungeeCommandInvoker.groovy @@ -245,7 +245,7 @@ class BungeeCommandInvoker { private static BaseComponent[] text(String str) { - return TextComponent.fromLegacyText(str) + return TextComponent.fromLegacy(str) } } diff --git a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/bungee/GroovierPlugin.groovy b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/bungee/GroovierPlugin.groovy index 1b3f50d..f7f1f18 100644 --- a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/bungee/GroovierPlugin.groovy +++ b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/bungee/GroovierPlugin.groovy @@ -1,6 +1,7 @@ package com.ericlam.mc.groovier.bungee import com.ericlam.mc.groovier.GroovierCore +import com.ericlam.mc.groovier.ScriptLoadingException import com.ericlam.mc.groovier.ScriptPlugin import com.ericlam.mc.groovier.scriptloaders.CommandRegister import com.ericlam.mc.groovier.scriptloaders.EventRegister @@ -34,29 +35,33 @@ class GroovierPlugin extends Plugin implements ScriptPlugin { @Override void execute(CommandSender sender, String[] args) { if (hasPermission(sender)) { - sender.sendMessage(TextComponent.fromLegacyText("${ChatColor.RED}no permission.")) + sender.sendMessage(TextComponent.fromLegacy("${ChatColor.RED}no permission.")) } if (args.length == 0) { - sender.sendMessage(TextComponent.fromLegacyText("Usage: /groovier reload | version")) + sender.sendMessage(TextComponent.fromLegacy("Usage: /groovier reload | version")) return } if (args[0].equalsIgnoreCase("reload")) { core.reloadAllScripts().whenComplete((v, ex) -> { if (ex != null) { - sender.sendMessage(TextComponent.fromLegacyText("${ChatColor.RED}Failed to reload scripts: " + ex.getMessage())) - ex.printStackTrace() + if (ex instanceof ScriptLoadingException) { + sender.sendMessage(TextComponent.fromLegacy("${ChatColor.GOLD}Script is still loading, please wait until complete.")) + } else { + sender.sendMessage(TextComponent.fromLegacy("${ChatColor.RED}Failed to reload scripts: " + ex.getMessage())) + ex.printStackTrace() + } } else { - sender.sendMessage(TextComponent.fromLegacyText("${ChatColor.GREEN}Successfully reloaded scripts")) + sender.sendMessage(TextComponent.fromLegacy("${ChatColor.GREEN}Successfully reloaded scripts")) } }) return } if (args[0].equalsIgnoreCase("version")) { - sender.sendMessage(TextComponent.fromLegacyText("Groovier v${getDescription().getVersion()} by ${getDescription().getAuthor()}")) + sender.sendMessage(TextComponent.fromLegacy("Groovier v${getDescription().getVersion()} by ${getDescription().getAuthor()}")) return } - sender.sendMessage(TextComponent.fromLegacyText("Usage: /groovier reload | version")) + sender.sendMessage(TextComponent.fromLegacy("Usage: /groovier reload | version")) } } diff --git a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/spigot/GroovierPlugin.groovy b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/spigot/GroovierPlugin.groovy index 19984d5..b3ce56f 100644 --- a/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/spigot/GroovierPlugin.groovy +++ b/groovier-plugin/src/main/groovy/com/ericlam/mc/groovier/spigot/GroovierPlugin.groovy @@ -1,6 +1,7 @@ package com.ericlam.mc.groovier.spigot import com.ericlam.mc.groovier.GroovierCore +import com.ericlam.mc.groovier.ScriptLoadingException import com.ericlam.mc.groovier.ScriptPlugin import com.ericlam.mc.groovier.scriptloaders.CommandRegister import com.ericlam.mc.groovier.scriptloaders.EventRegister @@ -77,8 +78,12 @@ class GroovierPlugin extends JavaPlugin implements ScriptPlugin { case "reload": core.reloadAllScripts().whenComplete{v, ex -> if (ex != null){ - ex.printStackTrace() - sender.sendMessage("${ChatColor.RED}Failed to reload scripts: " + ex.getMessage()) + if (ex instanceof ScriptLoadingException) { + sender.sendMessage("${ChatColor.GOLD}Script is still loading, please wait until complete.") + } else { + sender.sendMessage("${ChatColor.RED}Failed to reload scripts: " + ex.getMessage()) + ex.printStackTrace() + } } else { sender.sendMessage("${ChatColor.GREEN}Successfully reloaded scripts") } diff --git a/groovier-plugin/src/main/resources_bungee/commands/info.groovy b/groovier-plugin/src/main/resources_bungee/commands/info.groovy index ed3e58e..4b19e4e 100644 --- a/groovier-plugin/src/main/resources_bungee/commands/info.groovy +++ b/groovier-plugin/src/main/resources_bungee/commands/info.groovy @@ -14,12 +14,12 @@ void info(CommandSender sender, @CommandArg(value = 'player', optional = true) P if (player == null && sender instanceof ProxiedPlayer) { player = (ProxiedPlayer)sender } else if (player == null) { - sender.sendMessage(TextComponent.fromLegacyText("Please specify a player")) + sender.sendMessage(TextComponent.fromLegacy("Please specify a player")) return } - sender.sendMessage(TextComponent.fromLegacyText("Player: ${player.name}")) - sender.sendMessage(TextComponent.fromLegacyText("UUID: ${player.uniqueId}")) - sender.sendMessage(TextComponent.fromLegacyText("Ping: ${player.ping}")) + sender.sendMessage(TextComponent.fromLegacy("Player: ${player.name}")) + sender.sendMessage(TextComponent.fromLegacy("UUID: ${player.uniqueId}")) + sender.sendMessage(TextComponent.fromLegacy("Ping: ${player.ping}")) } diff --git a/groovier-plugin/src/main/resources_bungee/commands/love.groovy b/groovier-plugin/src/main/resources_bungee/commands/love.groovy index 85d080d..c959df4 100644 --- a/groovier-plugin/src/main/resources_bungee/commands/love.groovy +++ b/groovier-plugin/src/main/resources_bungee/commands/love.groovy @@ -10,7 +10,7 @@ import net.md_5.bungee.api.chat.TextComponent @CommandScript(description = 'love what?') void love(CommandSender sender, @CommandArg('target') String target) { - sender.sendMessage(TextComponent.fromLegacyText("oh, you love $target")) + sender.sendMessage(TextComponent.fromLegacy("oh, you love $target")) } List tabComplete(CommandSender sender, String[] args) { diff --git a/groovier-plugin/src/main/resources_bungee/commands/math/add.groovy b/groovier-plugin/src/main/resources_bungee/commands/math/add.groovy index ffc1f05..a95fa06 100644 --- a/groovier-plugin/src/main/resources_bungee/commands/math/add.groovy +++ b/groovier-plugin/src/main/resources_bungee/commands/math/add.groovy @@ -16,6 +16,6 @@ import javax.inject.Inject @CommandScript(description = 'add two numbers') void add(CommandSender sender, @CommandArg('one') int a, @CommandArg(value = 'two', optional = true) int b = 1) { - sender.sendMessage(TextComponent.fromLegacyText("$a + $b = ${mathService.add(a, b)}")) + sender.sendMessage(TextComponent.fromLegacy("$a + $b = ${mathService.add(a, b)}")) } diff --git a/groovier-plugin/src/main/resources_bungee/commands/math/minus.groovy b/groovier-plugin/src/main/resources_bungee/commands/math/minus.groovy index 27d0146..3172d94 100644 --- a/groovier-plugin/src/main/resources_bungee/commands/math/minus.groovy +++ b/groovier-plugin/src/main/resources_bungee/commands/math/minus.groovy @@ -19,5 +19,5 @@ import javax.inject.Inject @CommandScript(description = 'minus two numbers') void minus(CommandSender sender, @CommandArg('one') int a, @CommandArg('two') int b) { - sender.sendMessage(TextComponent.fromLegacyText("$a - $b = ${mathService.minus(a, b)}")) + sender.sendMessage(TextComponent.fromLegacy("$a - $b = ${mathService.minus(a, b)}")) } \ No newline at end of file diff --git a/groovier-plugin/src/main/resources_bungee/commands/say.groovy b/groovier-plugin/src/main/resources_bungee/commands/say.groovy index 801f65c..f4851bb 100644 --- a/groovier-plugin/src/main/resources_bungee/commands/say.groovy +++ b/groovier-plugin/src/main/resources_bungee/commands/say.groovy @@ -10,5 +10,5 @@ import net.md_5.bungee.api.chat.TextComponent @CommandScript(description = 'say something') void say(CommandSender sender, @CommandArg('message') String[] message) { - sender.sendMessage(TextComponent.fromLegacyText("${sender.name} says: ${String.join(' ', message)}")) + sender.sendMessage(TextComponent.fromLegacy("${sender.name} says: ${String.join(' ', message)}")) } \ No newline at end of file diff --git a/groovier-plugin/src/main/resources_bungee/listeners/myListener.groovy b/groovier-plugin/src/main/resources_bungee/listeners/myListener.groovy index a1e666c..2580420 100644 --- a/groovier-plugin/src/main/resources_bungee/listeners/myListener.groovy +++ b/groovier-plugin/src/main/resources_bungee/listeners/myListener.groovy @@ -12,10 +12,10 @@ void onPlayerChat(ChatEvent e){ var player = e.sender as ProxiedPlayer if (e.message == 'ping'){ e.cancelled = true - player.sendMessage(TextComponent.fromLegacyText("pong!")) + player.sendMessage(TextComponent.fromLegacy("pong!")) } else if (e.message == 'pong') { e.cancelled = true - player.sendMessage(TextComponent.fromLegacyText("ping!")) + player.sendMessage(TextComponent.fromLegacy("ping!")) } }