From d01064256d3f6dcd6798d006f2ebb57993b82038 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Wed, 1 Feb 2017 19:18:29 +0100 Subject: [PATCH] Finished the manage command, now comes the testing --- .../lobbybalancer/LobbyBalancer.java | 3 +- .../lobbybalancer/commands/MainCommand.java | 4 +- .../lobbybalancer/commands/ManageCommand.java | 106 +++++++++++++++--- .../lobbybalancer/utils/WrappedAdapter.java | 1 + 4 files changed, 94 insertions(+), 20 deletions(-) diff --git a/src/main/java/me/jaimemartz/lobbybalancer/LobbyBalancer.java b/src/main/java/me/jaimemartz/lobbybalancer/LobbyBalancer.java index 6b73a66..168f909 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/LobbyBalancer.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/LobbyBalancer.java @@ -123,8 +123,9 @@ public class LobbyBalancer extends Plugin { getProxy().getPluginManager().registerListener(this, kickListener); } - //Silence jackson stuff + //Silent jackson stuff Logger.getLogger(Java7Support.class.getName()).setLevel(Level.SEVERE); + if (ConfigEntries.GEOLOCATION_ENABLED.get()) { getLogger().warning("The geolocation feature has not been tested in depth"); try { diff --git a/src/main/java/me/jaimemartz/lobbybalancer/commands/MainCommand.java b/src/main/java/me/jaimemartz/lobbybalancer/commands/MainCommand.java index 7ee2f85..d7b8936 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/commands/MainCommand.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/commands/MainCommand.java @@ -20,13 +20,13 @@ public class MainCommand extends Command { Messager msgr = new Messager(sender); if (args.length == 0) { msgr.send( - "&e=====================================================", + "&7&m-----------------------------------------------------", "&7Information: LobbyBalancer version " + plugin.getDescription().getVersion(), "&7Available commands:", "&3/balancer &7- &cShows this message", "&3/balancer paste &7- &cCreates a paste with the important files", "&3/balancer reload &7- &cReloads the plugin completely", - "&e=====================================================" + "&7&m-----------------------------------------------------" ); } else { switch (args[0]) { diff --git a/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java b/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java index 95eb6ab..92e493c 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java @@ -1,17 +1,25 @@ package me.jaimemartz.lobbybalancer.commands; import me.jaimemartz.faucet.Messager; +import me.jaimemartz.faucet.Replacement; +import me.jaimemartz.faucet.StringCombiner; import me.jaimemartz.lobbybalancer.LobbyBalancer; import me.jaimemartz.lobbybalancer.configuration.ConfigEntries; import me.jaimemartz.lobbybalancer.connection.ConnectionIntent; +import me.jaimemartz.lobbybalancer.ping.ServerStatus; import me.jaimemartz.lobbybalancer.section.ServerSection; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; +import java.util.Iterator; +import java.util.Set; + public class ManageCommand extends Command { private final LobbyBalancer plugin; @@ -37,13 +45,13 @@ public class ManageCommand extends Command { if (player != null) { ConnectionIntent.simple(plugin, player, section); } else { - msgr.send(ChatColor.RED + "There is no player with that name connected to this proxy"); + msgr.send("&cThere is no player with that name connected to this proxy"); } } else { if (sender instanceof ProxiedPlayer) { ConnectionIntent.simple(plugin, (ProxiedPlayer) sender, section); } else { - msgr.send(ChatColor.RED + "This command can only be executed by a player"); + msgr.send("&cThis command can only be executed by a player"); } } } else { @@ -60,7 +68,60 @@ public class ManageCommand extends Command { String input = args[1]; ServerSection section = plugin.getSectionManager().getByName(input); if (section != null) { - //Information about the section %s + msgr.send("&7&m-----------------------------------------------------"); + + msgr.send("&7Information of section &b{name}", + new Replacement("{name}", ChatColor.RED + section.getName())); + + msgr.send("&7Principal: &b{status}", + new Replacement("{status}", format(section.isPrincipal()))); + + if (section.hasParent()) { + TextComponent message = new TextComponent("Parent: "); + message.setColor(ChatColor.GRAY); + + TextComponent extra = new TextComponent(section.getParent().getName()); + extra.setColor(ChatColor.AQUA); + extra.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/section info %s", section.getParent().getName()))); + extra.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click me for info").color(ChatColor.RED).create())); + + message.addExtra(extra); + sender.sendMessage(message); + } else { + msgr.send("&7Parent: &bNone"); + } + + msgr.send("&7Provider: &b{name} &7({relation}&7)", + new Replacement("{name}", section.getProvider().name()), + new Replacement("{relation}", section.isProviderInherited() ? "Inherited" : "Specified")); + + msgr.send("&7Dummy: &b{status}", new Replacement("{status}", format(section.isDummy()))); + + 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(), ", "))); + } else { + msgr.send("&7Section Command: &bNone"); + } + + msgr.send("&7Valid: &b{status}", + new Replacement("{status}", format(section.isValid()))); + + 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()); } @@ -71,26 +132,33 @@ public class ManageCommand extends Command { } case "list": { - TextComponent message = new TextComponent("These are the configured sections"); - message.setColor(ChatColor.GREEN); + Set keys = plugin.getSectionManager().getSections().keySet(); + Iterator iterator = keys.iterator(); + TextComponent message = new TextComponent(String.format("There are %s configured sections:\n", keys.size())); + message.setColor(ChatColor.GRAY); - //GRIS Y VERDE CLARO - //Format: Section %s (Info) - plugin.getSectionManager().getSections().forEach((name, section) -> { - ComponentBuilder builder = new ComponentBuilder("Section %s (Info)"); - TextComponent extra = new TextComponent(builder.create()); + 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); + } - message.addExtra("\n"); message.addExtra(extra); - }); - - //TODO X players are connected to your network + } + sender.sendMessage(message); break; } default: { - msgr.send(ChatColor.RED + "This is not a valid argument for this command!"); + msgr.send("&cThis is not a valid argument for this command!"); sendHelper(msgr); } } @@ -104,12 +172,16 @@ public class ManageCommand extends Command { private void sendHelper(Messager msgr) { msgr.send( - "&e=====================================================", + "&7&m-----------------------------------------------------", "&7Available commands:", "&3/section list &7- &cTells you which sections are configured in the plugin", "&3/section info
&7- &cTells you info about the section", "&3/section connect [section] &7- &cConnects you or the specified player to that section", - "&e=====================================================" + "&7&m-----------------------------------------------------" ); } + + private String format(boolean reference) { + return reference ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"; + } } diff --git a/src/main/java/me/jaimemartz/lobbybalancer/utils/WrappedAdapter.java b/src/main/java/me/jaimemartz/lobbybalancer/utils/WrappedAdapter.java index d008d4a..803bf91 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/utils/WrappedAdapter.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/utils/WrappedAdapter.java @@ -9,6 +9,7 @@ import java.util.Map; public class WrappedAdapter implements ConfigurationAdapter { private final ConfigurationAdapter adapter; + public WrappedAdapter(ConfigurationAdapter adapter) { this.adapter = adapter; }