mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 02:08:27 +01:00
Ditch RedisBungee. Long live the RemotePlayer API
RedisBungee has been abandoned by it's developers. So we're abanding it too. SubServers.Sync will now finally pick up the slack and sync basic player information between proxies over their SubData connection.
This commit is contained in:
parent
f2f196dc79
commit
891913dbe3
@ -30,14 +30,14 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>20w30a</version>
|
||||
<version>20w30b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>20w30a</version>
|
||||
<version>20w30b</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -54,12 +54,6 @@
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<version>0.3.8-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -108,17 +108,6 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is connected to RedisBungee's server
|
||||
*
|
||||
* @return Redis Status
|
||||
*/
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
public boolean isRedis() {
|
||||
SubProxy plugin = SubAPI.getInstance().getInternals();
|
||||
return plugin.redis != null && Util.getDespiteException(() -> plugin.redis("getPlayersOnProxy", new NamedContainer<>(String.class, getName())) != null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is the Master Proxy
|
||||
*
|
||||
@ -133,20 +122,12 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
*
|
||||
* @return Remote Player Collection
|
||||
*/
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
@SuppressWarnings("deprecation")
|
||||
public Collection<RemotePlayer> getPlayers() {
|
||||
List<RemotePlayer> players = new LinkedList<RemotePlayer>();
|
||||
//List<UUID> used = new ArrayList<UUID>();
|
||||
SubProxy plugin = SubAPI.getInstance().getInternals();
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
for (UUID id : (Set<UUID>) plugin.redis("getPlayersOnProxy", new NamedContainer<>(String.class, getName()))) {
|
||||
//if (!used.contains(id)) {
|
||||
players.add(new RemotePlayer(id));
|
||||
// used.add(id);
|
||||
//}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
ArrayList<RemotePlayer> players = new ArrayList<RemotePlayer>();
|
||||
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, this)) {
|
||||
players.add(plugin.rPlayers.get(id));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
@ -199,7 +180,6 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
for (RemotePlayer player : getPlayers())
|
||||
players.set(player.getUniqueId().toString(), player.getName());
|
||||
info.set("players", players);
|
||||
info.set("redis", isRedis());
|
||||
info.set("master", isMaster());
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>();
|
||||
for (int channel : this.subdata.keySet()) subdata.set(channel, (this.subdata.get(channel) == null)?null:this.subdata.get(channel).getID());
|
||||
|
@ -1,14 +1,12 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Container.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataSerializable;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubProxy;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -18,7 +16,7 @@ public class RemotePlayer implements SubDataSerializable {
|
||||
private ProxiedPlayer local;
|
||||
private UUID id;
|
||||
private String name;
|
||||
private InetAddress ip;
|
||||
private InetSocketAddress ip;
|
||||
private Proxy proxy;
|
||||
private Server server;
|
||||
|
||||
@ -36,34 +34,19 @@ public class RemotePlayer implements SubDataSerializable {
|
||||
/**
|
||||
* Search for a Remote Player using their ID
|
||||
*
|
||||
* @param player Remote Player ID
|
||||
* @param name Player Name
|
||||
* @param id Player UUID
|
||||
* @param proxy Proxy the player is on
|
||||
* @param server Server the player is on
|
||||
* @param ip Player IP Address
|
||||
*/
|
||||
public RemotePlayer(UUID player) {
|
||||
if (Util.isNull(player)) throw new NullPointerException();
|
||||
|
||||
id = player;
|
||||
refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a new copy of the data
|
||||
*/
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
public void refresh() {
|
||||
SubProxy plugin = SubAPI.getInstance().getInternals();
|
||||
UUID player = id;
|
||||
|
||||
this.local = plugin.getPlayer(player);
|
||||
if (local == null) {
|
||||
if (plugin.redis != null && Util.getDespiteException(() -> (boolean) plugin.redis("isPlayerOnline", new NamedContainer<>(UUID.class, player)), false)) {
|
||||
server = Util.getDespiteException(() -> (Server) plugin.redis("getServerFor", new NamedContainer<>(UUID.class, player)), null);
|
||||
proxy = Util.getDespiteException(() -> plugin.api.getProxy((String) plugin.redis("getProxy", new NamedContainer<>(UUID.class, player))), null);
|
||||
ip = Util.getDespiteException(() -> (InetAddress) plugin.redis("getPlayerIp", new NamedContainer<>(UUID.class, player)), null);
|
||||
name = Util.getDespiteException(() -> (String) plugin.redis("getNameFromUuid", new NamedContainer<>(UUID.class, player), new NamedContainer<>(boolean.class, false)), null);
|
||||
}
|
||||
|
||||
if (name == null) throw new IllegalStateException("Player " + id.toString() + " not found!");
|
||||
}
|
||||
public RemotePlayer(String name, UUID id, Proxy proxy, Server server, InetSocketAddress ip) {
|
||||
if (Util.isNull(name, id, proxy, ip)) throw new NullPointerException();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.ip = ip;
|
||||
this.proxy = proxy;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,9 +86,9 @@ public class RemotePlayer implements SubDataSerializable {
|
||||
* @return the remote address
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public InetAddress getAddress() {
|
||||
public InetSocketAddress getAddress() {
|
||||
if (local != null) {
|
||||
return local.getAddress().getAddress();
|
||||
return local.getAddress();
|
||||
} else return ip;
|
||||
}
|
||||
|
||||
@ -141,6 +124,7 @@ public class RemotePlayer implements SubDataSerializable {
|
||||
ObjectMap<String> pinfo = new ObjectMap<String>();
|
||||
pinfo.set("name", getName());
|
||||
pinfo.set("id", getUniqueId());
|
||||
pinfo.set("address", getAddress().getAddress().getHostAddress() + ':' + getAddress().getPort());
|
||||
if (getServer() != null) pinfo.set("server", getServer().getName());
|
||||
if (getProxy() != null) pinfo.set("proxy", getProxy().getName());
|
||||
return pinfo;
|
||||
|
@ -157,25 +157,13 @@ public class ServerImpl extends BungeeServerInfo implements Server {
|
||||
Collections.sort(groups);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Collection<RemotePlayer> getGlobalPlayers() {
|
||||
List<RemotePlayer> players = new LinkedList<RemotePlayer>();
|
||||
List<UUID> used = new ArrayList<UUID>();
|
||||
SubProxy plugin = SubAPI.getInstance().getInternals();
|
||||
for (ProxiedPlayer player : getPlayers()) {
|
||||
players.add(new RemotePlayer(player));
|
||||
used.add(player.getUniqueId());
|
||||
}
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
for (UUID id : (Set<UUID>) plugin.redis("getPlayersOnServer", new NamedContainer<>(String.class, getName()))) {
|
||||
if (!used.contains(id)) {
|
||||
players.add(new RemotePlayer(id));
|
||||
used.add(id);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
ArrayList<RemotePlayer> players = new ArrayList<RemotePlayer>();
|
||||
for (UUID id : Util.getBackwards(plugin.rPlayerLinkS, this)) {
|
||||
players.add(plugin.rPlayers.get(id));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
@ -446,8 +446,6 @@ public class ConfigUpdater {
|
||||
def.put("Interface.Generic.Invalid-Permission", "&4You need &n$str$");
|
||||
def.put("Interface.Proxy-Menu.Proxy-Player-Count", "&2$int$ Player(s) Online");
|
||||
def.put("Interface.Proxy-Menu.Proxy-Master", "&8Master Proxy");
|
||||
def.put("Interface.Proxy-Menu.Proxy-SubData", "&9SubData Only");
|
||||
def.put("Interface.Proxy-Menu.Proxy-Redis", "&7Redis Only");
|
||||
def.put("Interface.Proxy-Menu.Proxy-Disconnected", "&4Disconnected");
|
||||
def.put("Interface.Host-Menu.Title", "Host Menu");
|
||||
def.put("Interface.Host-Menu.Host-Unavailable", "&4Unavailable");
|
||||
|
@ -0,0 +1,107 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Host.RemotePlayer;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubProxy;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* External Player Sync Packet
|
||||
*/
|
||||
public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubProxy plugin;
|
||||
private String name;
|
||||
private boolean mode;
|
||||
private RemotePlayer[] values;
|
||||
|
||||
/**
|
||||
* New PacketExSyncPlayer (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketExSyncPlayer(SubProxy plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExSyncPlayer (Out)
|
||||
*
|
||||
* @param name Proxy Name
|
||||
* @param mode Update Mode (true for add, false for remove, null for reset)
|
||||
* @param values RemotePlayers
|
||||
*/
|
||||
public PacketExSyncPlayer(String name, Boolean mode, RemotePlayer... values) {
|
||||
if (Util.isNull(mode)) throw new NullPointerException();
|
||||
this.name = name;
|
||||
this.mode = mode;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, name);
|
||||
data.set(0x0001, mode);
|
||||
if (values != null) {
|
||||
ArrayList<ObjectMap<String>> list = new ArrayList<ObjectMap<String>>();
|
||||
for (RemotePlayer value : values) list.add(value.forSubData());
|
||||
data.set(0x0002, list);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
if (client.getHandler() instanceof Proxy) {
|
||||
ArrayList<RemotePlayer> forward = new ArrayList<RemotePlayer>();
|
||||
if (data.getBoolean(0x0001) == null) {
|
||||
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, (Proxy) client.getHandler())) {
|
||||
plugin.rPlayerLinkS.remove(id);
|
||||
plugin.rPlayerLinkP.remove(id);
|
||||
plugin.rPlayers.remove(id);
|
||||
}
|
||||
}
|
||||
if (data.getBoolean(0x0001) != Boolean.FALSE) {
|
||||
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
||||
Server server = (object.getOrDefault("server", null) != null)?plugin.api.getServer(object.get("server").toString()):null;
|
||||
RemotePlayer player = new RemotePlayer(object.get("name").toString(), UUID.fromString(object.get("id").toString()), (Proxy) client.getHandler(), server,
|
||||
new InetSocketAddress(object.get("address").toString().split(":")[0], Integer.parseInt(object.get("address").toString().split(":")[1])));
|
||||
|
||||
forward.add(player);
|
||||
plugin.rPlayers.put(player.getUniqueId(), player);
|
||||
plugin.rPlayerLinkP.put(player.getUniqueId(), (Proxy) client.getHandler());
|
||||
if (server != null) plugin.rPlayerLinkS.put(player.getUniqueId(), server);
|
||||
}
|
||||
} else {
|
||||
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
||||
UUID id = UUID.fromString(object.get("id").toString());
|
||||
RemotePlayer player = plugin.rPlayers.get(id);
|
||||
|
||||
if (player != null) forward.add(player);
|
||||
plugin.rPlayerLinkS.remove(id);
|
||||
plugin.rPlayerLinkP.remove(id);
|
||||
plugin.rPlayers.remove(id);
|
||||
}
|
||||
}
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null && proxy != client.getHandler()) {
|
||||
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(proxy.getName(), data.getBoolean(0x0001), forward.toArray(new RemotePlayer[0])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -125,11 +125,13 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance.registerPacket(0x0071, PacketOutExReset.class);
|
||||
instance.registerPacket(0x0072, PacketOutExReload.class);
|
||||
instance.registerPacket(0x0073, PacketOutExUpdateWhitelist.class);
|
||||
instance.registerPacket(0x0074, PacketExSyncPlayer.class);
|
||||
|
||||
//instance.registerPacket(0x0070, new PacketOutRunEvent());
|
||||
//instance.registerPacket(0x0071, new PacketOutReset());
|
||||
//instance.registerPacket(0x0072, new PacketOutReload());
|
||||
//instance.registerPacket(0x0073, new PacketOutExUpdateWhitelist());
|
||||
instance.registerPacket(0x0074, new PacketExSyncPlayer(plugin));
|
||||
}
|
||||
|
||||
return instance;
|
||||
|
@ -531,17 +531,17 @@ public final class SubAPI {
|
||||
public Proxy getProxy(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
Proxy proxy = getProxies().getOrDefault(name.toLowerCase(), null);
|
||||
if (proxy == null && plugin.redis != null && plugin.redis.getName().equalsIgnoreCase(name)) proxy = plugin.redis;
|
||||
if (proxy == null && plugin.mProxy != null && plugin.mProxy.getName().equalsIgnoreCase(name)) proxy = plugin.mProxy;
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Master Proxy redis container (null if unavailable)
|
||||
* Get the Master Proxy Container
|
||||
*
|
||||
* @return Master Proxy
|
||||
*/
|
||||
public Proxy getMasterProxy() {
|
||||
return plugin.redis;
|
||||
return plugin.mProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,23 +549,8 @@ public final class SubAPI {
|
||||
*
|
||||
* @return Remote Player Collection
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<UUID, RemotePlayer> getGlobalPlayers() {
|
||||
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
|
||||
SubProxy plugin = SubAPI.getInstance().getInternals();
|
||||
for (ProxiedPlayer player : plugin.getPlayers()) {
|
||||
players.put(player.getUniqueId(), new RemotePlayer(player));
|
||||
}
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
for (UUID id : (Set<UUID>) plugin.redis("getPlayersOnline")) {
|
||||
if (!players.keySet().contains(id)) {
|
||||
players.put(id, new RemotePlayer(id));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
return players;
|
||||
return new HashMap<UUID, RemotePlayer>(plugin.rPlayers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -574,16 +559,12 @@ public final class SubAPI {
|
||||
* @param name Player name
|
||||
* @return Remote Player
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public RemotePlayer getGlobalPlayer(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
SubProxy plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
RemotePlayer remote;
|
||||
ProxiedPlayer local = plugin.getPlayer(name);
|
||||
if (local != null) remote = new RemotePlayer(local);
|
||||
else remote = Util.getDespiteException(() -> new RemotePlayer((UUID) plugin.redis("getUuidFromName", new NamedContainer<>(String.class, name), new NamedContainer<>(boolean.class, false))), null);
|
||||
return remote;
|
||||
for (RemotePlayer player : getGlobalPlayers().values()) {
|
||||
if (player.getName().equalsIgnoreCase(name)) return player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -594,13 +575,7 @@ public final class SubAPI {
|
||||
*/
|
||||
public RemotePlayer getGlobalPlayer(UUID id) {
|
||||
if (Util.isNull(id)) throw new NullPointerException();
|
||||
SubProxy plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
RemotePlayer remote;
|
||||
ProxiedPlayer local = plugin.getPlayer(id);
|
||||
if (local != null) remote = new RemotePlayer(local);
|
||||
else remote = Util.getDespiteException(() -> new RemotePlayer(id), null);
|
||||
return remote;
|
||||
return getGlobalPlayers().getOrDefault(id, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -251,12 +251,8 @@ public final class SubCommand extends CommandX {
|
||||
message = " (master)";
|
||||
for (Proxy proxy : plugin.api.getProxies().values()) {
|
||||
message += div;
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
if (proxy.getSubData()[0] != null) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (proxy.isRedis()) {
|
||||
message += ChatColor.WHITE;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
@ -275,7 +271,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > Info on player: " + ChatColor.WHITE + player.getName());
|
||||
if (player.getProxy() != null) sender.sendMessage(" -> Proxy: " + ChatColor.WHITE + player.getProxy().getName());
|
||||
if (player.getServer() != null) sender.sendMessage(" -> Server: " + ChatColor.WHITE + player.getServer().getName());
|
||||
if (player.getAddress() != null) sender.sendMessage(" -> Address: " + ChatColor.WHITE + player.getAddress().getHostAddress());
|
||||
if (player.getAddress() != null) sender.sendMessage(" -> Address: " + ChatColor.WHITE + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort());
|
||||
sender.sendMessage(" -> UUID: " + ChatColor.AQUA + player.getUniqueId());
|
||||
} else {
|
||||
if (type == null) {
|
||||
@ -368,8 +364,7 @@ public final class SubCommand extends CommandX {
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + proxy.getName());
|
||||
if (!proxy.isMaster()) sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
else if (!proxy.getDisplayName().toLowerCase().contains("master")) sender.sendMessage(" -> Type: " + ChatColor.WHITE + "Master");
|
||||
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Players: " + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + proxy.getSignature());
|
||||
} else {
|
||||
if (type == null) {
|
||||
@ -887,9 +882,7 @@ public final class SubCommand extends CommandX {
|
||||
ReturnRunnable<Collection<String>> getPlayers = () -> {
|
||||
LinkedList<String> names = new LinkedList<String>();
|
||||
for (ProxiedPlayer player : plugin.getPlayers()) names.add(player.getName());
|
||||
if (plugin.redis != null) {
|
||||
for (String name : Util.<Collection<String>>getDespiteException(() -> (Collection<String>) plugin.redis("getHumanPlayersOnline"), Collections.emptyList())) if (!names.contains(name)) names.add(name);
|
||||
}
|
||||
for (RemotePlayer player : plugin.api.getGlobalPlayers().values()) if (!names.contains(player.getName())) names.add(player.getName());
|
||||
Collections.sort(names);
|
||||
return names;
|
||||
};
|
||||
@ -1101,16 +1094,14 @@ public final class SubCommand extends CommandX {
|
||||
if (player.getName().toLowerCase().startsWith(last)) list.add(Last + player.getName().substring(last.length()));
|
||||
used.add(player.getUniqueId());
|
||||
}
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
for (UUID id : (Set<UUID>) plugin.redis("getPlayersOnServer", new NamedContainer<>(String.class, ((ProxiedPlayer) sender).getServer().getInfo().getName()))) {
|
||||
if (!used.contains(id)) {
|
||||
String name = (String) plugin.redis("getNameFromUuid", new NamedContainer<>(UUID.class, id), new NamedContainer<>(boolean.class, false));
|
||||
if (name.toLowerCase().startsWith(last)) list.add(Last + name.substring(last.length()));
|
||||
used.add(id);
|
||||
}
|
||||
|
||||
if (((ProxiedPlayer) sender).getServer().getInfo() instanceof Server) {
|
||||
for (RemotePlayer player : ((Server) ((ProxiedPlayer) sender).getServer().getInfo()).getGlobalPlayers()) {
|
||||
if (!used.contains(player.getUniqueId())) {
|
||||
if (player.getName().toLowerCase().startsWith(last)) list.add(Last + player.getName().substring(last.length()));
|
||||
used.add(player.getUniqueId());
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Server server : plugin.api.getServers().values()) {
|
||||
|
@ -5,7 +5,6 @@ import com.google.common.collect.Range;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.Galaxi.Library.Container.PrimitiveContainer;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Container.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.*;
|
||||
@ -26,6 +25,7 @@ import net.ME1312.SubServers.Bungee.Library.ConfigUpdater;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExSyncPlayer;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExReload;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubProtocol;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
@ -65,6 +65,9 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
public final HashMap<String, Host> hosts = new HashMap<String, Host>();
|
||||
public final HashMap<String, Server> exServers = new HashMap<String, Server>();
|
||||
private final HashMap<String, ServerInfo> legServers = new HashMap<String, ServerInfo>();
|
||||
public final HashMap<UUID, Server> rPlayerLinkS = new HashMap<UUID, Server>();
|
||||
public final HashMap<UUID, Proxy> rPlayerLinkP = new HashMap<UUID, Proxy>();
|
||||
public final HashMap<UUID, RemotePlayer> rPlayers = new HashMap<UUID, RemotePlayer>();
|
||||
private final HashMap<UUID, List<ServerInfo>> fallbackLimbo = new HashMap<UUID, List<ServerInfo>>();
|
||||
|
||||
public final PrintStream out;
|
||||
@ -79,7 +82,7 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
public SubServer sudo = null;
|
||||
public static final Version version = Version.fromString("2.16.1a");
|
||||
|
||||
public Proxy redis = null;
|
||||
public final Proxy mProxy;
|
||||
public boolean canSudo = false;
|
||||
public final boolean isPatched;
|
||||
public final boolean isGalaxi;
|
||||
@ -224,6 +227,8 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
}
|
||||
}, TimeUnit.DAYS.toMillis(7), TimeUnit.DAYS.toMillis(7));
|
||||
|
||||
mProxy = new Proxy("(master)");
|
||||
|
||||
api.addHostDriver(net.ME1312.SubServers.Bungee.Host.Internal.InternalHost.class, "virtual");
|
||||
api.addHostDriver(net.ME1312.SubServers.Bungee.Host.External.ExternalHost.class, "network");
|
||||
|
||||
@ -259,7 +264,6 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void startListeners() {
|
||||
try {
|
||||
if (getPluginManager().getPlugin("RedisBungee") != null) redis = Util.getDespiteException(() -> new Proxy((String) redis("getServerId")), null);
|
||||
reload();
|
||||
|
||||
if (UPnP.isUPnPAvailable()) {
|
||||
@ -313,34 +317,6 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
Util.isException(subdata::waitFor);
|
||||
subdata = null;
|
||||
}
|
||||
int proxies = 1;
|
||||
if (redis != null) {
|
||||
try {
|
||||
boolean first = true;
|
||||
String master = (String) redis("getServerId");
|
||||
if (!master.equals(redis.getName())) redis = new Proxy(master);
|
||||
if (!redis.getDisplayName().equals("(master)")) redis.setDisplayName("(master)");
|
||||
for (String name : (List<String>) redis("getAllServers")) {
|
||||
if (!ukeys.contains(name.toLowerCase()) && !master.equals(name)) try {
|
||||
if (first) Logger.get("SubServers").info(((status)?"Rel":"L")+"oading Proxies...");
|
||||
first = false;
|
||||
Proxy proxy = this.proxies.get(name.toLowerCase());
|
||||
if (proxy == null) {
|
||||
proxy = new Proxy(name);
|
||||
getPluginManager().callEvent(new SubAddProxyEvent(proxy));
|
||||
this.proxies.put(name.toLowerCase(), proxy);
|
||||
}
|
||||
ukeys.add(name.toLowerCase());
|
||||
proxies++;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
ukeys.clear();
|
||||
|
||||
int hosts = 0;
|
||||
Logger.get("SubServers").info(((status)?"Rel":"L")+"oading Hosts...");
|
||||
@ -619,7 +595,7 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
}
|
||||
|
||||
reloading = false;
|
||||
Logger.get("SubServers").info(((plugins > 0)?plugins+" Plugin"+((plugins == 1)?"":"s")+", ":"") + ((proxies > 1)?proxies+" Proxies, ":"") + hosts + " Host"+((hosts == 1)?"":"s")+", " + servers + " Server"+((servers == 1)?"":"s")+", and " + subservers + " SubServer"+((subservers == 1)?"":"s")+" "+((status)?"re":"")+"loaded in " + new DecimalFormat("0.000").format((Calendar.getInstance().getTime().getTime() - begin) / 1000D) + "s");
|
||||
Logger.get("SubServers").info(((plugins > 0)?plugins+" Plugin"+((plugins == 1)?"":"s")+", ":"") + hosts + " Host"+((hosts == 1)?"":"s")+", " + servers + " Server"+((servers == 1)?"":"s")+", and " + subservers + " SubServer"+((subservers == 1)?"":"s")+" "+((status)?"re":"")+"loaded in " + new DecimalFormat("0.000").format((Calendar.getInstance().getTime().getTime() - begin) / 1000D) + "s");
|
||||
|
||||
long scd = TimeUnit.SECONDS.toMillis(this.servers.get().getMap("Settings").getLong("Run-On-Launch-Timeout", 0L));
|
||||
if (autorun.size() > 0) for (Host host : api.getHosts().values()) {
|
||||
@ -745,6 +721,10 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
for (ListenerInfo listener : getConfig().getListeners()) {
|
||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
|
||||
}
|
||||
|
||||
rPlayerLinkS.clear();
|
||||
rPlayerLinkP.clear();
|
||||
rPlayers.clear();
|
||||
}
|
||||
|
||||
String getNewSignature() {
|
||||
@ -762,30 +742,6 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
return (result.length() == 0) ? DIGITS.substring(0, 1) : result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference a RedisBungee method via reflection
|
||||
*
|
||||
* @param method Method to reference
|
||||
* @param args Method arguments
|
||||
* @return Method Response
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object redis(String method, NamedContainer<Class<?>, ?>... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
if (getPluginManager().getPlugin("RedisBungee") != null) {
|
||||
Object api = getPluginManager().getPlugin("RedisBungee").getClass().getMethod("getApi").invoke(null);
|
||||
Class<?>[] classargs = new Class<?>[args.length];
|
||||
Object[] objargs = new Object[args.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
classargs[i] = args[i].name();
|
||||
objargs[i] = args[i].get();
|
||||
if (!classargs[i].isPrimitive() && !classargs[i].isInstance(objargs[i])) throw new ClassCastException(classargs[i].getCanonicalName() + " != " + objargs[i].getClass().getCanonicalName());
|
||||
}
|
||||
return api.getClass().getMethod(method, classargs).invoke(api, objargs);
|
||||
} else {
|
||||
throw new IllegalStateException("RedisBungee is not installed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Further override BungeeCord's signature when patched into the same jar
|
||||
*
|
||||
@ -887,7 +843,6 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void validate(ServerConnectEvent e) {
|
||||
Map<String, ServerInfo> servers = new TreeMap<String, ServerInfo>(api.getServers());
|
||||
@ -928,6 +883,19 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void setPlayer(ServerConnectedEvent e) {
|
||||
RemotePlayer player = new RemotePlayer(e.getPlayer().getName(), e.getPlayer().getUniqueId(), mProxy, (e.getServer().getInfo() instanceof Server)?(Server) e.getServer().getInfo():null, e.getPlayer().getAddress());
|
||||
rPlayers.put(player.getUniqueId(), player);
|
||||
rPlayerLinkP.put(player.getUniqueId(), player.getProxy());
|
||||
if (player.getServer() != null) rPlayerLinkS.put(player.getUniqueId(), player.getServer());
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
|
||||
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(mProxy.getName(), true, player));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void fallback(ServerKickEvent e) {
|
||||
@ -969,9 +937,18 @@ public final class SubProxy extends BungeeCord implements Listener {
|
||||
}, 1000);
|
||||
}
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void resetLimbo(PlayerDisconnectEvent e) {
|
||||
public void resetPlayer(PlayerDisconnectEvent e) {
|
||||
fallbackLimbo.remove(e.getPlayer().getUniqueId());
|
||||
SubCommand.players.remove(e.getPlayer().getUniqueId());
|
||||
|
||||
if (rPlayers.containsKey(e.getPlayer().getUniqueId())) {
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
|
||||
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(mProxy.getName(), false, rPlayers.get(e.getPlayer().getUniqueId())));
|
||||
}
|
||||
rPlayerLinkS.remove(e.getPlayer().getUniqueId());
|
||||
rPlayerLinkP.remove(e.getPlayer().getUniqueId());
|
||||
rPlayers.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
|
@ -48,7 +48,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>20w30a</version>
|
||||
<version>20w30b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
@ -294,9 +294,11 @@ public class BungeeChat {
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
if (proxymaster != null) {
|
||||
hover = new TextComponent('\n' + proxymaster.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
if (!proxymaster.getName().equals(proxymaster.getDisplayName())) {
|
||||
hover = new TextComponent('\n' + proxymaster.getDisplayName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master"));
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxymaster.getPlayers().size())) + ChatColor.RESET);
|
||||
@ -311,17 +313,7 @@ public class BungeeChat {
|
||||
hoverm = new LinkedList<TextComponent>();
|
||||
message = new TextComponent(proxy.getDisplayName());
|
||||
hover = new TextComponent(proxy.getDisplayName());
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message.setColor(ChatColor.GREEN);
|
||||
hover.setColor(ChatColor.GREEN);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + proxy.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
}
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())));
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
if (proxy.getSubData()[0] != null) {
|
||||
message.setColor(ChatColor.AQUA);
|
||||
hover.setColor(ChatColor.AQUA);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
@ -329,20 +321,6 @@ public class BungeeChat {
|
||||
hover = new TextComponent('\n' + proxy.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
}
|
||||
if (proxymaster != null) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-SubData"));
|
||||
}
|
||||
} else if (proxy.isRedis()) {
|
||||
message.setColor(ChatColor.WHITE);
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover = new TextComponent('\n' + proxy.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis"));
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())));
|
||||
} else {
|
||||
|
@ -404,9 +404,6 @@ public class PlaceholderImpl extends PlaceholderExpansion implements Taskable, C
|
||||
case "proxy.type": {
|
||||
return defaults(responses, "Master Proxy", "Proxy") [((proxy.isMaster())?0:1)];
|
||||
}
|
||||
case "proxy.redis": {
|
||||
return defaults(responses, ChatColor.GREEN+"Available", ChatColor.RED+"Unavailable") [(proxy.isRedis())?0:1];
|
||||
}
|
||||
case "proxy.players": {
|
||||
return Integer.toString(proxy.getPlayers().size());
|
||||
}
|
||||
|
@ -106,15 +106,6 @@ public class Proxy {
|
||||
return raw.getRawString("display");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is connected to RedisBungee's server
|
||||
*
|
||||
* @return Redis Status
|
||||
*/
|
||||
public boolean isRedis() {
|
||||
return raw.getBoolean("redis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is the Master Proxy
|
||||
*
|
||||
|
@ -9,6 +9,7 @@ import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
|
||||
public class RemotePlayer {
|
||||
@ -69,8 +70,8 @@ public class RemotePlayer {
|
||||
*
|
||||
* @return the remote address
|
||||
*/
|
||||
public InetAddress getAddress() {
|
||||
return Util.getDespiteException(() -> InetAddress.getByName(raw.getRawString("address")), null);
|
||||
public InetSocketAddress getAddress() {
|
||||
return new InetSocketAddress(raw.getRawString("address").split(":")[0], Integer.parseInt(raw.getRawString("address").split(":")[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,12 +175,8 @@ public final class SubCommand extends BukkitCommand {
|
||||
message = " (master)";
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message += div;
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
if (proxy.getSubData()[0] != null) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (proxy.isRedis()) {
|
||||
message += ChatColor.WHITE;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
@ -201,7 +197,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
if (player.getProxy() != null) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Proxy") + ChatColor.WHITE + player.getProxy());
|
||||
if (player.getServer() != null) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Server") + ChatColor.WHITE + player.getServer());
|
||||
if (player.getAddress() != null && plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.WHITE + player.getAddress().getHostAddress());
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.WHITE + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort());
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "UUID") + ChatColor.AQUA + player.getUniqueId());
|
||||
} else {
|
||||
if (type == null) {
|
||||
@ -291,8 +287,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name") + ChatColor.WHITE + proxy.getName());
|
||||
if (!proxy.isMaster()) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
else if (!proxy.getDisplayName().toLowerCase().contains("master")) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Type") + ChatColor.WHITE + "Master");
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis") + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + proxy.getSignature());
|
||||
} else {
|
||||
if (type == null) {
|
||||
|
@ -30,7 +30,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>20w30a</version>
|
||||
<version>20w30b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
@ -106,15 +106,6 @@ public class Proxy {
|
||||
return raw.getRawString("display");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is connected to RedisBungee's server
|
||||
*
|
||||
* @return Redis Status
|
||||
*/
|
||||
public boolean isRedis() {
|
||||
return raw.getBoolean("redis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is the Master Proxy
|
||||
*
|
||||
|
@ -9,6 +9,7 @@ import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
@ -71,8 +72,8 @@ public class RemotePlayer {
|
||||
*
|
||||
* @return the remote address
|
||||
*/
|
||||
public InetAddress getAddress() {
|
||||
return Util.getDespiteException(() -> InetAddress.getByName(raw.getRawString("address")), null);
|
||||
public InetSocketAddress getAddress() {
|
||||
return new InetSocketAddress(raw.getRawString("address").split(":")[0], Integer.parseInt(raw.getRawString("address").split(":")[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -426,8 +426,10 @@ public final class SubCommand implements CommandExecutor {
|
||||
message.color(TextColors.GRAY);
|
||||
hover.color(TextColors.GRAY);
|
||||
if (proxymaster != null) {
|
||||
if (!proxymaster.getName().equals(proxymaster.getDisplayName())) {
|
||||
hover.append(Text.builder('\n' + proxymaster.getDisplayName()).color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(
|
||||
Text.builder('\n' + proxymaster.getName()).color(TextColors.GRAY).build(),
|
||||
ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")),
|
||||
ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxymaster.getPlayers().size())))
|
||||
);
|
||||
@ -437,32 +439,13 @@ public final class SubCommand implements CommandExecutor {
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message = Text.builder(proxy.getDisplayName());
|
||||
hover = Text.builder(proxy.getDisplayName());
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message.color(TextColors.GREEN);
|
||||
hover.color(TextColors.GREEN);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size()))));
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
if (proxy.getSubData()[0] != null) {
|
||||
message.color(TextColors.AQUA);
|
||||
hover.color(TextColors.AQUA);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
||||
}
|
||||
if (proxymaster != null) {
|
||||
hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-SubData")));
|
||||
}
|
||||
} else if (proxy.isRedis()) {
|
||||
message.color(TextColors.WHITE);
|
||||
hover.color(TextColors.WHITE);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(
|
||||
ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis")),
|
||||
ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())))
|
||||
);
|
||||
hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size()))));
|
||||
} else {
|
||||
message.color(TextColors.RED);
|
||||
hover.color(TextColors.RED);
|
||||
@ -507,7 +490,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (player.getProxy() != null) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Proxy")).toBuilder().append(Text.builder(player.getProxy()).color(TextColors.WHITE).build()).build());
|
||||
if (player.getServer() != null) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Server")).toBuilder().append(Text.builder(player.getServer()).color(TextColors.WHITE).build()).build());
|
||||
if (player.getAddress() != null && plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(player.getAddress().getHostAddress()).color(TextColors.WHITE).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort()).color(TextColors.WHITE).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "UUID")).toBuilder().append(Text.builder(player.getUniqueId().toString()).color(TextColors.AQUA).build()).build());
|
||||
} else {
|
||||
if (type == null) {
|
||||
@ -597,8 +580,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(proxy.getName()).color(TextColors.WHITE).build()).build());
|
||||
if (!proxy.isMaster()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((proxy.getSubData()[0] != null)?"yes":"no").color((proxy.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((proxy.getSubData().length > 1)?" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):"").color(TextColors.AQUA).build()).build());
|
||||
else if (!proxy.getDisplayName().toLowerCase().contains("master")) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Type")).toBuilder().append(Text.builder("Master").color(TextColors.WHITE).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis")).toBuilder().append(Text.builder(((proxy.isRedis())?"":"un") + "available").color((proxy.isRedis())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||
if (proxy.isRedis()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(proxy.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(proxy.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature")).toBuilder().append(Text.builder(proxy.getSignature()).color(TextColors.AQUA).build()).build());
|
||||
} else {
|
||||
if (type == null) {
|
||||
|
@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>20w30a</version>
|
||||
<version>20w30b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
@ -82,15 +82,6 @@ public class Proxy {
|
||||
return raw.getRawString("display");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is connected to RedisBungee's server
|
||||
*
|
||||
* @return Redis Status
|
||||
*/
|
||||
public boolean isRedis() {
|
||||
return raw.getBoolean("redis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is the Master Proxy
|
||||
*
|
||||
|
@ -9,6 +9,7 @@ import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
@ -71,8 +72,8 @@ public class RemotePlayer {
|
||||
*
|
||||
* @return the remote address
|
||||
*/
|
||||
public InetAddress getAddress() {
|
||||
return Util.getDespiteException(() -> InetAddress.getByName(raw.getRawString("address")), null);
|
||||
public InetSocketAddress getAddress() {
|
||||
return new InetSocketAddress(raw.getRawString("address").split(":")[0], Integer.parseInt(raw.getRawString("address").split(":")[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,12 +159,8 @@ public class SubCommand {
|
||||
message = " (master)";
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message += div;
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message += TextColor.GREEN;
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
if (proxy.getSubData()[0] != null) {
|
||||
message += TextColor.AQUA;
|
||||
} else if (proxy.isRedis()) {
|
||||
message += TextColor.WHITE;
|
||||
} else {
|
||||
message += TextColor.RED;
|
||||
}
|
||||
@ -195,7 +191,7 @@ public class SubCommand {
|
||||
sender.sendMessage("Info on player: " + TextColor.WHITE + player.getName());
|
||||
if (player.getProxy() != null) sender.sendMessage(" -> Proxy: " + TextColor.WHITE + player.getProxy());
|
||||
if (player.getServer() != null) sender.sendMessage(" -> Server: " + TextColor.WHITE + player.getServer());
|
||||
if (player.getAddress() != null) sender.sendMessage(" -> Address: " + TextColor.WHITE + player.getAddress().getHostAddress());
|
||||
if (player.getAddress() != null) sender.sendMessage(" -> Address: " + TextColor.WHITE + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort());
|
||||
sender.sendMessage(" -> UUID: " + TextColor.AQUA + player.getUniqueId());
|
||||
} else {
|
||||
if (type == null) {
|
||||
@ -284,8 +280,7 @@ public class SubCommand {
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + proxy.getName());
|
||||
if (!proxy.isMaster()) sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?TextColor.GREEN+"yes"+((proxy.getSubData().length > 1)?TextColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
else if (!proxy.getDisplayName().toLowerCase().contains("master")) sender.sendMessage(" -> Type: " + TextColor.WHITE + "Master");
|
||||
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?TextColor.GREEN:TextColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + TextColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Players: " + TextColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Signature: " + TextColor.AQUA + proxy.getSignature());
|
||||
} else {
|
||||
if (type == null) {
|
||||
|
@ -30,14 +30,14 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>20w30a</version>
|
||||
<version>20w30b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>20w30a</version>
|
||||
<version>20w30b</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -22,6 +22,8 @@ import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Library.ConfigUpdater;
|
||||
import net.ME1312.SubServers.Sync.Network.API.RemotePlayer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketExSyncPlayer;
|
||||
import net.ME1312.SubServers.Sync.Network.SubProtocol;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerImpl;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerImpl;
|
||||
@ -54,12 +56,14 @@ public final class ExProxy extends BungeeCord implements Listener {
|
||||
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
public final Map<String, ServerImpl> servers = new TreeMap<String, ServerImpl>();
|
||||
public final HashMap<UUID, ServerImpl> rPlayerLinkS = new HashMap<UUID, ServerImpl>();
|
||||
public final HashMap<UUID, String> rPlayerLinkP = new HashMap<UUID, String>();
|
||||
public final HashMap<UUID, RemotePlayer> rPlayers = new HashMap<UUID, RemotePlayer>();
|
||||
private final HashMap<UUID, List<ServerInfo>> fallbackLimbo = new HashMap<UUID, List<ServerInfo>>();
|
||||
|
||||
public final PrintStream out;
|
||||
public final UniversalFile dir = new UniversalFile(new File(System.getProperty("user.dir")));
|
||||
public YAMLConfig config;
|
||||
public boolean redis = false;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
public SubProtocol subprotocol;
|
||||
public static final Version version = Version.fromString("2.16.1a");
|
||||
@ -115,7 +119,6 @@ public final class ExProxy extends BungeeCord implements Listener {
|
||||
public void startListeners() {
|
||||
try {
|
||||
resetDate = Calendar.getInstance().getTime().getTime();
|
||||
redis = getPluginManager().getPlugin("RedisBungee") != null;
|
||||
ConfigUpdater.updateConfig(new UniversalFile(dir, "SubServers:sync.yml"));
|
||||
config.reload();
|
||||
|
||||
@ -233,30 +236,6 @@ public final class ExProxy extends BungeeCord implements Listener {
|
||||
}, 0, TimeUnit.DAYS.toMillis(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference a RedisBungee method via reflection
|
||||
*
|
||||
* @param method Method to reference
|
||||
* @param args Method arguments
|
||||
* @return Method Response
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object redis(String method, NamedContainer<Class<?>, ?>... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
if (redis) {
|
||||
Object api = getPluginManager().getPlugin("RedisBungee").getClass().getMethod("getApi").invoke(null);
|
||||
Class<?>[] classargs = new Class<?>[args.length];
|
||||
Object[] objargs = new Object[args.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
classargs[i] = args[i].name();
|
||||
objargs[i] = args[i].get();
|
||||
if (!classargs[i].isInstance(objargs[i])) throw new ClassCastException(classargs[i].getCanonicalName() + " != " + objargs[i].getClass().getCanonicalName());
|
||||
}
|
||||
return api.getClass().getMethod(method, classargs).invoke(api, objargs);
|
||||
} else {
|
||||
throw new IllegalStateException("RedisBungee is not installed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Further override BungeeCord's signature when patched into the same jar
|
||||
*
|
||||
@ -384,7 +363,6 @@ public final class ExProxy extends BungeeCord implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void validate(ServerConnectEvent e) {
|
||||
Map<String, ServerInfo> servers = new TreeMap<String, ServerInfo>(this.servers);
|
||||
@ -425,6 +403,20 @@ public final class ExProxy extends BungeeCord implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void setPlayer(ServerConnectedEvent e) {
|
||||
ObjectMap<String> raw = RemotePlayer.translate(e.getPlayer());
|
||||
raw.set("server", e.getServer().getInfo().getName());
|
||||
RemotePlayer player = new RemotePlayer(raw);
|
||||
rPlayers.put(player.getUniqueId(), player);
|
||||
rPlayerLinkP.put(player.getUniqueId(), player.getProxy());
|
||||
if (e.getServer().getInfo() instanceof ServerImpl) rPlayerLinkS.put(player.getUniqueId(), (ServerImpl) e.getServer().getInfo());
|
||||
if (api.getSubDataNetwork()[0] != null) {
|
||||
((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(new PacketExSyncPlayer(true, player));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void fallback(ServerKickEvent e) {
|
||||
@ -466,9 +458,18 @@ public final class ExProxy extends BungeeCord implements Listener {
|
||||
}, 1000);
|
||||
}
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void resetLimbo(PlayerDisconnectEvent e) {
|
||||
public void resetPlayer(PlayerDisconnectEvent e) {
|
||||
fallbackLimbo.remove(e.getPlayer().getUniqueId());
|
||||
SubCommand.permitted.remove(e.getPlayer().getUniqueId());
|
||||
|
||||
if (rPlayers.containsKey(e.getPlayer().getUniqueId())) {
|
||||
if (api.getSubDataNetwork()[0] != null) {
|
||||
((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(new PacketExSyncPlayer(false, rPlayers.get(e.getPlayer().getUniqueId())));
|
||||
}
|
||||
rPlayerLinkS.remove(e.getPlayer().getUniqueId());
|
||||
rPlayerLinkP.remove(e.getPlayer().getUniqueId());
|
||||
rPlayers.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -82,15 +82,6 @@ public class Proxy {
|
||||
return raw.getRawString("display");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is connected to RedisBungee's server
|
||||
*
|
||||
* @return Redis Status
|
||||
*/
|
||||
public boolean isRedis() {
|
||||
return raw.getBoolean("redis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the proxy is the Master Proxy
|
||||
*
|
||||
|
@ -6,9 +6,11 @@ import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadPlayerInfo;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
@ -19,6 +21,32 @@ public class RemotePlayer {
|
||||
private Server server = null;
|
||||
long timestamp;
|
||||
|
||||
/**
|
||||
* Convert a Local Player to a Raw representation of a Remote Player
|
||||
*
|
||||
* @param player Local Player
|
||||
* @return Raw representation of the Remote Player
|
||||
*/
|
||||
public static ObjectMap<String> translate(ProxiedPlayer player) {
|
||||
ObjectMap<String> raw = new ObjectMap<String>();
|
||||
raw = new ObjectMap<String>();
|
||||
raw.set("name", player.getName());
|
||||
raw.set("id", player.getUniqueId());
|
||||
raw.set("address", player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort());
|
||||
if (player.getServer() != null) raw.set("server", player.getServer().getInfo().getName());
|
||||
if (SubAPI.getInstance().getName() != null) raw.set("proxy", SubAPI.getInstance().getName());
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Local Player to an API representation of a Remote Player
|
||||
*
|
||||
* @param player Local Player
|
||||
*/
|
||||
public RemotePlayer(ProxiedPlayer player) {
|
||||
this(translate(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an API representation of a Remote Player
|
||||
*
|
||||
@ -71,8 +99,8 @@ public class RemotePlayer {
|
||||
*
|
||||
* @return the remote address
|
||||
*/
|
||||
public InetAddress getAddress() {
|
||||
return Util.getDespiteException(() -> InetAddress.getByName(raw.getRawString("address")), null);
|
||||
public InetSocketAddress getAddress() {
|
||||
return new InetSocketAddress(raw.getRawString("address").split(":")[0], Integer.parseInt(raw.getRawString("address").split(":")[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,90 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataSender;
|
||||
import net.ME1312.SubServers.Sync.Network.API.RemotePlayer;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerImpl;
|
||||
import net.ME1312.SubServers.Sync.ExProxy;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* External Player Sync Packet
|
||||
*/
|
||||
public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExProxy plugin;
|
||||
private boolean mode;
|
||||
private RemotePlayer[] values;
|
||||
|
||||
/**
|
||||
* New PacketExSyncPlayer (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketExSyncPlayer(ExProxy plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExSyncPlayer (Out)
|
||||
*
|
||||
* @param mode Update Mode (true for add, false for remove, null for reset)
|
||||
* @param values RemotePlayers
|
||||
*/
|
||||
public PacketExSyncPlayer(Boolean mode, RemotePlayer... values) {
|
||||
if (Util.isNull(mode)) throw new NullPointerException();
|
||||
this.mode = mode;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataSender client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0001, mode);
|
||||
if (values != null) {
|
||||
ArrayList<ObjectMap<String>> list = new ArrayList<ObjectMap<String>>();
|
||||
for (RemotePlayer value : values) list.add(value.getRaw());
|
||||
data.set(0x0002, list);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void receive(SubDataSender client, ObjectMap<Integer> data) {
|
||||
String proxy = (data.contains(0x0000)?data.getRawString(0x0000).toLowerCase():null);
|
||||
if (data.getBoolean(0x0001) == null) {
|
||||
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, proxy)) {
|
||||
plugin.rPlayerLinkS.remove(id);
|
||||
plugin.rPlayerLinkP.remove(id);
|
||||
plugin.rPlayers.remove(id);
|
||||
}
|
||||
}
|
||||
if (data.getBoolean(0x0001) != Boolean.FALSE) {
|
||||
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
||||
ServerImpl server = (object.getOrDefault("server", null) != null)?plugin.servers.getOrDefault(object.get("server").toString().toLowerCase(), null):null;
|
||||
RemotePlayer player = new RemotePlayer(new ObjectMap<>(object));
|
||||
|
||||
plugin.rPlayers.put(player.getUniqueId(), player);
|
||||
plugin.rPlayerLinkP.put(player.getUniqueId(), proxy);
|
||||
if (server != null) plugin.rPlayerLinkS.put(player.getUniqueId(), server);
|
||||
}
|
||||
} else {
|
||||
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
||||
UUID id = UUID.fromString(object.get("id").toString());
|
||||
plugin.rPlayerLinkS.remove(id);
|
||||
plugin.rPlayerLinkP.remove(id);
|
||||
plugin.rPlayers.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -11,10 +11,13 @@ import net.ME1312.SubData.Client.SubDataProtocol;
|
||||
import net.ME1312.SubServers.Sync.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Sync.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Sync.ExProxy;
|
||||
import net.ME1312.SubServers.Sync.Network.API.RemotePlayer;
|
||||
import net.ME1312.SubServers.Sync.Network.API.Server;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerImpl;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.conf.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -96,10 +99,12 @@ public class SubProtocol extends SubDataProtocol {
|
||||
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
|
||||
//instance.registerPacket(0x0071, PacketInExReset.class);
|
||||
//instance.registerPacket(0x0073, PacketInExReload.class);
|
||||
instance.registerPacket(0x0074, PacketExSyncPlayer.class);
|
||||
|
||||
instance.registerPacket(0x0070, new PacketInExRunEvent(plugin));
|
||||
instance.registerPacket(0x0071, new PacketInExReset());
|
||||
instance.registerPacket(0x0073, new PacketInExUpdateWhitelist(plugin));
|
||||
instance.registerPacket(0x0074, new PacketExSyncPlayer(plugin));
|
||||
}
|
||||
|
||||
return instance;
|
||||
@ -160,7 +165,19 @@ public class SubProtocol extends SubDataProtocol {
|
||||
for (Server server : servers.values()) {
|
||||
plugin.merge(server);
|
||||
}
|
||||
|
||||
plugin.api.getGlobalPlayers(players -> {
|
||||
for (RemotePlayer player : players.values()) {
|
||||
plugin.rPlayers.put(player.getUniqueId(), player);
|
||||
plugin.rPlayerLinkP.put(player.getUniqueId(), player.getProxy().toLowerCase());
|
||||
|
||||
ServerInfo server = plugin.getServerInfo(player.getServer());
|
||||
if (server instanceof ServerImpl)
|
||||
plugin.rPlayerLinkS.put(player.getUniqueId(), (ServerImpl) server);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}));
|
||||
subdata.on.ready(client -> plugin.getPluginManager().callEvent(new SubNetworkConnectEvent((SubDataClient) client)));
|
||||
subdata.on.closed(client -> {
|
||||
|
@ -5,6 +5,8 @@ import net.ME1312.SubData.Client.DataSender;
|
||||
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubData.Client.SubDataSender;
|
||||
import net.ME1312.SubServers.Sync.ExProxy;
|
||||
import net.ME1312.SubServers.Sync.Network.API.RemotePlayer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@ -114,32 +116,18 @@ public class ServerImpl extends BungeeServerInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* See if a player is whitelisted
|
||||
* Get players on this server across all known proxies
|
||||
*
|
||||
* @param player Player
|
||||
* @return Whitelisted Status
|
||||
* @return Remote Player Collection
|
||||
*/
|
||||
public boolean canAccess(CommandSender player) {
|
||||
return (player instanceof ProxiedPlayer && whitelist.contains(((ProxiedPlayer) player).getUniqueId())) || super.canAccess(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
*/
|
||||
public void whitelist(UUID player) {
|
||||
if (Util.isNull(player)) throw new NullPointerException();
|
||||
whitelist.add(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void unwhitelist(UUID player) {
|
||||
whitelist.remove(player);
|
||||
@SuppressWarnings("deprecation")
|
||||
public Collection<RemotePlayer> getGlobalPlayers() {
|
||||
ExProxy plugin = SubAPI.getInstance().getInternals();
|
||||
ArrayList<RemotePlayer> players = new ArrayList<RemotePlayer>();
|
||||
for (UUID id : Util.getBackwards(plugin.rPlayerLinkS, this)) {
|
||||
players.add(plugin.rPlayers.get(id));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,6 +177,35 @@ public class ServerImpl extends BungeeServerInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See if a player is whitelisted
|
||||
*
|
||||
* @param player Player
|
||||
* @return Whitelisted Status
|
||||
*/
|
||||
public boolean canAccess(CommandSender player) {
|
||||
return (player instanceof ProxiedPlayer && whitelist.contains(((ProxiedPlayer) player).getUniqueId())) || super.canAccess(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
*/
|
||||
public void whitelist(UUID player) {
|
||||
if (Util.isNull(player)) throw new NullPointerException();
|
||||
whitelist.add(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void unwhitelist(UUID player) {
|
||||
whitelist.remove(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Signature of this Object
|
||||
*
|
||||
|
@ -72,12 +72,6 @@ public final class SubAPI {
|
||||
public String getName() {
|
||||
if (name != null) {
|
||||
return name;
|
||||
} else if (plugin.redis) {
|
||||
try {
|
||||
return (String) plugin.redis("getServerId");
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -517,7 +511,7 @@ public final class SubAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Master Proxy redis container (null if unavailable)
|
||||
* Get the Master Proxy Container
|
||||
*
|
||||
* @param callback Master Proxy
|
||||
*/
|
||||
@ -540,6 +534,15 @@ public final class SubAPI {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get players on this network across all known proxies (Cached)
|
||||
*
|
||||
* @return Remote Player Collection
|
||||
*/
|
||||
public Map<UUID, RemotePlayer> getGlobalPlayers() {
|
||||
return new HashMap<UUID, RemotePlayer>(plugin.rPlayers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get players on this network across all known proxies
|
||||
*
|
||||
@ -564,6 +567,20 @@ public final class SubAPI {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player on this network by searching across all known proxies (Cached)
|
||||
*
|
||||
* @param name Player name
|
||||
* @return Remote Player
|
||||
*/
|
||||
public RemotePlayer getGlobalPlayer(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
for (RemotePlayer player : getGlobalPlayers().values()) {
|
||||
if (player.getName().equalsIgnoreCase(name)) return player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player on this network by searching across all known proxies
|
||||
*
|
||||
@ -589,6 +606,17 @@ public final class SubAPI {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player on this network by searching across all known proxies (Cached)
|
||||
*
|
||||
* @param id Player UUID
|
||||
* @return Remote Player
|
||||
*/
|
||||
public RemotePlayer getGlobalPlayer(UUID id) {
|
||||
if (Util.isNull(id)) throw new NullPointerException();
|
||||
return getGlobalPlayers().getOrDefault(id, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player on this network by searching across all known proxies
|
||||
*
|
||||
|
@ -204,12 +204,8 @@ public final class SubCommand extends CommandX {
|
||||
message = " (master)";
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message += div;
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
if (proxy.getSubData()[0] != null) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (proxy.isRedis()) {
|
||||
message += ChatColor.WHITE;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
@ -228,7 +224,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > Info on player: " + ChatColor.WHITE + player.getName());
|
||||
if (player.getProxy() != null) sender.sendMessage(" -> Proxy: " + ChatColor.WHITE + player.getProxy());
|
||||
if (player.getServer() != null) sender.sendMessage(" -> Server: " + ChatColor.WHITE + player.getServer());
|
||||
if (player.getAddress() != null) sender.sendMessage(" -> Address: " + ChatColor.WHITE + player.getAddress().getHostAddress());
|
||||
if (player.getAddress() != null) sender.sendMessage(" -> Address: " + ChatColor.WHITE + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort());
|
||||
sender.sendMessage(" -> UUID: " + ChatColor.AQUA + player.getUniqueId());
|
||||
} else {
|
||||
if (type == null) {
|
||||
@ -317,8 +313,7 @@ public final class SubCommand extends CommandX {
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + proxy.getName());
|
||||
if (!proxy.isMaster()) sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
else if (!proxy.getDisplayName().toLowerCase().contains("master")) sender.sendMessage(" -> Type: " + ChatColor.WHITE + "Master");
|
||||
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Players: " + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + proxy.getSignature());
|
||||
} else {
|
||||
if (type == null) {
|
||||
@ -1002,12 +997,7 @@ public final class SubCommand extends CommandX {
|
||||
ReturnRunnable<Collection<String>> getPlayers = () -> {
|
||||
LinkedList<String> names = new LinkedList<String>();
|
||||
for (ProxiedPlayer player : plugin.getPlayers()) names.add(player.getName());
|
||||
if (proxyMasterCache != null)
|
||||
for (NamedContainer<String, UUID> player : proxyMasterCache.getPlayers())
|
||||
if (!names.contains(player.name())) names.add(player.name());
|
||||
for (Proxy proxy : proxyCache.values())
|
||||
for (NamedContainer<String, UUID> player : proxy.getPlayers())
|
||||
if (!names.contains(player.name())) names.add(player.name());
|
||||
for (RemotePlayer player : plugin.api.getGlobalPlayers().values()) if (!names.contains(player.getName())) names.add(player.getName());
|
||||
Collections.sort(names);
|
||||
return names;
|
||||
};
|
||||
@ -1211,16 +1201,14 @@ public final class SubCommand extends CommandX {
|
||||
if (player.getName().toLowerCase().startsWith(last)) list.add(Last + player.getName().substring(last.length()));
|
||||
used.add(player.getUniqueId());
|
||||
}
|
||||
if (plugin.redis) {
|
||||
try {
|
||||
for (UUID id : (Set<UUID>) plugin.redis("getPlayersOnServer", new NamedContainer<>(String.class, ((ProxiedPlayer) sender).getServer().getInfo().getName()))) {
|
||||
if (!used.contains(id)) {
|
||||
String name = (String) plugin.redis("getNameFromUuid", new NamedContainer<>(UUID.class, id), new NamedContainer<>(boolean.class, false));
|
||||
if (name.toLowerCase().startsWith(last)) list.add(Last + name.substring(last.length()));
|
||||
used.add(id);
|
||||
}
|
||||
|
||||
if (((ProxiedPlayer) sender).getServer().getInfo() instanceof ServerImpl) {
|
||||
for (RemotePlayer player : ((ServerImpl) ((ProxiedPlayer) sender).getServer().getInfo()).getGlobalPlayers()) {
|
||||
if (!used.contains(player.getUniqueId())) {
|
||||
if (player.getName().toLowerCase().startsWith(last)) list.add(Last + player.getName().substring(last.length()));
|
||||
used.add(player.getUniqueId());
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
@ -1474,7 +1462,7 @@ public final class SubCommand extends CommandX {
|
||||
if (i != 0) serverm.addExtra(div);
|
||||
TextComponent message = new TextComponent(plugin.api.getLang("SubServers", "Bungee.Server.List").replace("$str$", server.getDisplayName()));
|
||||
try {
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(plugin.api.getLang("SubServers", "Bungee.Server.Hover").replace("$int$", Integer.toString((plugin.redis)?((Set<UUID>)plugin.redis("getPlayersOnServer", new NamedContainer<>(String.class, server.getName()))).size():server.getPlayers().size())))}));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(plugin.api.getLang("SubServers", "Bungee.Server.Hover").replace("$int$", Integer.toString(server.getGlobalPlayers().size())))}));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -1555,15 +1543,7 @@ public final class SubCommand extends CommandX {
|
||||
int players = 0;
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
List<String> playerlist = new ArrayList<String>();
|
||||
if (plugin.redis) {
|
||||
try {
|
||||
for (UUID player : (Set<UUID>) plugin.redis("getPlayersOnServer", new NamedContainer<>(String.class, server.getName()))) playerlist.add((String) plugin.redis("getNameFromUuid", new NamedContainer<>(UUID.class, player)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
for (ProxiedPlayer player : server.getPlayers()) playerlist.add(player.getName());
|
||||
}
|
||||
for (RemotePlayer player : server.getGlobalPlayers()) playerlist.add(player.getName());
|
||||
Collections.sort(playerlist);
|
||||
|
||||
players += playerlist.size();
|
||||
|
Loading…
Reference in New Issue
Block a user