Skip to content

Commit

Permalink
replaced legacy method from bungeecord.chat; better handle for script…
Browse files Browse the repository at this point in the history
… still loading
  • Loading branch information
eric2788 committed Aug 15, 2024
1 parent 58697a1 commit d0d6300
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GroovierScriptLoader {

CompletableFuture<Void> reloadAllScripts() {
if (loading.get()) {
return CompletableFuture.failedFuture(new IllegalStateException("Scripts are still loading."))
return CompletableFuture.failedFuture(new ScriptLoadingException())
}
this.unloadAllScripts()
return this.loadAllScripts()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ericlam.mc.groovier;

public class ScriptLoadingException extends RuntimeException {
public ScriptLoadingException() {
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class BungeeCommandInvoker {


private static BaseComponent[] text(String str) {
return TextComponent.fromLegacyText(str)
return TextComponent.fromLegacy(str)
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<String> tabComplete(CommandSender sender, String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"))
}

Original file line number Diff line number Diff line change
Expand Up @@ -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)}"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!"))
}
}

0 comments on commit d0d6300

Please sign in to comment.