From 098ca5920e9dfa2f5ec0e2e8bb5cea646f332ffc Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 16 Jan 2013 11:16:21 +1100 Subject: [PATCH] Start a hugely messy implementation of the API --- .../java/net/md_5/bungee/api/ProxyServer.java | 10 ++ .../bungee/api/connection/ProxiedPlayer.java | 7 + .../net/md_5/bungee/api/plugin/Command.java | 10 ++ .../main/java/net/md_5/bungee/BungeeCord.java | 96 ++++++++++--- .../main/java/net/md_5/bungee/Permission.java | 18 --- .../net/md_5/bungee/ReconnectSaveThread.java | 30 ----- .../java/net/md_5/bungee/command/Command.java | 26 ---- .../net/md_5/bungee/command/CommandAlert.java | 21 +-- .../md_5/bungee/command/CommandBungee.java | 8 +- .../net/md_5/bungee/command/CommandEnd.java | 17 ++- .../net/md_5/bungee/command/CommandIP.java | 19 +-- .../net/md_5/bungee/command/CommandList.java | 26 ++-- .../net/md_5/bungee/command/CommandMotd.java | 25 ++-- .../md_5/bungee/command/CommandReload.java | 16 ++- .../md_5/bungee/command/CommandSender.java | 19 --- .../md_5/bungee/command/CommandServer.java | 36 +++-- .../bungee/command/ConsoleCommandSender.java | 33 +++++ .../net/md_5/bungee/plugin/Cancellable.java | 22 --- .../net/md_5/bungee/plugin/ChatEvent.java | 36 ----- .../bungee/plugin/InvalidPluginException.java | 20 --- .../net/md_5/bungee/plugin/JavaPlugin.java | 75 ----------- .../md_5/bungee/plugin/JavaPluginManager.java | 127 ------------------ .../net/md_5/bungee/plugin/LoginEvent.java | 33 ----- .../md_5/bungee/plugin/PluginDescription.java | 48 ------- .../bungee/plugin/PluginMessageEvent.java | 47 ------- .../bungee/plugin/ServerConnectEvent.java | 33 ----- .../bungee/tablist/GlobalPingTabList.java | 12 +- .../md_5/bungee/tablist/GlobalTabList.java | 32 ++--- .../bungee/tablist/ServerUniqueTabList.java | 45 ++++--- .../md_5/bungee/tablist/TabListHandler.java | 18 --- 30 files changed, 275 insertions(+), 690 deletions(-) delete mode 100644 proxy/src/main/java/net/md_5/bungee/Permission.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/ReconnectSaveThread.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/command/Command.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/command/CommandSender.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/Cancellable.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/ChatEvent.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/InvalidPluginException.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/JavaPlugin.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/JavaPluginManager.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/LoginEvent.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/PluginDescription.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/PluginMessageEvent.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/tablist/TabListHandler.java diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java index 609db868a..9f9280cd4 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java @@ -97,4 +97,14 @@ public abstract class ProxyServer * @param adapter the adapter to use */ public abstract void setConfigurationAdapter(ConfigurationAdapter adapter); + + /** + * Gracefully mark this instance for shutdown. + */ + public abstract void stop(); + + /** + * Start this instance so that it may accept connections. + */ + public abstract void start(); } diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index efa662ad0..30a6cfaaf 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -27,6 +27,13 @@ public abstract class ProxiedPlayer implements Connection, CommandSender */ public abstract void connect(Server server); + /** + * Gets the server this player is connected to. + * + * @return the server this player is connected to + */ + public abstract Server getServer(); + /** * Gets the ping time between the proxy and this connection. * diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/Command.java b/api/src/main/java/net/md_5/bungee/api/plugin/Command.java index d89a910d6..9f5d088f3 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/Command.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/Command.java @@ -17,6 +17,16 @@ public abstract class Command private final String permission; private final String[] aliases; + /** + * Construct a new command with no permissions or aliases. + * + * @param name the name of this command + */ + public Command(String name) + { + this(name, null); + } + /** * Construct a new command. * diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index c8d9fdf2a..7cb20d286 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -6,17 +6,26 @@ import java.io.InputStreamReader; import java.net.InetSocketAddress; import java.net.Socket; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Queue; +import java.util.Timer; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; +import java.util.logging.Logger; +import lombok.Getter; import static net.md_5.bungee.Logger.$; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ConfigurationAdapter; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.plugin.PluginManager; import net.md_5.bungee.command.*; import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.PacketFAPluginMessage; @@ -29,7 +38,7 @@ import net.md_5.bungee.tablist.TabListHandler; /** * Main BungeeCord proxy class. */ -public class BungeeCord +public class BungeeCord extends ProxyServer { /** @@ -40,10 +49,6 @@ public class BungeeCord * Server game version. */ public static final String GAME_VERSION = "1.4.6"; - /** - * Current software instance. - */ - public static BungeeCord instance; /** * Current operation state. */ @@ -59,7 +64,7 @@ public class BungeeCord /** * locations.yml save thread. */ - private final ReconnectSaveThread saveThread = new ReconnectSaveThread(); + private final Timer saveThread = new Timer("Reconnect Saver"); /** * Server socket listener. */ @@ -88,18 +93,20 @@ public class BungeeCord /** * Plugin manager. */ - public final JavaPluginManager pluginManager = new JavaPluginManager(); + @Getter + public final PluginManager pluginManager = new PluginManager(); { - commandMap.put("greload", new CommandReload()); - commandMap.put("end", new CommandEnd()); - commandMap.put("glist", new CommandList()); - commandMap.put("server", new CommandServer()); - commandMap.put("ip", new CommandIP()); - commandMap.put("alert", new CommandAlert()); - commandMap.put("motd", new CommandMotd()); - commandMap.put("bungee", new CommandBungee()); + getPluginManager().registerCommand(new CommandReload()); + getPluginManager().registerCommand(new CommandReload()); + getPluginManager().registerCommand(new CommandEnd()); + getPluginManager().registerCommand(new CommandList()); + getPluginManager().registerCommand(new CommandServer()); + getPluginManager().registerCommand(new CommandIP()); + getPluginManager().registerCommand(new CommandAlert()); + getPluginManager().registerCommand(new CommandMotd()); + getPluginManager().registerCommand(new CommandBungee()); } /** @@ -110,17 +117,18 @@ public class BungeeCord */ public static void main(String[] args) throws IOException { - instance = new BungeeCord(); - $().info("Enabled BungeeCord version " + instance.version); - instance.start(); + BungeeCord bungee = new BungeeCord(); + ProxyServer.setInstance(bungee); + $().info("Enabled BungeeCord version " + bungee.getVersion()); + bungee.start(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - while (instance.isRunning) + while (bungee.isRunning) { String line = br.readLine(); if (line != null) { - boolean handled = instance.dispatchCommand(line, ConsoleCommandSender.instance); + boolean handled = getInstance().getPluginManager().dispatchCommand(ConsoleCommandSender.instance, line); if (!handled) { System.err.println("Command not found"); @@ -338,4 +346,52 @@ public class BungeeCord globalPluginChannels.add(channel); broadcast(new PacketFAPluginMessage("REGISTER", channel.getBytes())); } + + @Override + public String getName() + { + return "BungeeCord"; + } + + @Override + public String getVersion() + { + return version; + } + + @Override + public Logger getLogger() + { + return $(); + } + + @Override + public Collection getPlayers() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public ProxiedPlayer getPlayer(String name) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Server getServer(String name) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Collection getServers() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setConfigurationAdapter(ConfigurationAdapter adapter) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } } diff --git a/proxy/src/main/java/net/md_5/bungee/Permission.java b/proxy/src/main/java/net/md_5/bungee/Permission.java deleted file mode 100644 index 7a912ad7d..000000000 --- a/proxy/src/main/java/net/md_5/bungee/Permission.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.md_5.bungee; - -public enum Permission -{ - - /** - * Can access all commands. - */ - ADMIN, - /** - * Can access commands which do not affect everyone. - */ - MODERATOR, - /** - * Can access other commands. - */ - DEFAULT; -} diff --git a/proxy/src/main/java/net/md_5/bungee/ReconnectSaveThread.java b/proxy/src/main/java/net/md_5/bungee/ReconnectSaveThread.java deleted file mode 100644 index 92745688d..000000000 --- a/proxy/src/main/java/net/md_5/bungee/ReconnectSaveThread.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.md_5.bungee; - -/** - * Class to call the {@link Configuration#saveHosts() } method at 5 minute - * intervals. - */ -public class ReconnectSaveThread extends Thread -{ - - public ReconnectSaveThread() - { - super("Location Save Thread"); - setPriority(Thread.MIN_PRIORITY); - } - - @Override - public void run() - { - while (BungeeCord.instance.isRunning) - { - try - { - Thread.sleep(5 * 1000 * 60); // 5 minutes - } catch (InterruptedException ex) - { - } - BungeeCord.instance.config.saveHosts(); - } - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/command/Command.java b/proxy/src/main/java/net/md_5/bungee/command/Command.java deleted file mode 100644 index f08336e7a..000000000 --- a/proxy/src/main/java/net/md_5/bungee/command/Command.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.md_5.bungee.command; - -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.Permission; - -/** - * Class which represents a proxy command. The {@link #execute(net.md_5.bungee.command.CommandSender, java.lang.String[]) - * } method will be called to dispatch the command. - */ -public abstract class Command -{ - - /** - * Execute this command. - * - * @param sender the sender executing this command - * @param args the parameters to this command, does not include the '/' or - * the original command. - */ - public abstract void execute(CommandSender sender, String[] args); - - public Permission getPermission(CommandSender sender) - { - return BungeeCord.instance.config.getPermission(sender); - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandAlert.java b/proxy/src/main/java/net/md_5/bungee/command/CommandAlert.java index f8d1c761b..5958c9674 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandAlert.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandAlert.java @@ -1,21 +1,22 @@ package net.md_5.bungee.command; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.Permission; -import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Command; public class CommandAlert extends Command { + public CommandAlert() + { + super("alert", "bungee.command.alert"); + } + @Override public void execute(CommandSender sender, String[] args) { - if (getPermission(sender) != Permission.ADMIN) - { - sender.sendMessage(ChatColor.RED + "You do not have permission to execute this command!"); - return; - } if (args.length == 0) { sender.sendMessage(ChatColor.RED + "You must supply a message."); @@ -36,9 +37,9 @@ public class CommandAlert extends Command } String message = builder.substring(0, builder.length() - 1); - for (UserConnection con : BungeeCord.instance.connections.values()) + for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) { - con.sendMessage(message); + player.sendMessage(message); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java b/proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java index 7e34debb6..490e81b95 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java @@ -2,14 +2,20 @@ package net.md_5.bungee.command; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.plugin.Command; public class CommandBungee extends Command { + public CommandBungee() + { + super("bungee"); + } + @Override public void execute(CommandSender sender, String[] args) { sender.sendMessage(ChatColor.BLUE + "This server is running BungeeCord version " + BungeeCord.version + " by md_5"); - sender.sendMessage(ChatColor.BLUE + "Your current permission level is " + getPermission(sender).name()); } } diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandEnd.java b/proxy/src/main/java/net/md_5/bungee/command/CommandEnd.java index 570d308cf..349ef805d 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandEnd.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandEnd.java @@ -1,8 +1,8 @@ package net.md_5.bungee.command; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.Permission; -import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.plugin.Command; /** * Command to terminate the proxy instance. May only be used by the console. @@ -10,15 +10,14 @@ import net.md_5.bungee.api.ChatColor; public class CommandEnd extends Command { + public CommandEnd() + { + super("end", "bungeecord.command.end"); + } + @Override public void execute(CommandSender sender, String[] args) { - if (getPermission(sender) != Permission.ADMIN) - { - sender.sendMessage(ChatColor.RED + "You do not have permission to use this command"); - } else - { - BungeeCord.instance.stop(); - } + BungeeCord.getInstance().stop(); } } diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandIP.java b/proxy/src/main/java/net/md_5/bungee/command/CommandIP.java index 755f7b6c7..b11c7fea6 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandIP.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandIP.java @@ -1,27 +1,28 @@ package net.md_5.bungee.command; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.Permission; -import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Command; public class CommandIP extends Command { + public CommandIP() + { + super("ip", "bungeecord.command.ip"); + } + @Override public void execute(CommandSender sender, String[] args) { - if (getPermission(sender) != Permission.MODERATOR && getPermission(sender) != Permission.ADMIN) - { - sender.sendMessage(ChatColor.RED + "You do not have permission to use this command"); - return; - } if (args.length < 1) { sender.sendMessage(ChatColor.RED + "Please follow this command by a user name"); return; } - UserConnection user = BungeeCord.instance.connections.get(args[0]); + ProxiedPlayer user = ProxyServer.getInstance().getPlayer(args[0]); if (user == null) { sender.sendMessage(ChatColor.RED + "That user is not online"); diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandList.java b/proxy/src/main/java/net/md_5/bungee/command/CommandList.java index 988106dd6..f836b26bf 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandList.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandList.java @@ -1,9 +1,11 @@ package net.md_5.bungee.command; import java.util.Collection; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Command; /** * Command to list all players connected to the proxy. @@ -11,11 +13,16 @@ import net.md_5.bungee.api.ChatColor; public class CommandList extends Command { + public CommandList() + { + super("list", "bungeecord.command.list"); + } + @Override public void execute(CommandSender sender, String[] args) { StringBuilder users = new StringBuilder(); - Collection connections = BungeeCord.instance.connections.values(); + Collection connections = ProxyServer.getInstance().getPlayers(); if (connections.isEmpty()) { @@ -23,18 +30,9 @@ public class CommandList extends Command return; } - for (UserConnection con : connections) + for (ProxiedPlayer player : connections) { - switch (getPermission(con)) - { - case ADMIN: - users.append(ChatColor.RED); - break; - case MODERATOR: - users.append(ChatColor.GREEN); - break; - } - users.append(con.username); + users.append(player.getDisplayName()); users.append(", "); users.append(ChatColor.RESET); } diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandMotd.java b/proxy/src/main/java/net/md_5/bungee/command/CommandMotd.java index 3acab4c17..22a5ee1cd 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandMotd.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandMotd.java @@ -1,8 +1,10 @@ package net.md_5.bungee.command; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.Permission; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.plugin.Command; /** * Command to set a temp copy of the motd in real-time without stopping the @@ -11,21 +13,20 @@ import net.md_5.bungee.api.ChatColor; public class CommandMotd extends Command { + public CommandMotd() + { + super("bungeecord.command.motd"); + } + @Override public void execute(CommandSender sender, String[] args) { - if (getPermission(sender) != Permission.ADMIN) + StringBuilder newMOTD = new StringBuilder(); + for (String s : args) { - sender.sendMessage(ChatColor.RED + "You do not have permission to use this command"); - } else - { - String newMOTD = ""; - for (String s : args) - { - newMOTD = newMOTD + s + " "; - } - newMOTD = newMOTD.substring(0, newMOTD.length() - 1); - BungeeCord.instance.config.motd = ChatColor.translateAlternateColorCodes('&', newMOTD); + newMOTD.append(s); + newMOTD.append(" "); } + ((BungeeCord) ProxyServer.getInstance()).config.motd = ChatColor.translateAlternateColorCodes('&', newMOTD.substring(0, newMOTD.length() - 1)); } } diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandReload.java b/proxy/src/main/java/net/md_5/bungee/command/CommandReload.java index 337fdf1eb..268a8d461 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandReload.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandReload.java @@ -1,21 +1,23 @@ package net.md_5.bungee.command; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.Permission; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.plugin.Command; public class CommandReload extends Command { + public CommandReload() + { + super("greload", "bungeecord.command.reload"); + } + @Override public void execute(CommandSender sender, String[] args) { - if (getPermission(sender) != Permission.ADMIN) - { - sender.sendMessage(ChatColor.RED + "You do not have permission to execute this command!"); - return; - } - BungeeCord.instance.config.load(); + ((BungeeCord) ProxyServer.getInstance()).config.load(); sender.sendMessage(ChatColor.GREEN + "Reloaded config, please restart if you have any issues"); } } diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandSender.java b/proxy/src/main/java/net/md_5/bungee/command/CommandSender.java deleted file mode 100644 index fb0adf36f..000000000 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandSender.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.md_5.bungee.command; - -public interface CommandSender -{ - - /** - * Sends a message to the client at the earliest available opportunity. - * - * @param message the message to send - */ - public abstract void sendMessage(String message); - - /** - * Get the senders name or CONSOLE for console. - * - * @return the friendly name of the player. - */ - public abstract String getName(); -} diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandServer.java b/proxy/src/main/java/net/md_5/bungee/command/CommandServer.java index f7bdce4db..746b585a1 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandServer.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandServer.java @@ -4,6 +4,11 @@ import java.util.Collection; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.plugin.Command; /** * Command to list and switch a player between available servers. @@ -11,37 +16,42 @@ import net.md_5.bungee.api.ChatColor; public class CommandServer extends Command { + public CommandServer() + { + super("server", "bungeecord.command.server"); + } + @Override public void execute(CommandSender sender, String[] args) { - if (!(sender instanceof UserConnection)) + if (!(sender instanceof ProxiedPlayer)) { return; } - UserConnection con = (UserConnection) sender; - Collection servers = BungeeCord.instance.config.servers.keySet(); - if (args.length <= 0) + ProxiedPlayer player = (ProxiedPlayer) sender; + Collection servers = ProxyServer.getInstance().getServers(); + if (args.length == 0) { StringBuilder serverList = new StringBuilder(); - for (String server : servers) + for (Server server : servers) { - serverList.append(server); + serverList.append(server.getInfo().getName()); serverList.append(", "); } serverList.setLength(serverList.length() - 2); - con.sendMessage(ChatColor.GOLD + "You may connect to the following servers at this time: " + serverList.toString()); + player.sendMessage(ChatColor.GOLD + "You may connect to the following servers at this time: " + serverList.toString()); } else { - String server = args[0]; - if (!servers.contains(server)) + Server server = ProxyServer.getInstance().getServer(args[0]); + if (server == null) { - con.sendMessage(ChatColor.RED + "The specified server does not exist"); - } else if (args[0].equals(con.getServer())) + player.sendMessage(ChatColor.RED + "The specified server does not exist"); + } else if (server == player.getServer()) { - con.sendMessage(ChatColor.RED + "You are already on this server."); + player.sendMessage(ChatColor.RED + "You are already on this server."); } else { - con.connect(server); + player.connect(server); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandSender.java b/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandSender.java index 52d2216c4..77a1a956e 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandSender.java +++ b/proxy/src/main/java/net/md_5/bungee/command/ConsoleCommandSender.java @@ -1,6 +1,9 @@ package net.md_5.bungee.command; +import java.util.Collection; +import java.util.Collections; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; /** * Command sender representing the proxy console. @@ -21,4 +24,34 @@ public class ConsoleCommandSender implements CommandSender { return "CONSOLE"; } + + @Override + public Collection getGroups() + { + return Collections.emptySet(); + } + + @Override + public void addGroups(String... groups) + { + throw new UnsupportedOperationException("Console may not have groups"); + } + + @Override + public void removeGroups(String... groups) + { + throw new UnsupportedOperationException("Console may not have groups"); + } + + @Override + public boolean hasPermission(String permission) + { + return true; + } + + @Override + public void setPermission(String permission, boolean value) + { + throw new UnsupportedOperationException("Console has all permissions"); + } } diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/Cancellable.java b/proxy/src/main/java/net/md_5/bungee/plugin/Cancellable.java deleted file mode 100644 index f4c9bceb3..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/Cancellable.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.md_5.bungee.plugin; - -/** - * An event which may be canceled and this be prevented from happening. - */ -public interface Cancellable -{ - - /** - * Sets the canceled state of this event. - * - * @param canceled whether this event is canceled or not - */ - public void setCancelled(boolean canceled); - - /** - * Gets the canceled state of this event. - * - * @return whether this event is canceled or not - */ - public boolean isCancelled(); -} diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/ChatEvent.java b/proxy/src/main/java/net/md_5/bungee/plugin/ChatEvent.java deleted file mode 100644 index 76fab296b..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/ChatEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.md_5.bungee.plugin; - -import lombok.Data; -import net.md_5.bungee.UserConnection; - -@Data -public class ChatEvent implements Cancellable -{ - - /** - * Canceled state. - */ - private boolean cancelled; - /** - * Whether this packet is destined for the server or the client. - */ - private final Destination destination; - /** - * User in question. - */ - private final UserConnection connection; - /** - * Text contained in this chat. - */ - private String text; - - /** - * An enum that signifies the destination for this packet. - */ - public enum Destination - { - - SERVER, - CLIENT - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/InvalidPluginException.java b/proxy/src/main/java/net/md_5/bungee/plugin/InvalidPluginException.java deleted file mode 100644 index 1c277afd8..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/InvalidPluginException.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.md_5.bungee.plugin; - -/** - * Exception thrown when a plugin could not be loaded for any reason. - */ -public class InvalidPluginException extends RuntimeException -{ - - private static final long serialVersionUID = 1L; - - public InvalidPluginException(String message, Throwable cause) - { - super(message, cause); - } - - public InvalidPluginException(String message) - { - super(message); - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/JavaPlugin.java b/proxy/src/main/java/net/md_5/bungee/plugin/JavaPlugin.java deleted file mode 100644 index 74bbe1826..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/JavaPlugin.java +++ /dev/null @@ -1,75 +0,0 @@ -package net.md_5.bungee.plugin; - -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.command.Command; - -/** - * Base class which all proxy plugins should extend. - */ -public abstract class JavaPlugin -{ - - /** - * Description file. - */ - PluginDescription description; - - /** - * Called on enable. - */ - public void onEnable() - { - } - - /** - * Called on disable. - */ - public void onDisable() - { - } - - /** - * Called when a user connects with their name and address. To keep things - * simple this name has not been checked with minecraft.net. - */ - public void onHandshake(LoginEvent event) - { - } - - /** - * Called after a user has been authed with minecraftt.net and is about to - * log into the proxy. - */ - public void onLogin(LoginEvent event) - { - } - - /** - * Called when a user is connecting to a new server. - */ - public void onServerConnect(ServerConnectEvent event) - { - } - - /** - * Called when a plugin message is sent to the client or server - */ - public void onPluginMessage(PluginMessageEvent event) - { - } - - /** - * Called when a chat message is sent to the client or server - */ - public void onChat(ChatEvent event) - { - } - - /** - * Register a command for use with the proxy. - */ - protected final void registerCommand(String label, Command command) - { - BungeeCord.instance.commandMap.put(label, command); - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/JavaPluginManager.java b/proxy/src/main/java/net/md_5/bungee/plugin/JavaPluginManager.java deleted file mode 100644 index 1a695cc97..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/JavaPluginManager.java +++ /dev/null @@ -1,127 +0,0 @@ -package net.md_5.bungee.plugin; - -import com.google.common.io.PatternFilenameFilter; -import java.io.File; -import java.io.InputStream; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.HashSet; -import java.util.Set; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; -import lombok.Getter; -import static net.md_5.bungee.Logger.$; - -/** - * Plugin manager to handle loading and saving other JavaPlugin's. This class is - * itself a plugin for ease of use. - */ -public class JavaPluginManager extends JavaPlugin -{ - - /** - * Set of loaded plugins. - */ - @Getter - private final Set plugins = new HashSet<>(); - - /** - * Load all plugins from the plugins folder. This method must only be called - * once per instance. - */ - public void loadPlugins() - { - File dir = new File("plugins"); - dir.mkdir(); - - for (File file : dir.listFiles(new PatternFilenameFilter(".*\\.jar"))) - { - try - { - JarFile jar = new JarFile(file); - ZipEntry entry = jar.getEntry("plugin.yml"); - if (entry == null) - { - throw new InvalidPluginException("Jar does not contain a plugin.yml"); - } - - PluginDescription description; - try (InputStream is = jar.getInputStream(entry)) - { - description = PluginDescription.load(is); - } - URLClassLoader classloader = new URLClassLoader(new URL[] - { - file.toURI().toURL() - }, getClass().getClassLoader()); - Class clazz = Class.forName(description.getMain(), true, classloader); - Class subClazz = clazz.asSubclass(JavaPlugin.class); - JavaPlugin plugin = subClazz.getDeclaredConstructor().newInstance(); - - plugin.description = description; - plugin.onEnable(); - plugins.add(plugin); - - $().info("Loaded plugin: " + plugin.description.getName()); - } catch (Exception ex) - { - $().severe("Could not load plugin: " + file); - ex.printStackTrace(); - } - } - } - - @Override - public void onDisable() - { - for (JavaPlugin p : plugins) - { - p.onDisable(); - } - } - - @Override - public void onHandshake(LoginEvent event) - { - for (JavaPlugin p : plugins) - { - p.onHandshake(event); - } - } - - @Override - public void onLogin(LoginEvent event) - { - for (JavaPlugin p : plugins) - { - p.onLogin(event); - } - } - - @Override - public void onServerConnect(ServerConnectEvent event) - { - for (JavaPlugin p : plugins) - { - p.onServerConnect(event); - } - } - - @Override - public void onPluginMessage(PluginMessageEvent event) - { - for (JavaPlugin p : plugins) - { - p.onPluginMessage(event); - } - } - - @Override - public void onChat(ChatEvent event) - { - for (JavaPlugin p : plugins) - { - p.onChat(event); - } - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/LoginEvent.java b/proxy/src/main/java/net/md_5/bungee/plugin/LoginEvent.java deleted file mode 100644 index 16479c84b..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/LoginEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.md_5.bungee.plugin; - -import java.net.InetAddress; -import lombok.Data; - -/** - * Event called to represent a player logging in. - */ -@Data -public class LoginEvent implements Cancellable -{ - - /** - * Canceled state. - */ - private boolean cancelled; - /** - * Message to use when kicking if this event is canceled. - */ - private String cancelReason; - /** - * Username which the player wishes to use. - */ - private final String username; - /** - * IP address of the remote connection. - */ - private final InetAddress address; - /** - * Hostname which the user tried to connect to. - */ - private final String hostname; -} diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/PluginDescription.java b/proxy/src/main/java/net/md_5/bungee/plugin/PluginDescription.java deleted file mode 100644 index 78cca603c..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/PluginDescription.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.md_5.bungee.plugin; - -import java.io.InputStream; -import java.lang.reflect.Field; -import lombok.Data; -import org.yaml.snakeyaml.Yaml; - -/** - * File which contains information about a plugin, its authors, and how to load - * it. - */ -@Data -public class PluginDescription -{ - - private String name; - private String main; - private String version; - private String author; - - private PluginDescription() - { - } - - public static PluginDescription load(InputStream is) - { - PluginDescription ret = new Yaml().loadAs(is, PluginDescription.class); - if (ret == null) - { - throw new InvalidPluginException("Could not load plugin description file."); - } - - for (Field f : PluginDescription.class.getDeclaredFields()) - { - try - { - if (f.get(ret) == null) - { - throw new InvalidPluginException(f.getName() + " is not set properly in plugin description"); - } - } catch (IllegalArgumentException | IllegalAccessException ex) - { - } - } - - return ret; - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/PluginMessageEvent.java b/proxy/src/main/java/net/md_5/bungee/plugin/PluginMessageEvent.java deleted file mode 100644 index ad74ebdd6..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/PluginMessageEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.md_5.bungee.plugin; - -import lombok.Data; -import net.md_5.bungee.UserConnection; - -/** - * Event called when a plugin message is sent to the client or server - */ -@Data -public class PluginMessageEvent implements Cancellable -{ - - /** - * Canceled state. - */ - private boolean cancelled; - /** - * Message to use when kicking if this event is canceled. - */ - private String cancelReason; - /** - * Whether this packet is destined for the server or the client - */ - private final Destination destination; - /** - * User in question - */ - private final UserConnection connection; - /** - * Tag specified for this plugin message. - */ - private String tag; - /** - * Data contained in this plugin message. - */ - private String data; - - /** - * An enum that signifies the destination for this packet - */ - public enum Destination - { - - SERVER, - CLIENT - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java b/proxy/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java deleted file mode 100644 index 6a7339bb7..000000000 --- a/proxy/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.md_5.bungee.plugin; - -import lombok.Data; -import net.md_5.bungee.UserConnection; - -/** - * Event called when the decision is made to decide which server to connect to. - */ -@Data -public class ServerConnectEvent -{ - - /** - * If the player currently has no server, this is true - */ - private final boolean firstTime; - /** - * Message to send just before the change. null for no message - */ - private String message; - /** - * User in question. - */ - private final UserConnection connection; - /** - * Name of the server they are connecting to. - */ - private final String server; - /** - * Name of the server which they will be forwarded to instead. - */ - private String newServer; -} diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPingTabList.java b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPingTabList.java index c8b39b5be..7eba09cef 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPingTabList.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPingTabList.java @@ -4,23 +4,23 @@ import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.UserConnection; +import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.packet.PacketC9PlayerListItem; public class GlobalPingTabList extends GlobalTabList { public static final int PING_THRESHOLD = 20; - private Map lastPings = Collections.synchronizedMap(new WeakHashMap()); + private Map lastPings = Collections.synchronizedMap(new WeakHashMap()); @Override - public void onPingChange(final UserConnection con, final int ping) + public void onPingChange(ProxiedPlayer player, int ping) { - Integer lastPing = lastPings.get(con); + Integer lastPing = lastPings.get(player); if (lastPing == null || (ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing)) { - BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, true, ping)); - lastPings.put(con, ping); + BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, ping)); + lastPings.put(player, ping); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalTabList.java b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalTabList.java index f97fd0e89..eae6aa68c 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalTabList.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalTabList.java @@ -5,15 +5,17 @@ import java.util.HashSet; import java.util.Set; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.UserConnection; +import net.md_5.bungee.api.TabListHandler; +import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.packet.PacketC9PlayerListItem; public class GlobalTabList implements TabListHandler { - private Set sentPings = Collections.synchronizedSet(new HashSet()); + private Set sentPings = Collections.synchronizedSet(new HashSet()); @Override - public void onJoin(UserConnection con) + public void onConnect(ProxiedPlayer player) { for (UserConnection c : BungeeCord.instance.connections.values()) { @@ -22,29 +24,29 @@ public class GlobalTabList implements TabListHandler } @Override - public void onServerChange(UserConnection con) + public void onPingChange(ProxiedPlayer player, int ping) { - } - - @Override - public void onPingChange(final UserConnection con, final int ping) - { - if (!sentPings.contains(con)) + if (!sentPings.contains(player)) { - BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, true, con.getPing())); - sentPings.add(con); + BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing())); + sentPings.add(player); } } @Override - public void onDisconnect(final UserConnection con) + public void onDisconnect(ProxiedPlayer player) { - BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, false, 9999)); - sentPings.remove(con); + BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999)); + sentPings.remove(player); } @Override - public boolean onPacketC9(UserConnection con, PacketC9PlayerListItem packet) + public void onServerChange(ProxiedPlayer player) + { + } + + @Override + public boolean onListUpdate(ProxiedPlayer player, String name, boolean online, int ping) { return false; } diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/ServerUniqueTabList.java b/proxy/src/main/java/net/md_5/bungee/tablist/ServerUniqueTabList.java index e17f7ce49..ea17938c7 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/ServerUniqueTabList.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/ServerUniqueTabList.java @@ -5,30 +5,41 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; -import net.md_5.bungee.UserConnection; +import net.md_5.bungee.api.TabListHandler; +import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.packet.PacketC9PlayerListItem; public class ServerUniqueTabList implements TabListHandler { - private Map> sentUsernames = Collections.synchronizedMap(new WeakHashMap>()); + private Map> sentUsernames = Collections.synchronizedMap(new WeakHashMap>()); @Override - public void onJoin(UserConnection con) + public void onConnect(ProxiedPlayer player) { } @Override - public void onServerChange(UserConnection con) + public void onPingChange(ProxiedPlayer player, int ping) { - Set usernames = sentUsernames.get(con); + } + + @Override + public void onDisconnect(ProxiedPlayer player) + { + } + + @Override + public void onServerChange(ProxiedPlayer player) + { + Set usernames = sentUsernames.get(player); if (usernames != null) { synchronized (usernames) { for (String username : usernames) { - con.packetQueue.add(new PacketC9PlayerListItem(username, false, 9999)); + player.packetQueue.add(new PacketC9PlayerListItem(username, false, 9999)); } usernames.clear(); } @@ -36,31 +47,21 @@ public class ServerUniqueTabList implements TabListHandler } @Override - public void onPingChange(UserConnection con, int ping) + public boolean onListUpdate(ProxiedPlayer player, String name, boolean online, int ping) { - } - - @Override - public void onDisconnect(UserConnection con) - { - } - - @Override - public boolean onPacketC9(final UserConnection con, final PacketC9PlayerListItem packet) - { - Set usernames = sentUsernames.get(con); + Set usernames = sentUsernames.get(player); if (usernames == null) { usernames = new LinkedHashSet<>(); - sentUsernames.put(con, usernames); + sentUsernames.put(player, usernames); } - if (packet.online) + if (online) { - usernames.add(packet.username); + usernames.add(name); } else { - usernames.remove(packet.username); + usernames.remove(name); } return true; diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/TabListHandler.java b/proxy/src/main/java/net/md_5/bungee/tablist/TabListHandler.java deleted file mode 100644 index b11d92e76..000000000 --- a/proxy/src/main/java/net/md_5/bungee/tablist/TabListHandler.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.md_5.bungee.tablist; - -import net.md_5.bungee.UserConnection; -import net.md_5.bungee.packet.PacketC9PlayerListItem; - -public interface TabListHandler -{ - - public void onJoin(UserConnection con); - - public void onServerChange(UserConnection con); - - public void onPingChange(UserConnection con, int ping); - - public void onDisconnect(UserConnection con); - - public boolean onPacketC9(UserConnection con, PacketC9PlayerListItem packet); -}