From 2e3677a592932fa2ac0b5193648bc1a85f786d73 Mon Sep 17 00:00:00 2001 From: Matsv Date: Sat, 2 Apr 2016 11:51:17 +0200 Subject: [PATCH] Make command sender messages cleaner --- .../myles/ViaVersion/api/command/ViaSubCommand.java | 11 +++++++++++ .../myles/ViaVersion/commands/ViaCommandHandler.java | 4 ++++ .../commands/defaultsubs/AutoTeamSubCmd.java | 4 ++-- .../ViaVersion/commands/defaultsubs/DebugSubCmd.java | 2 +- .../commands/defaultsubs/DisplayLeaksSubCmd.java | 8 ++++---- .../commands/defaultsubs/DontBugMeSubCmd.java | 2 +- .../ViaVersion/commands/defaultsubs/ListSubCmd.java | 2 +- .../ViaVersion/commands/defaultsubs/ReloadSubCmd.java | 2 +- 8 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/api/command/ViaSubCommand.java b/src/main/java/us/myles/ViaVersion/api/command/ViaSubCommand.java index d1a68683d..f133ff547 100644 --- a/src/main/java/us/myles/ViaVersion/api/command/ViaSubCommand.java +++ b/src/main/java/us/myles/ViaVersion/api/command/ViaSubCommand.java @@ -63,4 +63,15 @@ public abstract class ViaSubCommand { public String color(String s) { return ViaCommandHandler.color(s); } + + /** + * Send message formatted / colored + * + * @param sender command sender + * @param message string message + * @param args optional objects + */ + public void sendMessage(CommandSender sender, String message, Object... args){ + ViaCommandHandler.sendMessage(sender, message, args); + } } diff --git a/src/main/java/us/myles/ViaVersion/commands/ViaCommandHandler.java b/src/main/java/us/myles/ViaVersion/commands/ViaCommandHandler.java index 4b44868c5..b64cfaf25 100644 --- a/src/main/java/us/myles/ViaVersion/commands/ViaCommandHandler.java +++ b/src/main/java/us/myles/ViaVersion/commands/ViaCommandHandler.java @@ -145,4 +145,8 @@ public class ViaCommandHandler implements ViaVersionCommand, CommandExecutor, Ta } return string; } + + public static void sendMessage(@NonNull CommandSender sender, String message, Object... args) { + sender.sendMessage(color(String.format(message, args))); + } } diff --git a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/AutoTeamSubCmd.java b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/AutoTeamSubCmd.java index 86e673e9b..89d529852 100644 --- a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/AutoTeamSubCmd.java +++ b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/AutoTeamSubCmd.java @@ -23,8 +23,8 @@ public class AutoTeamSubCmd extends ViaSubCommand { boolean newValue = !plugin.isAutoTeam(); plugin.getConfig().set("auto-team", newValue); plugin.saveConfig(); - sender.sendMessage(color("&6We will " + (newValue ? "&aautomatically team players" : "&cno longer auto team players"))); - sender.sendMessage(color("&6All players will need to re-login for the change to take place.")); + sendMessage(sender, "&6We will %s", (newValue ? "&aautomatically team players" : "&cno longer auto team players")); + sendMessage(sender, "&6All players will need to re-login for the change to take place."); return true; } diff --git a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DebugSubCmd.java b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DebugSubCmd.java index ba1b2b272..e5666434b 100644 --- a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DebugSubCmd.java +++ b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DebugSubCmd.java @@ -21,7 +21,7 @@ public class DebugSubCmd extends ViaSubCommand { ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance(); plugin.setDebug(!plugin.isDebug()); - sender.sendMessage(color("&6Debug mode is now " + (plugin.isDebug() ? "&aenabled" : "&cdisabled"))); + sendMessage(sender, "&6Debug mode is now %s" , (plugin.isDebug() ? "&aenabled" : "&cdisabled")); return true; } } diff --git a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DisplayLeaksSubCmd.java b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DisplayLeaksSubCmd.java index f230cb2c2..8701d9f6f 100644 --- a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DisplayLeaksSubCmd.java +++ b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DisplayLeaksSubCmd.java @@ -17,12 +17,12 @@ public class DisplayLeaksSubCmd extends ViaSubCommand { @Override public boolean execute(CommandSender sender, String[] args) { - if (ResourceLeakDetector.getLevel() != ResourceLeakDetector.Level.ADVANCED) { + if (ResourceLeakDetector.getLevel() != ResourceLeakDetector.Level.ADVANCED) ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED); - } else { + else ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED); - } - sender.sendMessage(color("&6Leak detector is now " + (ResourceLeakDetector.getLevel() == ResourceLeakDetector.Level.ADVANCED ? "&aenabled" : "&cdisabled"))); + + sendMessage(sender, "&6Leak detector is now %s", (ResourceLeakDetector.getLevel() == ResourceLeakDetector.Level.ADVANCED ? "&aenabled" : "&cdisabled")); return true; } } diff --git a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DontBugMeSubCmd.java b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DontBugMeSubCmd.java index 0ca7033a4..e115a92ad 100644 --- a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DontBugMeSubCmd.java +++ b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/DontBugMeSubCmd.java @@ -23,7 +23,7 @@ public class DontBugMeSubCmd extends ViaSubCommand { boolean newValue = !plugin.isCheckForUpdates(); plugin.getConfig().set("checkforupdates", newValue); plugin.saveConfig(); - sender.sendMessage(color("&6We will " + (newValue ? "&anotify you about updates." : "&cnot tell you about updates."))); + sendMessage(sender, "&6We will %snotify you about updates.", (newValue ? "&a" : "&cnot ")); return true; } diff --git a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ListSubCmd.java b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ListSubCmd.java index 35ac81994..cd7fd2b89 100644 --- a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ListSubCmd.java +++ b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ListSubCmd.java @@ -39,7 +39,7 @@ public class ListSubCmd extends ViaSubCommand { Map> sorted = new TreeMap<>(playerVersions); for (Map.Entry> entry : sorted.entrySet()) - sender.sendMessage(String.format(color("&8[&6%s&8]: &b%s"), ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue())); + sendMessage(sender, "&8[&6%s&8]: &b%s", ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue()); sorted.clear(); return true; diff --git a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ReloadSubCmd.java b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ReloadSubCmd.java index d335f8566..b2fb411a4 100644 --- a/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ReloadSubCmd.java +++ b/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ReloadSubCmd.java @@ -21,7 +21,7 @@ public class ReloadSubCmd extends ViaSubCommand { ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance(); plugin.generateConfig(); - sender.sendMessage(color("&6Configuration successfully reloaded! Some features may need a restart.")); + sendMessage(sender, "&6Configuration successfully reloaded! Some features may need a restart."); return true; } }