From 66f31500d85b1bff2116208d7459cb69159206cb Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Thu, 2 Feb 2017 19:54:31 +0100 Subject: [PATCH] Fixed errors with the section management command --- pom.xml | 2 +- .../lobbybalancer/commands/ManageCommand.java | 71 +++++++++++-------- .../lobbybalancer/section/ServerSection.java | 2 +- src/main/resources/config.yml | 2 +- 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index b5e9ea2..a3493f4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.jaimemartz lobbybalancer - 2.0.9.1 + 2.0.9.2 LobbyBalancer diff --git a/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java b/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java index 2a03a61..5049bbc 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java @@ -73,7 +73,7 @@ public class ManageCommand extends Command { new Replacement("{name}", ChatColor.RED + section.getName())); msgr.send("&7Principal: &b{status}", - new Replacement("{status}", format(section.isPrincipal()))); + new Replacement("{status}", section.isPrincipal() ? ChatColor.GREEN + "yes" : ChatColor.RED + "no")); if (section.hasParent()) { TextComponent message = new TextComponent("Parent: "); @@ -92,34 +92,40 @@ public class ManageCommand extends Command { msgr.send("&7Provider: &b{name} &7({relation}&7)", new Replacement("{name}", section.getProvider().name()), - new Replacement("{relation}", section.isProviderInherited() ? "Inherited" : "Specified")); + new Replacement("{relation}", section.hasInheritedProvider() ? "Inherited" : "Specified")); - msgr.send("&7Dummy: &b{status}", new Replacement("{status}", format(section.isDummy()))); + msgr.send("&7Dummy: &b{status}", new Replacement("{status}", section.isDummy() ? ChatColor.GREEN + "yes" : ChatColor.RED + "no")); msgr.send("&7Section Server: &b{name}", new Replacement("{name}", section.hasServer() ? section.getServer().getName() : "None")); if (section.hasCommand()) { msgr.send("&7Section Command: &b{name}&7, Permission: &b{permission}&7, Aliases: &b{aliases}", new Replacement("{name}", section.getCommand().getName()), - new Replacement("{permission}", section.getCommand().getPermission().equals("") ? "none" : section.getCommand().getPermission()), - new Replacement("{aliases}", StringCombiner.combine(section.getCommand().getAliases(), ", "))); + new Replacement("{permission}", section.getCommand().getPermission().equals("") ? "None" : section.getCommand().getPermission()), + new Replacement("{aliases}", section.getCommand().getAliases().length == 0 ? "None" : StringCombiner.combine(section.getCommand().getAliases(), ", "))); } else { msgr.send("&7Section Command: &bNone"); } msgr.send("&7Valid: &b{status}", - new Replacement("{status}", format(section.isValid()))); + new Replacement("{status}", section.isValid() ? ChatColor.GREEN + "yes" : ChatColor.RED + "no")); + + + if (!section.getServers().isEmpty()) { + msgr.send("&7Section Servers: "); + section.getServers().forEach(server -> { + ServerStatus status = plugin.getPingManager().getStatus(server); + msgr.send("&7Server &b{name} &c({connected}/{maximum}) &7({status}&7)", + new Replacement("{name}", server.getName()), + new Replacement("{connected}", String.valueOf(status.getOnlinePlayers())), + new Replacement("{maximum}", String.valueOf(status.getMaximumPlayers())), + new Replacement("{status}", status.isAccessible() ? ChatColor.GREEN + "Accessible" : ChatColor.RED + "Inaccessible") + ); + }); + } else { + msgr.send("&7Section Servers: &bNone"); + } - msgr.send("&7Section Servers: "); - section.getServers().forEach(server -> { - ServerStatus status = plugin.getPingManager().getStatus(server); - msgr.send("&7Server &b{name} &c({connected}/{maximum}) &7({status}&7)", - new Replacement("{name}", server.getName()), - new Replacement("{connected}", String.valueOf(status.getOnlinePlayers())), - new Replacement("{maximum}", String.valueOf(status.getMaximumPlayers())), - new Replacement("{status}", status.isAccessible() ? ChatColor.GREEN + "Accessible" : ChatColor.RED + "Inaccessible") - ); - }); msgr.send("&7&m-----------------------------------------------------"); } else { msgr.send(ConfigEntries.UNKNOWN_SECTION_MESSAGE.get()); @@ -136,22 +142,29 @@ public class ManageCommand extends Command { TextComponent message = new TextComponent(String.format("There are %s configured sections:\n", keys.size())); message.setColor(ChatColor.GRAY); - while (iterator.hasNext()) { - String name = iterator.next(); - TextComponent extra = new TextComponent(name); - extra.setColor(ChatColor.GREEN); - extra.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/section info %s", name))); - extra.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click me for info").color(ChatColor.RED).create())); + if (iterator.hasNext()) { + while (iterator.hasNext()) { + String name = iterator.next(); + TextComponent extra = new TextComponent(name); + extra.setColor(ChatColor.GREEN); + extra.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/section info %s", name))); + extra.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click me for info").color(ChatColor.RED).create())); - if (iterator.hasNext()) { - TextComponent sep = new TextComponent(", "); - sep.setColor(ChatColor.GRAY); - extra.addExtra(sep); + if (iterator.hasNext()) { + TextComponent sep = new TextComponent(", "); + sep.setColor(ChatColor.GRAY); + extra.addExtra(sep); + } + + message.addExtra(extra); } - + } else { + TextComponent extra = new TextComponent("There are no sections to list"); + extra.setColor(ChatColor.RED); message.addExtra(extra); } + sender.sendMessage(message); break; } @@ -179,8 +192,4 @@ public class ManageCommand extends Command { "&7&m-----------------------------------------------------" ); } - - private String format(boolean reference) { - return reference ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"; - } } diff --git a/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java b/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java index 7ea347a..f39a4ba 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java @@ -179,7 +179,7 @@ public class ServerSection { return provider; } - public boolean isProviderInherited() { + public boolean hasInheritedProvider() { return inherited; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0af6500..3f998fa 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -128,7 +128,7 @@ settings: # Comment a message to disable it messages: connecting: '&aConnecting to {server}' - failure: '&cCould not find a server to connect to' + failure: '&cCould not find a server to get connected' unavailable: '&cThis command cannot be executed on this server' unknown: '&cCould not find a section with that name'