From 4f8840c7656bc82fffa0dfeb2565c8383f6f1853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Mart=C3=ADnez=20Rinc=C3=B3n?= Date: Tue, 26 Dec 2017 01:28:06 +0100 Subject: [PATCH] Before service refractor --- .../playerbalancer/PlayerBalancer.java | 19 +++++++---------- .../commands/ManageCommand.java | 21 +++++++++++++------ .../PluginMessageListener.java} | 6 +++--- .../playerbalancer/ping/ServerStatus.java | 7 ++----- .../section/SectionCommand.java | 1 + .../playerbalancer/utils/MessageUtils.java | 4 ++++ 6 files changed, 32 insertions(+), 26 deletions(-) rename Main Plugin/src/main/java/com/jaimemartz/playerbalancer/{services/MessagingService.java => listeners/PluginMessageListener.java} (98%) diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java index b74ffa5..0736cee 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java @@ -4,17 +4,13 @@ import com.google.common.reflect.TypeToken; import com.jaimemartz.playerbalancer.commands.MainCommand; import com.jaimemartz.playerbalancer.commands.ManageCommand; import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry; -import com.jaimemartz.playerbalancer.listeners.PlayerDisconnectListener; -import com.jaimemartz.playerbalancer.listeners.ProxyReloadListener; -import com.jaimemartz.playerbalancer.listeners.ServerConnectListener; -import com.jaimemartz.playerbalancer.listeners.ServerKickListener; +import com.jaimemartz.playerbalancer.listeners.*; import com.jaimemartz.playerbalancer.manager.NetworkManager; import com.jaimemartz.playerbalancer.manager.PasteHelper; import com.jaimemartz.playerbalancer.manager.PlayerLocker; import com.jaimemartz.playerbalancer.ping.StatusManager; import com.jaimemartz.playerbalancer.section.SectionManager; import com.jaimemartz.playerbalancer.services.FallbackService; -import com.jaimemartz.playerbalancer.services.MessagingService; import com.jaimemartz.playerbalancer.settings.SettingsHolder; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Listener; @@ -40,8 +36,7 @@ public class PlayerBalancer extends Plugin { private ConfigurationLoader loader; private FallbackService fallbackService; private Command mainCommand, manageCommand; - private MessagingService messagingService; - private Listener connectListener, kickListener, reloadListener; + private Listener connectListener, kickListener, reloadListener, pluginMessageListener; @Override public void onEnable() { @@ -138,8 +133,8 @@ public class PlayerBalancer extends Plugin { getProxy().getPluginManager().registerListener(this, statusManager); - messagingService = new MessagingService(this); - getProxy().getPluginManager().registerListener(this, messagingService); + pluginMessageListener = new PluginMessageListener(this); + getProxy().getPluginManager().registerListener(this, pluginMessageListener); } manageCommand = new ManageCommand(this); @@ -214,10 +209,10 @@ public class PlayerBalancer extends Plugin { } if (settings.getGeneralProps().isPluginMessaging()) { - if (messagingService != null) { + if (pluginMessageListener != null) { getProxy().unregisterChannel("PlayerBalancer"); - getProxy().getPluginManager().unregisterListener(messagingService); - messagingService = null; + getProxy().getPluginManager().unregisterListener(pluginMessageListener); + pluginMessageListener = null; } } diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java index ba7fecd..7da8639 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java @@ -148,9 +148,11 @@ public class ManageCommand extends Command { .color(ChatColor.AQUA) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Permission: ") .color(ChatColor.GRAY) - .append(section.getCommand().getPermission().equals("") ? "None" : section.getCommand().getPermission()) + .append("\"") + .append(section.getCommand().getPermission()) .color(ChatColor.AQUA) - .append("\nAliases: ") + .append("\n") + .append("Aliases: ") .color(ChatColor.GRAY) .append(Arrays.toString(section.getCommand().getAliases())) .color(ChatColor.AQUA) @@ -179,15 +181,20 @@ public class ManageCommand extends Command { .color(ChatColor.GRAY) .append(server.getName()) .color(ChatColor.AQUA) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Online: ") + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ComponentBuilder("Online: ") .color(ChatColor.GRAY) .append(status.isOnline() ? "yes" : "no") .color(status.isOnline() ? ChatColor.GREEN : ChatColor.RED) - .append("\nAccessible: ") + + .append("\n") + .append("Accessible: ") .color(ChatColor.GRAY) .append(accessible ? "yes" : "no") .color(accessible ? ChatColor.GREEN : ChatColor.RED) - .append("\nDescription: ") + + .append("\n") + .append("Description: ") .color(ChatColor.GRAY) .append("\"") .color(ChatColor.AQUA) @@ -195,7 +202,9 @@ public class ManageCommand extends Command { .color(ChatColor.WHITE) .append("\"") .color(ChatColor.AQUA) - .append("\nAddress: ") + + .append("\n") + .append("Address: ") .color(ChatColor.GRAY) .append(server.getAddress().toString()) .color(ChatColor.AQUA) diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/services/MessagingService.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/PluginMessageListener.java similarity index 98% rename from Main Plugin/src/main/java/com/jaimemartz/playerbalancer/services/MessagingService.java rename to Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/PluginMessageListener.java index cbfb98d..19c1990 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/services/MessagingService.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/PluginMessageListener.java @@ -1,4 +1,4 @@ -package com.jaimemartz.playerbalancer.services; +package com.jaimemartz.playerbalancer.listeners; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; @@ -22,11 +22,11 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.concurrent.TimeUnit; -public class MessagingService implements Listener { +public class PluginMessageListener implements Listener { private final PlayerBalancer plugin; private final Gson gson; - public MessagingService(PlayerBalancer plugin) { + public PluginMessageListener(PlayerBalancer plugin) { this.plugin = plugin; GsonBuilder builder = new GsonBuilder(); diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/ServerStatus.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/ServerStatus.java index 303d6eb..836f76b 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/ServerStatus.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/ServerStatus.java @@ -1,8 +1,9 @@ package com.jaimemartz.playerbalancer.ping; -import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.config.ServerInfo; +import static com.jaimemartz.playerbalancer.utils.MessageUtils.revertColor; + public class ServerStatus { private final String description; private final int players, maximum; @@ -75,8 +76,4 @@ public class ServerStatus { public void setOutdated(boolean outdated) { this.outdated = outdated; } - - private static String revertColor(String string) { - return string.replace(ChatColor.COLOR_CHAR, '&'); - } } \ No newline at end of file diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java index e467b90..d0e8e4f 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java @@ -4,6 +4,7 @@ import com.jaimemartz.playerbalancer.PlayerBalancer; import com.jaimemartz.playerbalancer.services.FallbackService; import net.md_5.bungee.api.connection.ProxiedPlayer; +//This is unsafe, make it extend just the command, not the listener too public class SectionCommand extends FallbackService { private final ServerSection section; diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java index 013032e..d526cc1 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java @@ -21,4 +21,8 @@ public final class MessageUtils { send(sender, text); } + + public static String revertColor(String string) { + return string.replace(ChatColor.COLOR_CHAR, '&'); + } }