Fixed errors with the section management command

This commit is contained in:
Jaime Martinez Rincon 2017-02-02 19:54:31 +01:00
parent 330ed1c96a
commit 66f31500d8
4 changed files with 43 additions and 34 deletions

View File

@ -6,7 +6,7 @@
<groupId>me.jaimemartz</groupId>
<artifactId>lobbybalancer</artifactId>
<version>2.0.9.1</version>
<version>2.0.9.2</version>
<name>LobbyBalancer</name>
<properties>

View File

@ -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";
}
}

View File

@ -179,7 +179,7 @@ public class ServerSection {
return provider;
}
public boolean isProviderInherited() {
public boolean hasInheritedProvider() {
return inherited;
}

View File

@ -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'