Start a hugely messy implementation of the API
This commit is contained in:
parent
8c942e299f
commit
098ca5920e
@ -97,4 +97,14 @@ public abstract class ProxyServer
|
|||||||
* @param adapter the adapter to use
|
* @param adapter the adapter to use
|
||||||
*/
|
*/
|
||||||
public abstract void setConfigurationAdapter(ConfigurationAdapter adapter);
|
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();
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,13 @@ public abstract class ProxiedPlayer implements Connection, CommandSender
|
|||||||
*/
|
*/
|
||||||
public abstract void connect(Server server);
|
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.
|
* Gets the ping time between the proxy and this connection.
|
||||||
*
|
*
|
||||||
|
@ -17,6 +17,16 @@ public abstract class Command
|
|||||||
private final String permission;
|
private final String permission;
|
||||||
private final String[] aliases;
|
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.
|
* Construct a new command.
|
||||||
*
|
*
|
||||||
|
@ -6,17 +6,26 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.Timer;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import lombok.Getter;
|
||||||
import static net.md_5.bungee.Logger.$;
|
import static net.md_5.bungee.Logger.$;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
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.command.*;
|
||||||
import net.md_5.bungee.packet.DefinedPacket;
|
import net.md_5.bungee.packet.DefinedPacket;
|
||||||
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
||||||
@ -29,7 +38,7 @@ import net.md_5.bungee.tablist.TabListHandler;
|
|||||||
/**
|
/**
|
||||||
* Main BungeeCord proxy class.
|
* Main BungeeCord proxy class.
|
||||||
*/
|
*/
|
||||||
public class BungeeCord
|
public class BungeeCord extends ProxyServer
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,10 +49,6 @@ public class BungeeCord
|
|||||||
* Server game version.
|
* Server game version.
|
||||||
*/
|
*/
|
||||||
public static final String GAME_VERSION = "1.4.6";
|
public static final String GAME_VERSION = "1.4.6";
|
||||||
/**
|
|
||||||
* Current software instance.
|
|
||||||
*/
|
|
||||||
public static BungeeCord instance;
|
|
||||||
/**
|
/**
|
||||||
* Current operation state.
|
* Current operation state.
|
||||||
*/
|
*/
|
||||||
@ -59,7 +64,7 @@ public class BungeeCord
|
|||||||
/**
|
/**
|
||||||
* locations.yml save thread.
|
* locations.yml save thread.
|
||||||
*/
|
*/
|
||||||
private final ReconnectSaveThread saveThread = new ReconnectSaveThread();
|
private final Timer saveThread = new Timer("Reconnect Saver");
|
||||||
/**
|
/**
|
||||||
* Server socket listener.
|
* Server socket listener.
|
||||||
*/
|
*/
|
||||||
@ -88,18 +93,20 @@ public class BungeeCord
|
|||||||
/**
|
/**
|
||||||
* Plugin manager.
|
* Plugin manager.
|
||||||
*/
|
*/
|
||||||
public final JavaPluginManager pluginManager = new JavaPluginManager();
|
@Getter
|
||||||
|
public final PluginManager pluginManager = new PluginManager();
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
commandMap.put("greload", new CommandReload());
|
getPluginManager().registerCommand(new CommandReload());
|
||||||
commandMap.put("end", new CommandEnd());
|
getPluginManager().registerCommand(new CommandReload());
|
||||||
commandMap.put("glist", new CommandList());
|
getPluginManager().registerCommand(new CommandEnd());
|
||||||
commandMap.put("server", new CommandServer());
|
getPluginManager().registerCommand(new CommandList());
|
||||||
commandMap.put("ip", new CommandIP());
|
getPluginManager().registerCommand(new CommandServer());
|
||||||
commandMap.put("alert", new CommandAlert());
|
getPluginManager().registerCommand(new CommandIP());
|
||||||
commandMap.put("motd", new CommandMotd());
|
getPluginManager().registerCommand(new CommandAlert());
|
||||||
commandMap.put("bungee", new CommandBungee());
|
getPluginManager().registerCommand(new CommandMotd());
|
||||||
|
getPluginManager().registerCommand(new CommandBungee());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,17 +117,18 @@ public class BungeeCord
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws IOException
|
public static void main(String[] args) throws IOException
|
||||||
{
|
{
|
||||||
instance = new BungeeCord();
|
BungeeCord bungee = new BungeeCord();
|
||||||
$().info("Enabled BungeeCord version " + instance.version);
|
ProxyServer.setInstance(bungee);
|
||||||
instance.start();
|
$().info("Enabled BungeeCord version " + bungee.getVersion());
|
||||||
|
bungee.start();
|
||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
while (instance.isRunning)
|
while (bungee.isRunning)
|
||||||
{
|
{
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if (line != null)
|
if (line != null)
|
||||||
{
|
{
|
||||||
boolean handled = instance.dispatchCommand(line, ConsoleCommandSender.instance);
|
boolean handled = getInstance().getPluginManager().dispatchCommand(ConsoleCommandSender.instance, line);
|
||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
System.err.println("Command not found");
|
System.err.println("Command not found");
|
||||||
@ -338,4 +346,52 @@ public class BungeeCord
|
|||||||
globalPluginChannels.add(channel);
|
globalPluginChannels.add(channel);
|
||||||
broadcast(new PacketFAPluginMessage("REGISTER", channel.getBytes()));
|
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<ProxiedPlayer> 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<Server> 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.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +1,22 @@
|
|||||||
package net.md_5.bungee.command;
|
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.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 class CommandAlert extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public CommandAlert()
|
||||||
|
{
|
||||||
|
super("alert", "bungee.command.alert");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
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)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.RED + "You must supply a message.");
|
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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,20 @@ package net.md_5.bungee.command;
|
|||||||
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
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 class CommandBungee extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public CommandBungee()
|
||||||
|
{
|
||||||
|
super("bungee");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
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 + "This server is running BungeeCord version " + BungeeCord.version + " by md_5");
|
||||||
sender.sendMessage(ChatColor.BLUE + "Your current permission level is " + getPermission(sender).name());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.md_5.bungee.command;
|
package net.md_5.bungee.command;
|
||||||
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.Permission;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command to terminate the proxy instance. May only be used by the console.
|
* 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 class CommandEnd extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public CommandEnd()
|
||||||
|
{
|
||||||
|
super("end", "bungeecord.command.end");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
public void execute(CommandSender sender, String[] args)
|
||||||
{
|
{
|
||||||
if (getPermission(sender) != Permission.ADMIN)
|
BungeeCord.getInstance().stop();
|
||||||
{
|
|
||||||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command");
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
BungeeCord.instance.stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,28 @@
|
|||||||
package net.md_5.bungee.command;
|
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.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 class CommandIP extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public CommandIP()
|
||||||
|
{
|
||||||
|
super("ip", "bungeecord.command.ip");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
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)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.RED + "Please follow this command by a user name");
|
sender.sendMessage(ChatColor.RED + "Please follow this command by a user name");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserConnection user = BungeeCord.instance.connections.get(args[0]);
|
ProxiedPlayer user = ProxyServer.getInstance().getPlayer(args[0]);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.RED + "That user is not online");
|
sender.sendMessage(ChatColor.RED + "That user is not online");
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package net.md_5.bungee.command;
|
package net.md_5.bungee.command;
|
||||||
|
|
||||||
import java.util.Collection;
|
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.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.
|
* 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 class CommandList extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public CommandList()
|
||||||
|
{
|
||||||
|
super("list", "bungeecord.command.list");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
public void execute(CommandSender sender, String[] args)
|
||||||
{
|
{
|
||||||
StringBuilder users = new StringBuilder();
|
StringBuilder users = new StringBuilder();
|
||||||
Collection<UserConnection> connections = BungeeCord.instance.connections.values();
|
Collection<ProxiedPlayer> connections = ProxyServer.getInstance().getPlayers();
|
||||||
|
|
||||||
if (connections.isEmpty())
|
if (connections.isEmpty())
|
||||||
{
|
{
|
||||||
@ -23,18 +30,9 @@ public class CommandList extends Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UserConnection con : connections)
|
for (ProxiedPlayer player : connections)
|
||||||
{
|
{
|
||||||
switch (getPermission(con))
|
users.append(player.getDisplayName());
|
||||||
{
|
|
||||||
case ADMIN:
|
|
||||||
users.append(ChatColor.RED);
|
|
||||||
break;
|
|
||||||
case MODERATOR:
|
|
||||||
users.append(ChatColor.GREEN);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
users.append(con.username);
|
|
||||||
users.append(", ");
|
users.append(", ");
|
||||||
users.append(ChatColor.RESET);
|
users.append(ChatColor.RESET);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package net.md_5.bungee.command;
|
package net.md_5.bungee.command;
|
||||||
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
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.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
|
* 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 class CommandMotd extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public CommandMotd()
|
||||||
|
{
|
||||||
|
super("bungeecord.command.motd");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
public void execute(CommandSender sender, String[] args)
|
||||||
{
|
{
|
||||||
if (getPermission(sender) != Permission.ADMIN)
|
StringBuilder newMOTD = new StringBuilder();
|
||||||
{
|
|
||||||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command");
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
String newMOTD = "";
|
|
||||||
for (String s : args)
|
for (String s : args)
|
||||||
{
|
{
|
||||||
newMOTD = newMOTD + s + " ";
|
newMOTD.append(s);
|
||||||
}
|
newMOTD.append(" ");
|
||||||
newMOTD = newMOTD.substring(0, newMOTD.length() - 1);
|
|
||||||
BungeeCord.instance.config.motd = ChatColor.translateAlternateColorCodes('&', newMOTD);
|
|
||||||
}
|
}
|
||||||
|
((BungeeCord) ProxyServer.getInstance()).config.motd = ChatColor.translateAlternateColorCodes('&', newMOTD.substring(0, newMOTD.length() - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
package net.md_5.bungee.command;
|
package net.md_5.bungee.command;
|
||||||
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
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.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 class CommandReload extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public CommandReload()
|
||||||
|
{
|
||||||
|
super("greload", "bungeecord.command.reload");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
public void execute(CommandSender sender, String[] args)
|
||||||
{
|
{
|
||||||
if (getPermission(sender) != Permission.ADMIN)
|
((BungeeCord) ProxyServer.getInstance()).config.load();
|
||||||
{
|
|
||||||
sender.sendMessage(ChatColor.RED + "You do not have permission to execute this command!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BungeeCord.instance.config.load();
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "Reloaded config, please restart if you have any issues");
|
sender.sendMessage(ChatColor.GREEN + "Reloaded config, please restart if you have any issues");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
}
|
|
@ -4,6 +4,11 @@ import java.util.Collection;
|
|||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.UserConnection;
|
import net.md_5.bungee.UserConnection;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
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.
|
* 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 class CommandServer extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public CommandServer()
|
||||||
|
{
|
||||||
|
super("server", "bungeecord.command.server");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args)
|
public void execute(CommandSender sender, String[] args)
|
||||||
{
|
{
|
||||||
if (!(sender instanceof UserConnection))
|
if (!(sender instanceof ProxiedPlayer))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserConnection con = (UserConnection) sender;
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
Collection<String> servers = BungeeCord.instance.config.servers.keySet();
|
Collection<Server> servers = ProxyServer.getInstance().getServers();
|
||||||
if (args.length <= 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
StringBuilder serverList = new StringBuilder();
|
StringBuilder serverList = new StringBuilder();
|
||||||
for (String server : servers)
|
for (Server server : servers)
|
||||||
{
|
{
|
||||||
serverList.append(server);
|
serverList.append(server.getInfo().getName());
|
||||||
serverList.append(", ");
|
serverList.append(", ");
|
||||||
}
|
}
|
||||||
serverList.setLength(serverList.length() - 2);
|
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
|
} else
|
||||||
{
|
{
|
||||||
String server = args[0];
|
Server server = ProxyServer.getInstance().getServer(args[0]);
|
||||||
if (!servers.contains(server))
|
if (server == null)
|
||||||
{
|
{
|
||||||
con.sendMessage(ChatColor.RED + "The specified server does not exist");
|
player.sendMessage(ChatColor.RED + "The specified server does not exist");
|
||||||
} else if (args[0].equals(con.getServer()))
|
} 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
|
} else
|
||||||
{
|
{
|
||||||
con.connect(server);
|
player.connect(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package net.md_5.bungee.command;
|
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.ChatColor;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command sender representing the proxy console.
|
* Command sender representing the proxy console.
|
||||||
@ -21,4 +24,34 @@ public class ConsoleCommandSender implements CommandSender
|
|||||||
{
|
{
|
||||||
return "CONSOLE";
|
return "CONSOLE";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> 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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<JavaPlugin> 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<? extends JavaPlugin> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -4,23 +4,23 @@ import java.util.Collections;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import net.md_5.bungee.BungeeCord;
|
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;
|
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||||
|
|
||||||
public class GlobalPingTabList extends GlobalTabList
|
public class GlobalPingTabList extends GlobalTabList
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final int PING_THRESHOLD = 20;
|
public static final int PING_THRESHOLD = 20;
|
||||||
private Map<UserConnection, Integer> lastPings = Collections.synchronizedMap(new WeakHashMap<UserConnection, Integer>());
|
private Map<ProxiedPlayer, Integer> lastPings = Collections.synchronizedMap(new WeakHashMap<ProxiedPlayer, Integer>());
|
||||||
|
|
||||||
@Override
|
@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))
|
if (lastPing == null || (ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing))
|
||||||
{
|
{
|
||||||
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, true, ping));
|
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, ping));
|
||||||
lastPings.put(con, ping);
|
lastPings.put(player, ping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,17 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.UserConnection;
|
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;
|
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||||
|
|
||||||
public class GlobalTabList implements TabListHandler
|
public class GlobalTabList implements TabListHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
private Set<UserConnection> sentPings = Collections.synchronizedSet(new HashSet<UserConnection>());
|
private Set<ProxiedPlayer> sentPings = Collections.synchronizedSet(new HashSet<ProxiedPlayer>());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onJoin(UserConnection con)
|
public void onConnect(ProxiedPlayer player)
|
||||||
{
|
{
|
||||||
for (UserConnection c : BungeeCord.instance.connections.values())
|
for (UserConnection c : BungeeCord.instance.connections.values())
|
||||||
{
|
{
|
||||||
@ -22,29 +24,29 @@ public class GlobalTabList implements TabListHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServerChange(UserConnection con)
|
public void onPingChange(ProxiedPlayer player, int ping)
|
||||||
{
|
{
|
||||||
}
|
if (!sentPings.contains(player))
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPingChange(final UserConnection con, final int ping)
|
|
||||||
{
|
{
|
||||||
if (!sentPings.contains(con))
|
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing()));
|
||||||
{
|
sentPings.add(player);
|
||||||
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, true, con.getPing()));
|
|
||||||
sentPings.add(con);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect(final UserConnection con)
|
public void onDisconnect(ProxiedPlayer player)
|
||||||
{
|
{
|
||||||
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(con.tabListName, false, 9999));
|
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999));
|
||||||
sentPings.remove(con);
|
sentPings.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5,30 +5,41 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
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;
|
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||||
|
|
||||||
public class ServerUniqueTabList implements TabListHandler
|
public class ServerUniqueTabList implements TabListHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
private Map<UserConnection, Set<String>> sentUsernames = Collections.synchronizedMap(new WeakHashMap<UserConnection, Set<String>>());
|
private Map<ProxiedPlayer, Set<String>> sentUsernames = Collections.synchronizedMap(new WeakHashMap<ProxiedPlayer, Set<String>>());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onJoin(UserConnection con)
|
public void onConnect(ProxiedPlayer player)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServerChange(UserConnection con)
|
public void onPingChange(ProxiedPlayer player, int ping)
|
||||||
{
|
{
|
||||||
Set<String> usernames = sentUsernames.get(con);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisconnect(ProxiedPlayer player)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServerChange(ProxiedPlayer player)
|
||||||
|
{
|
||||||
|
Set<String> usernames = sentUsernames.get(player);
|
||||||
if (usernames != null)
|
if (usernames != null)
|
||||||
{
|
{
|
||||||
synchronized (usernames)
|
synchronized (usernames)
|
||||||
{
|
{
|
||||||
for (String username : usernames)
|
for (String username : usernames)
|
||||||
{
|
{
|
||||||
con.packetQueue.add(new PacketC9PlayerListItem(username, false, 9999));
|
player.packetQueue.add(new PacketC9PlayerListItem(username, false, 9999));
|
||||||
}
|
}
|
||||||
usernames.clear();
|
usernames.clear();
|
||||||
}
|
}
|
||||||
@ -36,31 +47,21 @@ public class ServerUniqueTabList implements TabListHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPingChange(UserConnection con, int ping)
|
public boolean onListUpdate(ProxiedPlayer player, String name, boolean online, int ping)
|
||||||
{
|
{
|
||||||
}
|
Set<String> usernames = sentUsernames.get(player);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisconnect(UserConnection con)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPacketC9(final UserConnection con, final PacketC9PlayerListItem packet)
|
|
||||||
{
|
|
||||||
Set<String> usernames = sentUsernames.get(con);
|
|
||||||
if (usernames == null)
|
if (usernames == null)
|
||||||
{
|
{
|
||||||
usernames = new LinkedHashSet<>();
|
usernames = new LinkedHashSet<>();
|
||||||
sentUsernames.put(con, usernames);
|
sentUsernames.put(player, usernames);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet.online)
|
if (online)
|
||||||
{
|
{
|
||||||
usernames.add(packet.username);
|
usernames.add(name);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
usernames.remove(packet.username);
|
usernames.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -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);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user