From 592a504e77e3b6c4f45d3e565f0e8d9196e2f222 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 17 Jan 2013 11:59:59 +1100 Subject: [PATCH] Start work on making it compile again. --- .../java/net/md_5/bungee/api/ProxyServer.java | 5 +- .../api/connection/ConnectedPlayer.java | 2 +- .../bungee/api/connection/ProxiedPlayer.java | 28 ++++--- .../md_5/bungee/api/connection/Server.java | 17 ++-- .../main/java/net/md_5/bungee/BungeeCord.java | 56 +++---------- .../java/net/md_5/bungee/Configuration.java | 21 ----- .../java/net/md_5/bungee/ListenThread.java | 6 +- .../src/main/java/net/md_5/bungee/Logger.java | 2 +- .../main/java/net/md_5/bungee/Metrics.java | 7 +- .../net/md_5/bungee/ServerConnection.java | 46 +++++++++-- .../java/net/md_5/bungee/UserConnection.java | 79 +++++++++++++++++-- .../bungee/tablist/GlobalPingTabList.java | 2 +- .../md_5/bungee/tablist/GlobalTabList.java | 8 +- .../bungee/tablist/ServerUniqueTabList.java | 3 +- 14 files changed, 168 insertions(+), 114 deletions(-) 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 9f9280cd..112beac5 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 @@ -105,6 +105,9 @@ public abstract class ProxyServer /** * Start this instance so that it may accept connections. + * + * @throws Exception any exception thrown during startup causing the + * instance to fail to boot */ - public abstract void start(); + public abstract void start() throws Exception; } diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ConnectedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ConnectedPlayer.java index 904edfb7..cf09a65a 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ConnectedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ConnectedPlayer.java @@ -3,6 +3,6 @@ package net.md_5.bungee.api.connection; /** * Represents a player physically connected to the world hosted on this server. */ -public abstract class ConnectedPlayer extends ProxiedPlayer +public interface ConnectedPlayer extends ProxiedPlayer { } 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 30a6cfaa..e3409786 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 @@ -8,15 +8,23 @@ import net.md_5.bungee.api.CommandSender; * Represents a player who's connection is being connected to somewhere else, * whether it be a remote or embedded server. */ -public abstract class ProxiedPlayer implements Connection, CommandSender +public interface ProxiedPlayer extends Connection, CommandSender { /** - * Name displayed to other users in areas such as the tab list. + * Gets this player's display name. + * + * @return the players current display name */ - @Getter - @Setter - private String displayName; + public String getDisplayName(); + + /** + * Sets this players display name to be used as their nametag and tab list + * name. + * + * @param name the name to set + */ + public void setDisplayName(String name); /** * Connects / transfers this user to the specified connection, gracefully @@ -25,21 +33,21 @@ public abstract class ProxiedPlayer implements Connection, CommandSender * * @param server the new server to connect to */ - public abstract void connect(Server server); + public void connect(Server server); /** * Gets the server this player is connected to. * * @return the server this player is connected to */ - public abstract Server getServer(); + public Server getServer(); /** * Gets the ping time between the proxy and this connection. * * @return the current ping time */ - public abstract int getPing(); + public int getPing(); /** * Completely kick this user from the proxy and all of its child @@ -47,7 +55,7 @@ public abstract class ProxiedPlayer implements Connection, CommandSender * * @param reason the disconnect reason displayed to the player */ - public abstract void disconnect(String reason); + public void disconnect(String reason); /** * Send a plugin message to this player. @@ -55,5 +63,5 @@ public abstract class ProxiedPlayer implements Connection, CommandSender * @param channel the channel to send this data via * @param data the data to send */ - public abstract void sendData(String channel, byte[] data); + public void sendData(String channel, byte[] data); } diff --git a/api/src/main/java/net/md_5/bungee/api/connection/Server.java b/api/src/main/java/net/md_5/bungee/api/connection/Server.java index 692729ad..1bb0d04f 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/Server.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/Server.java @@ -11,22 +11,15 @@ import net.md_5.bungee.api.ServerPing; /** * Represents a destination which this proxy might connect to. */ -@RequiredArgsConstructor -public abstract class Server implements Connection +public interface Server extends Connection { /** - * Information about the address, name and configuration regarding this - * server. + * Returns the basic information about this server. + * + * @return the {@link ServerInfo} for this server */ - @Getter - private final ServerInfo info; - - @Override - public InetSocketAddress getAddress() - { - return info.getAddress(); - } + public ServerInfo getInfo(); /** * Send data by any available means to this server. 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 7cb20d28..999af46b 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -1,13 +1,12 @@ package net.md_5.bungee; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; 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; @@ -16,12 +15,11 @@ 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.TabListHandler; import net.md_5.bungee.api.config.ConfigurationAdapter; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.Server; @@ -29,11 +27,9 @@ 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; -import net.md_5.bungee.plugin.JavaPluginManager; import net.md_5.bungee.tablist.GlobalPingTabList; import net.md_5.bungee.tablist.GlobalTabList; import net.md_5.bungee.tablist.ServerUniqueTabList; -import net.md_5.bungee.tablist.TabListHandler; /** * Main BungeeCord proxy class. @@ -78,10 +74,6 @@ public class BungeeCord extends ProxyServer */ public Map connections = new ConcurrentHashMap<>(); public Map> connectionsByServer = new ConcurrentHashMap<>(); - /** - * Registered commands. - */ - public Map commandMap = new HashMap<>(); /** * Tab list handler */ @@ -109,6 +101,11 @@ public class BungeeCord extends ProxyServer getPluginManager().registerCommand(new CommandBungee()); } + public static BungeeCord getInstance() + { + return (BungeeCord) ProxyServer.getInstance(); + } + /** * Starts a new instance of BungeeCord. * @@ -137,39 +134,6 @@ public class BungeeCord extends ProxyServer } } - /** - * Dispatch a command by formatting the arguments and then executing it. - * - * @param commandLine the entire command and arguments string - * @param sender which executed the command - * @return whether the command was handled or not. - */ - public boolean dispatchCommand(String commandLine, CommandSender sender) - { - String[] split = commandLine.trim().split(" "); - String commandName = split[0].toLowerCase(); - Command command = commandMap.get(commandName); - if (config.disabledCommands != null && config.disabledCommands.contains(commandName)) - { - return false; - } else if (command != null) - { - String[] args = Arrays.copyOfRange(split, 1, split.length); - try - { - command.execute(sender, args); - } catch (Exception ex) - { - sender.sendMessage(ChatColor.RED + "An error occurred while executing this command!"); - $().severe("----------------------- [Start of command error] -----------------------"); - $().log(Level.SEVERE, "", ex); - $().severe("----------------------- [End of command error] -----------------------"); - } - } - - return command != null; - } - /** * Start this proxy instance by loading the configuration, plugins and * starting the connect thread. @@ -181,7 +145,9 @@ public class BungeeCord extends ProxyServer config.load(); isRunning = true; - pluginManager.loadPlugins(); + File plugins = new File("plugins"); + plugins.mkdir(); + pluginManager.loadPlugins(plugins); switch (config.tabList) { @@ -328,7 +294,7 @@ public class BungeeCord extends ProxyServer */ public void sendPluginMessage(String channel, String message, String targetServer) { - List conns = BungeeCord.instance.connectionsByServer.get(targetServer); + List conns = connectionsByServer.get(targetServer); if (conns != null && conns.size() > 0) { UserConnection user = conns.get(0); diff --git a/proxy/src/main/java/net/md_5/bungee/Configuration.java b/proxy/src/main/java/net/md_5/bungee/Configuration.java index 01b507b0..86545f6c 100644 --- a/proxy/src/main/java/net/md_5/bungee/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/Configuration.java @@ -16,8 +16,6 @@ import java.util.Map; import java.util.UUID; import static net.md_5.bungee.Logger.$; import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.command.CommandSender; -import net.md_5.bungee.command.ConsoleCommandSender; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; @@ -293,23 +291,4 @@ public class Configuration save(reconnect, reconnectLocations); $().info("Saved reconnect locations to " + reconnect); } - - /** - * Get the highest permission a player has. - * - * @param sender to get permissions of - * @return their permission - */ - public Permission getPermission(CommandSender sender) - { - Permission permission = Permission.DEFAULT; - if (admins.contains(sender.getName()) || sender instanceof ConsoleCommandSender) - { - permission = Permission.ADMIN; - } else if (moderators.contains(sender.getName())) - { - permission = Permission.MODERATOR; - } - return permission; - } } diff --git a/proxy/src/main/java/net/md_5/bungee/ListenThread.java b/proxy/src/main/java/net/md_5/bungee/ListenThread.java index e42e04ad..5d6cbae1 100644 --- a/proxy/src/main/java/net/md_5/bungee/ListenThread.java +++ b/proxy/src/main/java/net/md_5/bungee/ListenThread.java @@ -25,15 +25,15 @@ public class ListenThread extends Thread @Override public void run() { - while (BungeeCord.instance.isRunning) + while (BungeeCord.getInstance().isRunning) { try { Socket client = socket.accept(); - BungeeCord.instance.setSocketOptions(client); + BungeeCord.getInstance().setSocketOptions(client); $().info(client.getInetAddress() + " has connected"); InitialHandler handler = new InitialHandler(client); - BungeeCord.instance.threadPool.submit(handler); + BungeeCord.getInstance().threadPool.submit(handler); } catch (SocketException ex) { } catch (IOException ex) diff --git a/proxy/src/main/java/net/md_5/bungee/Logger.java b/proxy/src/main/java/net/md_5/bungee/Logger.java index 52f4ffd9..63964fe1 100644 --- a/proxy/src/main/java/net/md_5/bungee/Logger.java +++ b/proxy/src/main/java/net/md_5/bungee/Logger.java @@ -23,7 +23,7 @@ public class Logger extends java.util.logging.Logger super("RubberBand", null); try { - FileHandler handler = new FileHandler("proxy.log", BungeeCord.instance.config.logNumLines, 1, true); + FileHandler handler = new FileHandler("proxy.log", BungeeCord.getInstance().config.logNumLines, 1, true); handler.setFormatter(formatter); addHandler(handler); } catch (IOException ex) diff --git a/proxy/src/main/java/net/md_5/bungee/Metrics.java b/proxy/src/main/java/net/md_5/bungee/Metrics.java index fc5e81e5..2be00b5a 100644 --- a/proxy/src/main/java/net/md_5/bungee/Metrics.java +++ b/proxy/src/main/java/net/md_5/bungee/Metrics.java @@ -9,6 +9,7 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import static net.md_5.bungee.Logger.$; +import net.md_5.bungee.api.ProxyServer; public class Metrics extends Thread { @@ -73,10 +74,10 @@ public class Metrics extends Thread { // Construct the post data final StringBuilder data = new StringBuilder(); - data.append(encode("guid")).append('=').append(encode(BungeeCord.instance.config.statsUuid)); - encodeDataPair(data, "version", BungeeCord.instance.version); + data.append(encode("guid")).append('=').append(encode(BungeeCord.getInstance().config.statsUuid)); + encodeDataPair(data, "version", ProxyServer.getInstance().getVersion()); encodeDataPair(data, "server", "0"); - encodeDataPair(data, "players", Integer.toString(BungeeCord.instance.connections.size())); + encodeDataPair(data, "players", Integer.toString(ProxyServer.getInstance().getPlayers().size())); encodeDataPair(data, "revision", String.valueOf(REVISION)); // If we're pinging, append it diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 70f7edb9..b1afe67b 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -4,9 +4,15 @@ import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; import java.security.PublicKey; +import java.util.Collection; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import javax.crypto.SecretKey; +import net.md_5.bungee.api.Callback; +import net.md_5.bungee.api.ServerPing; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.Packet1Login; import net.md_5.bungee.packet.Packet2Handshake; @@ -22,7 +28,7 @@ import org.bouncycastle.crypto.io.CipherOutputStream; /** * Class representing a connection from the proxy to the server; ie upstream. */ -public class ServerConnection extends GenericConnection +public class ServerConnection extends GenericConnection implements Server { public final String name; @@ -41,8 +47,8 @@ public class ServerConnection extends GenericConnection try { Socket socket = new Socket(); - socket.connect(address, BungeeCord.instance.config.timeout); - BungeeCord.instance.setSocketOptions(socket); + socket.connect(address, BungeeCord.getInstance().config.timeout); + BungeeCord.getInstance().setSocketOptions(socket); PacketInputStream in = new PacketInputStream(socket.getInputStream()); OutputStream out = socket.getOutputStream(); @@ -80,7 +86,7 @@ public class ServerConnection extends GenericConnection // Register all global plugin message channels // TODO: Allow player-specific plugin message channels for full mod support - for (String channel : BungeeCord.instance.globalPluginChannels) + for (String channel : BungeeCord.getInstance().globalPluginChannels) { out.write(new PacketFAPluginMessage("REGISTER", channel.getBytes()).getPacket()); } @@ -91,7 +97,7 @@ public class ServerConnection extends GenericConnection throw ex; } catch (Exception ex) { - InetSocketAddress def = BungeeCord.instance.config.getServer(null); + InetSocketAddress def = BungeeCord.getInstance().config.getServer(null); if (retry && !address.equals(def)) { return connect(user, name, def, handshake, false); @@ -101,4 +107,34 @@ public class ServerConnection extends GenericConnection } } } + + @Override + public ServerInfo getInfo() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void sendData(String channel, byte[] data) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void ping(Callback callback) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Collection getPlayers() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public InetSocketAddress getAddress() + { + 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/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index c09e57ad..815cf20c 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -6,17 +6,18 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import net.md_5.bungee.command.CommandSender; +import javax.print.attribute.standard.Destination; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.event.ChatEvent; +import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.packet.*; -import net.md_5.bungee.plugin.ChatEvent; -import net.md_5.bungee.plugin.PluginMessageEvent; -import net.md_5.bungee.plugin.PluginMessageEvent.Destination; -import net.md_5.bungee.plugin.ServerConnectEvent; -public class UserConnection extends GenericConnection implements CommandSender +public class UserConnection extends GenericConnection implements ProxiedPlayer { public final Packet2Handshake handshake; @@ -212,6 +213,72 @@ public class UserConnection extends GenericConnection implements CommandSender return username; } + @Override + public String getDisplayName() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setDisplayName(String name) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void connect(Server server) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Server getServer() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void sendData(String channel, byte[] data) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public InetSocketAddress getAddress() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Collection getGroups() + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void addGroups(String... groups) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void removeGroups(String... groups) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean hasPermission(String permission) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void setPermission(String permission, boolean value) + { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + private class UpstreamBridge extends Thread { 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 7eba09ce..056ecc28 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 @@ -19,7 +19,7 @@ public class GlobalPingTabList extends GlobalTabList Integer lastPing = lastPings.get(player); if (lastPing == null || (ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing)) { - BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, ping)); + BungeeCord.getInstance().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 eae6aa68..08432b5a 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 @@ -17,9 +17,9 @@ public class GlobalTabList implements TabListHandler @Override public void onConnect(ProxiedPlayer player) { - for (UserConnection c : BungeeCord.instance.connections.values()) + for (UserConnection c : BungeeCord.getInstance().connections.values()) { - con.packetQueue.add(new PacketC9PlayerListItem(c.tabListName, true, c.getPing())); + c.packetQueue.add(new PacketC9PlayerListItem(c.tabListName, true, c.getPing())); } } @@ -28,7 +28,7 @@ public class GlobalTabList implements TabListHandler { if (!sentPings.contains(player)) { - BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing())); + BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing())); sentPings.add(player); } } @@ -36,7 +36,7 @@ public class GlobalTabList implements TabListHandler @Override public void onDisconnect(ProxiedPlayer player) { - BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999)); + BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999)); sentPings.remove(player); } 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 ea17938c..bff35075 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,6 +5,7 @@ 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; @@ -39,7 +40,7 @@ public class ServerUniqueTabList implements TabListHandler { for (String username : usernames) { - player.packetQueue.add(new PacketC9PlayerListItem(username, false, 9999)); + ((UserConnection) player).packetQueue.add(new PacketC9PlayerListItem(username, false, 9999)); } usernames.clear(); }