Before service refractor

This commit is contained in:
Jaime Martínez Rincón 2017-12-26 01:28:06 +01:00
parent 562bfec13a
commit 4f8840c765
6 changed files with 32 additions and 26 deletions

View File

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

View File

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

View File

@ -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();

View File

@ -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, '&');
}
}

View File

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

View File

@ -21,4 +21,8 @@ public final class MessageUtils {
send(sender, text);
}
public static String revertColor(String string) {
return string.replace(ChatColor.COLOR_CHAR, '&');
}
}