mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Allow targeting multiple RemotePlayers
This commit is contained in:
parent
517074f2b3
commit
7d6396ec1c
@ -12,10 +12,12 @@ import java.util.Map;
|
||||
* BungeeCord Common Layout Class
|
||||
*/
|
||||
public abstract class BungeeCommon extends BungeeCord {
|
||||
private static BungeeCommon instance;
|
||||
final ReturnRunnable<BungeeAPI> api;
|
||||
|
||||
protected BungeeCommon(ReturnRunnable<BungeeAPI> api) throws IOException {
|
||||
this.api = api;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,4 +33,13 @@ public abstract class BungeeCommon extends BungeeCord {
|
||||
* @return Server Map Copy
|
||||
*/
|
||||
public abstract Map<String, ServerInfo> getServersCopy();
|
||||
|
||||
/**
|
||||
* Gets the ProxyServer Common Object
|
||||
*
|
||||
* @return ProxyServer Common
|
||||
*/
|
||||
public static BungeeCommon getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package net.ME1312.SubServers.Bungee.Library.Compatibility;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* RemotePlayer Static Implementation Layout Class
|
||||
*/
|
||||
public abstract class RPSI {
|
||||
protected static RPSI instance;
|
||||
protected RPSI() {
|
||||
if (instance == null) instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param players Players to send to
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
protected abstract void sendMessage(UUID[] players, String[] messages, Callback<Integer> response);
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param players Players to send to
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
protected abstract void sendMessage(UUID[] players, BaseComponent[] messages, Callback<Integer> response);
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
*
|
||||
* @param players Players to send to
|
||||
* @param server Target server
|
||||
* @param response Success Status
|
||||
*/
|
||||
protected abstract void transfer(UUID[] players, String server, Callback<Integer> response);
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to send to
|
||||
* @param reason Disconnect Reason
|
||||
* @param response Success status
|
||||
*/
|
||||
protected abstract void disconnect(UUID[] players, String reason, Callback<Integer> response);
|
||||
}
|
@ -3,15 +3,14 @@ package net.ME1312.SubServers.Bungee.Library.Compatibility;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.ME1312.SubServers.Bungee.Library.Compatibility.RPSI.instance;
|
||||
|
||||
/**
|
||||
* RemotePlayer Layout Class
|
||||
*/
|
||||
@ -66,6 +65,35 @@ public interface RemotePlayer {
|
||||
*/
|
||||
ServerInfo getServer();
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param messages Messages to send
|
||||
*/
|
||||
static void broadcastMessage(String... messages) {
|
||||
broadcastMessage(messages, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
static void broadcastMessage(String message, Callback<Integer> response) {
|
||||
broadcastMessage(new String[]{ message }, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
static void broadcastMessage(String[] messages, Callback<Integer> response) {
|
||||
sendMessage(null, messages, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
@ -91,7 +119,67 @@ public interface RemotePlayer {
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
void sendMessage(String[] messages, Callback<Integer> response);
|
||||
default void sendMessage(String[] messages, Callback<Integer> response) {
|
||||
sendMessage(new UUID[]{ getUniqueId() }, messages, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param messages Messages to send
|
||||
*/
|
||||
static void sendMessage(UUID[] players, String... messages) {
|
||||
sendMessage(players, messages, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
static void sendMessage(UUID[] players, String message, Callback<Integer> response) {
|
||||
sendMessage(players, new String[]{ message }, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
static void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) {
|
||||
instance.sendMessage(players, messages, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param messages Messages to send
|
||||
*/
|
||||
static void broadcastMessage(BaseComponent... messages) {
|
||||
broadcastMessage(messages, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
static void broadcastMessage(BaseComponent message, Callback<Integer> response) {
|
||||
broadcastMessage(new BaseComponent[]{ message }, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
static void broadcastMessage(BaseComponent[] messages, Callback<Integer> response) {
|
||||
sendMessage(null, messages, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
@ -118,7 +206,41 @@ public interface RemotePlayer {
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
void sendMessage(BaseComponent[] messages, Callback<Integer> response);
|
||||
default void sendMessage(BaseComponent[] messages, Callback<Integer> response) {
|
||||
sendMessage(new UUID[]{ getUniqueId() }, messages, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param messages Messages to send
|
||||
*/
|
||||
static void sendMessage(UUID[] players, BaseComponent... messages) {
|
||||
sendMessage(players, messages, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
static void sendMessage(UUID[] players, BaseComponent message, Callback<Integer> response) {
|
||||
sendMessage(players, new BaseComponent[]{ message }, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
static void sendMessage(UUID[] players, BaseComponent[] message, Callback<Integer> response) {
|
||||
instance.sendMessage(players, message, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
@ -135,7 +257,30 @@ public interface RemotePlayer {
|
||||
* @param server Target server
|
||||
* @param response Success status
|
||||
*/
|
||||
void transfer(String server, Callback<Integer> response);
|
||||
default void transfer(String server, Callback<Integer> response) {
|
||||
transfer(new UUID[]{ getUniqueId() }, server, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param server Target server
|
||||
*/
|
||||
static void transfer(UUID[] players, String server) {
|
||||
transfer(players, server, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param server Target server
|
||||
* @param response Success status
|
||||
*/
|
||||
static void transfer(UUID[] players, String server, Callback<Integer> response) {
|
||||
instance.transfer(players, server, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
@ -152,13 +297,36 @@ public interface RemotePlayer {
|
||||
* @param server Target server
|
||||
* @param response Success status
|
||||
*/
|
||||
void transfer(ServerInfo server, Callback<Integer> response);
|
||||
default void transfer(ServerInfo server, Callback<Integer> response) {
|
||||
transfer(new UUID[]{ getUniqueId() }, server, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param server Target server
|
||||
*/
|
||||
static void transfer(UUID[] players, ServerInfo server) {
|
||||
transfer(players, server, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param server Target server
|
||||
* @param response Success status
|
||||
*/
|
||||
static void transfer(UUID[] players, ServerInfo server, Callback<Integer> response) {
|
||||
instance.transfer(players, server.getName(), response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*/
|
||||
default void disconnect() {
|
||||
disconnect(i -> {});
|
||||
disconnect((String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,7 +335,7 @@ public interface RemotePlayer {
|
||||
* @param response Success status
|
||||
*/
|
||||
default void disconnect(Callback<Integer> response) {
|
||||
disconnect(null, response);
|
||||
disconnect((String) null, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -185,5 +353,47 @@ public interface RemotePlayer {
|
||||
* @param reason Disconnect Reason
|
||||
* @param response Success status
|
||||
*/
|
||||
void disconnect(String reason, Callback<Integer> response);
|
||||
default void disconnect(String reason, Callback<Integer> response) {
|
||||
disconnect(new UUID[]{ getUniqueId() }, reason, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to select
|
||||
*/
|
||||
static void disconnect(UUID... players) {
|
||||
disconnect(players, (String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param response Success status
|
||||
*/
|
||||
static void disconnect(UUID[] players, Callback<Integer> response) {
|
||||
disconnect(players, null, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param reason Disconnect Reason
|
||||
*/
|
||||
static void disconnect(UUID[] players, String reason) {
|
||||
disconnect(players, reason, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param reason Disconnect Reason
|
||||
* @param response Success status
|
||||
*/
|
||||
static void disconnect(UUID[] players, String reason, Callback<Integer> response) {
|
||||
instance.disconnect(players, reason, response);
|
||||
}
|
||||
}
|
||||
|
@ -160,8 +160,8 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
|
||||
@Override
|
||||
public SubServer getSubServer(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getSubServers().get(name.toLowerCase());
|
||||
if (Util.isNull(name)) return null;
|
||||
return servers.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,8 +94,8 @@ public class InternalHost extends Host {
|
||||
|
||||
@Override
|
||||
public SubServer getSubServer(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getSubServers().get(name.toLowerCase());
|
||||
if (Util.isNull(name)) return null;
|
||||
return servers.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,15 +1,16 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Container.ContainedPair;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.SubDataSerializable;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExDisconnectPlayer;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExMessagePlayer;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExTransferPlayer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.RPSI;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -17,6 +18,7 @@ import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
@ -78,6 +80,10 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
|
||||
return local;
|
||||
}
|
||||
|
||||
private static ProxiedPlayer get(UUID player) {
|
||||
return ProxyServer.getInstance().getPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
if (local != null) {
|
||||
@ -133,119 +139,29 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
|
||||
return (server == null)? null : server.getName();
|
||||
}
|
||||
|
||||
static {
|
||||
// These overrides provide for the static methods in BungeeCommon
|
||||
new RPSI() {
|
||||
@Override
|
||||
public void sendMessage(String[] messages, Callback<Integer> response) {
|
||||
if (local != null) {
|
||||
local.sendMessages(messages);
|
||||
response.run(0);
|
||||
} else {
|
||||
SubDataClient client = getProxyConnection();
|
||||
if (client != null) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketExMessagePlayer(getUniqueId(), Arrays.asList(messages), null, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
} else response.run(4);
|
||||
}
|
||||
protected void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) {
|
||||
PacketMessagePlayer.run(Arrays.asList(players), new ContainedPair<>(messages, null), null, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(BaseComponent[] messages, Callback<Integer> response) {
|
||||
if (local != null) {
|
||||
local.sendMessage(messages);
|
||||
response.run(0);
|
||||
} else {
|
||||
SubDataClient client = getProxyConnection();
|
||||
if (client != null) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketExMessagePlayer(getUniqueId(), null, Collections.singletonList(ComponentSerializer.toString(messages)), data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
} else response.run(4);
|
||||
}
|
||||
protected void sendMessage(UUID[] players, BaseComponent[] messages, Callback<Integer> response) {
|
||||
PacketMessagePlayer.run(Arrays.asList(players), new ContainedPair<>(null, messages), null, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transfer(String server, Callback<Integer> response) {
|
||||
if (local != null) {
|
||||
Server info = SubAPI.getInstance().getServer(server);
|
||||
if (info != null) {
|
||||
local.connect(info);
|
||||
response.run(0);
|
||||
} else response.run(1);
|
||||
} else {
|
||||
SubDataClient client = getProxyConnection();
|
||||
if (client != null) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketExTransferPlayer(getUniqueId(), server, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
} else response.run(4);
|
||||
}
|
||||
protected void transfer(UUID[] players, String server, Callback<Integer> response) {
|
||||
PacketTransferPlayer.run(Arrays.asList(players), server, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transfer(ServerInfo server, Callback<Integer> response) {
|
||||
if (local != null) {
|
||||
local.connect(server);
|
||||
response.run(0);
|
||||
} else {
|
||||
SubDataClient client = getProxyConnection();
|
||||
if (client != null) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketExTransferPlayer(getUniqueId(), server.getName(), data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
} else response.run(4);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(String reason, Callback<Integer> response) {
|
||||
if (local != null) {
|
||||
if (reason != null) {
|
||||
local.disconnect(reason);
|
||||
} else local.disconnect();
|
||||
response.run(0);
|
||||
} else {
|
||||
SubDataClient client = getProxyConnection();
|
||||
if (client != null) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketExDisconnectPlayer(getUniqueId(), reason, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
} else response.run(4);
|
||||
protected void disconnect(UUID[] players, String reason, Callback<Integer> response) {
|
||||
PacketDisconnectPlayer.run(Arrays.asList(players), reason, response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,33 +1,34 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.AsyncConsolidator;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Container.Container;
|
||||
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.SubProxy;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Disconnect Player Packet
|
||||
*/
|
||||
public class PacketDisconnectPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubProxy plugin;
|
||||
private int response;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDisconnectPlayer (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketDisconnectPlayer(SubProxy plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
public PacketDisconnectPlayer() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,32 +53,50 @@ public class PacketDisconnectPlayer implements PacketObjectIn<Integer>, PacketOb
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
UUID id = data.getUUID(0x0001);
|
||||
run(data.getUUIDList(0x0001), data.contains(0x0002)?data.getRawString(0x0002):null, i -> {
|
||||
client.sendPacket(new PacketDisconnectPlayer(i, tracker));
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void run(List<UUID> ids, String reason, Callback<Integer> callback) {
|
||||
try {
|
||||
Container<Integer> failures = new Container<>(0);
|
||||
HashMap<Proxy, List<UUID>> requests = new HashMap<Proxy, List<UUID>>();
|
||||
for (UUID id : ids) {
|
||||
ProxiedPlayer local;
|
||||
RemotePlayer remote;
|
||||
if ((local = plugin.getPlayer(id)) != null) {
|
||||
if (data.contains(0x0002)) {
|
||||
local.disconnect(data.getRawString(0x0002));
|
||||
if ((local = ProxyServer.getInstance().getPlayer(id)) != null) {
|
||||
if (reason != null) {
|
||||
local.disconnect(reason);
|
||||
} else local.disconnect();
|
||||
} else if ((remote = SubAPI.getInstance().getRemotePlayer(id)) != null && remote.getProxy().getSubData()[0] != null) {
|
||||
Proxy proxy = remote.getProxy();
|
||||
List<UUID> list = requests.getOrDefault(proxy, new ArrayList<>());
|
||||
list.add(id);
|
||||
requests.put(proxy, list);
|
||||
} else {
|
||||
local.disconnect();
|
||||
++failures.value;
|
||||
}
|
||||
client.sendPacket(new PacketDisconnectPlayer(0, tracker));
|
||||
} else if ((remote = plugin.api.getRemotePlayer(id)) != null) {
|
||||
if (remote.getProxy().getSubData()[0] != null) {
|
||||
((SubDataClient) remote.getProxy().getSubData()[0]).sendPacket(new PacketExDisconnectPlayer(remote.getUniqueId(), (data.contains(0x0002)?data.getRawString(0x0002):null), r -> {
|
||||
client.sendPacket(new PacketDisconnectPlayer(r.getInt(0x0001), tracker));
|
||||
}
|
||||
|
||||
if (requests.size() == 0) {
|
||||
callback.run(failures.value);
|
||||
} else {
|
||||
AsyncConsolidator merge = new AsyncConsolidator(() -> {
|
||||
callback.run(failures.value);
|
||||
});
|
||||
for (Map.Entry<Proxy, List<UUID>> entry : requests.entrySet()) {
|
||||
merge.reserve();
|
||||
((SubDataClient) entry.getKey().getSubData()[0]).sendPacket(new PacketExDisconnectPlayer(entry.getValue(), reason, r -> {
|
||||
failures.value += r.getInt(0x0001);
|
||||
merge.release();
|
||||
}));
|
||||
} else {
|
||||
client.sendPacket(new PacketDisconnectPlayer(4, tracker));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketDisconnectPlayer(3, tracker));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketDisconnectPlayer(2, tracker));
|
||||
e.printStackTrace();
|
||||
callback.run(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -15,7 +16,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketExDisconnectPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private List<UUID> players;
|
||||
private String reason;
|
||||
private UUID id;
|
||||
|
||||
@ -27,14 +28,14 @@ public class PacketExDisconnectPlayer implements PacketObjectIn<Integer>, Packet
|
||||
/**
|
||||
* New PacketExDisconnectPlayer (Out)
|
||||
*
|
||||
* @param player Player
|
||||
* @param players Players
|
||||
* @param reason Reason
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExDisconnectPlayer(UUID player, String reason, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(player, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
public PacketExDisconnectPlayer(List<UUID> players, String reason, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(players, callback)) throw new NullPointerException();
|
||||
this.players = players;
|
||||
this.reason = reason;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(id, callback);
|
||||
@ -44,7 +45,7 @@ public class PacketExDisconnectPlayer implements PacketObjectIn<Integer>, Packet
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, id);
|
||||
data.set(0x0001, player);
|
||||
data.set(0x0001, players);
|
||||
if (reason != null) data.set(0x0002, reason);
|
||||
return data;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private List<UUID> players;
|
||||
private List<String> legacy, raw;
|
||||
private UUID id;
|
||||
|
||||
@ -28,15 +28,14 @@ public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObj
|
||||
/**
|
||||
* New PacketExMessagePlayer (Out)
|
||||
*
|
||||
* @param player Player
|
||||
* @param players Players
|
||||
* @param legacy Messages (Legacy)
|
||||
* @param raw Messages (JSON)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExMessagePlayer(UUID player, List<String> legacy, List<String> raw, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(player, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
public PacketExMessagePlayer(List<UUID> players, List<String> legacy, List<String> raw, Callback<ObjectMap<Integer>>... callback) {
|
||||
this.players = players;
|
||||
this.legacy = legacy;
|
||||
this.raw = raw;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
@ -47,7 +46,7 @@ public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObj
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, id);
|
||||
data.set(0x0001, player);
|
||||
if (players != null) data.set(0x0001, players);
|
||||
if (legacy != null) data.set(0x0002, legacy);
|
||||
if (raw != null) data.set(0x0003, raw);
|
||||
return data;
|
||||
|
@ -8,6 +8,7 @@ import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -15,7 +16,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketExTransferPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private List<UUID> players;
|
||||
private String server;
|
||||
private UUID id;
|
||||
|
||||
@ -27,14 +28,14 @@ public class PacketExTransferPlayer implements PacketObjectIn<Integer>, PacketOb
|
||||
/**
|
||||
* New PacketExTransferPlayer (Out)
|
||||
*
|
||||
* @param player Player
|
||||
* @param players Players
|
||||
* @param server Server
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExTransferPlayer(UUID player, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(player, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
public PacketExTransferPlayer(List<UUID> players, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(players, server, callback)) throw new NullPointerException();
|
||||
this.players = players;
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(id, callback);
|
||||
@ -44,8 +45,8 @@ public class PacketExTransferPlayer implements PacketObjectIn<Integer>, PacketOb
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, id);
|
||||
data.set(0x0001, player);
|
||||
if (server != null) data.set(0x0002, server);
|
||||
data.set(0x0001, players);
|
||||
data.set(0x0002, server);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -1,38 +1,38 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.AsyncConsolidator;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Container.ContainedPair;
|
||||
import net.ME1312.Galaxi.Library.Container.Container;
|
||||
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.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubProxy;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Message Player Packet
|
||||
*/
|
||||
public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubProxy plugin;
|
||||
private int response;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketMessagePlayer (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketMessagePlayer(SubProxy plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
public PacketMessagePlayer() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,40 +54,91 @@ public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjec
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
UUID id = data.getUUID(0x0001);
|
||||
run(data.contains(0x0001)?data.getUUIDList(0x0001):null, null, data, i -> {
|
||||
client.sendPacket(new PacketMessagePlayer(i, tracker));
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void run(List<UUID> ids, ContainedPair<String[], BaseComponent[]> message, ObjectMap<Integer> data, Callback<Integer> callback) {
|
||||
try {
|
||||
Container<Integer> failures = new Container<>(0);
|
||||
HashMap<Proxy, List<UUID>> requests = new HashMap<Proxy, List<UUID>>();
|
||||
if (ids == null || ids.size() == 0) {
|
||||
if (ProxyServer.getInstance().getPlayers().size() > 0) {
|
||||
if (message == null) message = parseMessage(data);
|
||||
|
||||
if (message.key != null) for (String s : message.key)
|
||||
ProxyServer.getInstance().broadcast(s);
|
||||
if (message.value != null)
|
||||
ProxyServer.getInstance().broadcast(message.value);
|
||||
}
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) {
|
||||
if (proxy.getPlayers().size() > 0) requests.put(proxy, null);
|
||||
}
|
||||
} else {
|
||||
for (UUID id : ids) {
|
||||
ProxiedPlayer local;
|
||||
RemotePlayer remote;
|
||||
if ((local = plugin.getPlayer(id)) != null) {
|
||||
if ((local = ProxyServer.getInstance().getPlayer(id)) != null) {
|
||||
if (message == null) message = parseMessage(data);
|
||||
if (message.key != null)
|
||||
local.sendMessages(message.key);
|
||||
if (message.value != null)
|
||||
local.sendMessage(message.value);
|
||||
} else if ((remote = SubAPI.getInstance().getRemotePlayer(id)) != null && remote.getProxy().getSubData()[0] != null) {
|
||||
Proxy proxy = remote.getProxy();
|
||||
List<UUID> list = requests.getOrDefault(proxy, new ArrayList<>());
|
||||
list.add(id);
|
||||
requests.put(proxy, list);
|
||||
} else {
|
||||
++failures.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (requests.size() == 0) {
|
||||
callback.run(failures.value);
|
||||
} else {
|
||||
AsyncConsolidator merge = new AsyncConsolidator(() -> {
|
||||
callback.run(failures.value);
|
||||
});
|
||||
List<String> legacy, raw;
|
||||
if (data == null) {
|
||||
legacy = (message.key != null?Arrays.asList(message.key):null);
|
||||
raw = (message.value != null?Collections.singletonList(ComponentSerializer.toString(message.value)):null);
|
||||
} else {
|
||||
legacy = (data.contains(0x0002)?data.getRawStringList(0x0002):null);
|
||||
raw = (data.contains(0x0003)?data.getRawStringList(0x0003):null);
|
||||
}
|
||||
for (Map.Entry<Proxy, List<UUID>> entry : requests.entrySet()) {
|
||||
merge.reserve();
|
||||
((SubDataClient) entry.getKey().getSubData()[0]).sendPacket(new PacketExMessagePlayer(entry.getValue(), legacy, raw, r -> {
|
||||
failures.value += r.getInt(0x0001);
|
||||
merge.release();
|
||||
}));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
callback.run((ids == null || ids.size() == 0)? 1 : ids.size());
|
||||
}
|
||||
}
|
||||
|
||||
private static ContainedPair<String[], BaseComponent[]> parseMessage(ObjectMap<Integer> data) {
|
||||
ContainedPair<String[], BaseComponent[]> value = new ContainedPair<>();
|
||||
if (data.contains(0x0002))
|
||||
local.sendMessages(data.getRawStringList(0x0002).toArray(new String[0]));
|
||||
value.key = data.getRawStringList(0x0002).toArray(new String[0]);
|
||||
if (data.contains(0x0003)) {
|
||||
List<String> messages = data.getRawStringList(0x0003);
|
||||
LinkedList<BaseComponent> components = new LinkedList<BaseComponent>();
|
||||
for (String message : messages) components.addAll(Arrays.asList(ComponentSerializer.parse(message)));
|
||||
local.sendMessage(components.toArray(new BaseComponent[0]));
|
||||
}
|
||||
client.sendPacket(new PacketMessagePlayer(0, tracker));
|
||||
} else if ((remote = plugin.api.getRemotePlayer(id)) != null) {
|
||||
if (remote.getProxy().getSubData()[0] != null) {
|
||||
((SubDataClient) remote.getProxy().getSubData()[0]).sendPacket(new PacketExMessagePlayer(remote.getUniqueId(), (data.contains(0x0002)?data.getRawStringList(0x0002):null), (data.contains(0x0003)?data.getRawStringList(0x0003):null), r -> {
|
||||
client.sendPacket(new PacketMessagePlayer(r.getInt(0x0001), tracker));
|
||||
}));
|
||||
} else {
|
||||
client.sendPacket(new PacketMessagePlayer(4, tracker));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketMessagePlayer(3, tracker));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketMessagePlayer(2, tracker));
|
||||
e.printStackTrace();
|
||||
value.value = components.toArray(new BaseComponent[0]);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,34 +1,34 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.AsyncConsolidator;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Container.Container;
|
||||
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.SubProxy;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Transfer Player Packet
|
||||
*/
|
||||
public class PacketTransferPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubProxy plugin;
|
||||
private int response;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketTransferPlayer (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketTransferPlayer(SubProxy plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
public PacketTransferPlayer() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,33 +53,50 @@ public class PacketTransferPlayer implements PacketObjectIn<Integer>, PacketObje
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
UUID id = data.getUUID(0x0001);
|
||||
run(data.getUUIDList(0x0001), data.getRawString(0x0002), i -> {
|
||||
client.sendPacket(new PacketTransferPlayer(i, tracker));
|
||||
});
|
||||
}
|
||||
|
||||
public static void run(List<UUID> ids, String name, Callback<Integer> callback) {
|
||||
try {
|
||||
Container<Integer> failures = new Container<>(0);
|
||||
HashMap<Proxy, List<UUID>> requests = new HashMap<Proxy, List<UUID>>();
|
||||
Server server = SubAPI.getInstance().getServer(name);
|
||||
for (UUID id : ids) {
|
||||
ProxiedPlayer local;
|
||||
RemotePlayer remote;
|
||||
if ((local = plugin.getPlayer(id)) != null) {
|
||||
Server server;
|
||||
if (data.contains(0x0002) && (server = plugin.api.getServer(data.getRawString(0x0002))) != null) {
|
||||
if ((local = ProxyServer.getInstance().getPlayer(id)) != null) {
|
||||
if (name != null) {
|
||||
local.connect(server);
|
||||
client.sendPacket(new PacketTransferPlayer(0, tracker));
|
||||
} else ++failures.value;
|
||||
} else if ((remote = SubAPI.getInstance().getRemotePlayer(id)) != null && remote.getProxy().getSubData()[0] != null) {
|
||||
Proxy proxy = remote.getProxy();
|
||||
List<UUID> list = requests.getOrDefault(proxy, new ArrayList<>());
|
||||
list.add(id);
|
||||
requests.put(proxy, list);
|
||||
} else {
|
||||
client.sendPacket(new PacketTransferPlayer(1, tracker));
|
||||
++failures.value;
|
||||
}
|
||||
} else if ((remote = plugin.api.getRemotePlayer(id)) != null) {
|
||||
if (remote.getProxy().getSubData()[0] != null) {
|
||||
((SubDataClient) remote.getProxy().getSubData()[0]).sendPacket(new PacketExTransferPlayer(remote.getUniqueId(), (data.contains(0x0002)?data.getRawString(0x0002):null), r -> {
|
||||
client.sendPacket(new PacketTransferPlayer(r.getInt(0x0001), tracker));
|
||||
}
|
||||
|
||||
if (requests.size() == 0) {
|
||||
callback.run(failures.value);
|
||||
} else {
|
||||
AsyncConsolidator merge = new AsyncConsolidator(() -> {
|
||||
callback.run(failures.value);
|
||||
});
|
||||
for (Map.Entry<Proxy, List<UUID>> entry : requests.entrySet()) {
|
||||
merge.reserve();
|
||||
((SubDataClient) entry.getKey().getSubData()[0]).sendPacket(new PacketExTransferPlayer(entry.getValue(), name, r -> {
|
||||
failures.value += r.getInt(0x0001);
|
||||
merge.release();
|
||||
}));
|
||||
} else {
|
||||
client.sendPacket(new PacketTransferPlayer(4, tracker));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketTransferPlayer(3, tracker));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketTransferPlayer(2, tracker));
|
||||
e.printStackTrace();
|
||||
callback.run(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,9 @@ public class SubProtocol extends SubDataProtocol {
|
||||
registerPacket(0x0038, new PacketRemoveServer(plugin));
|
||||
registerPacket(0x0039, new PacketDeleteServer(plugin));
|
||||
//registerPacket(0x003A, new PacketRestoreServer(plugin)); // TODO
|
||||
registerPacket(0x003B, new PacketTransferPlayer(plugin));
|
||||
registerPacket(0x003C, new PacketDisconnectPlayer(plugin));
|
||||
registerPacket(0x003D, new PacketMessagePlayer(plugin));
|
||||
registerPacket(0x003B, new PacketTransferPlayer());
|
||||
registerPacket(0x003C, new PacketDisconnectPlayer());
|
||||
registerPacket(0x003D, new PacketMessagePlayer());
|
||||
|
||||
|
||||
// 50-6F: External Host Packets
|
||||
|
@ -123,8 +123,8 @@ public final class SubAPI implements BungeeAPI {
|
||||
* @return a Host
|
||||
*/
|
||||
public Host getHost(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getHosts().get(name.toLowerCase());
|
||||
if (Util.isNull(name)) return null;
|
||||
return plugin.hosts.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -350,7 +350,7 @@ public final class SubAPI implements BungeeAPI {
|
||||
* @return a Server Group
|
||||
*/
|
||||
public Pair<String, List<Server>> getGroup(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
if (Util.isNull(name)) return null;
|
||||
for (Map.Entry<String, List<Server>> group : getLowercaseGroups().entrySet()) {
|
||||
if (group.getKey().equalsIgnoreCase(name)) return new ContainedPair<>(group.getKey(), group.getValue());
|
||||
}
|
||||
@ -378,8 +378,9 @@ public final class SubAPI implements BungeeAPI {
|
||||
* @return a Server
|
||||
*/
|
||||
public Server getServer(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getServers().get(name.toLowerCase());
|
||||
if (Util.isNull(name)) return null;
|
||||
Server server = plugin.exServers.getOrDefault(name.toLowerCase(), null);
|
||||
return (server == null)? getSubServer(name) : server;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -516,8 +517,13 @@ public final class SubAPI implements BungeeAPI {
|
||||
* @return a SubServer
|
||||
*/
|
||||
public SubServer getSubServer(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getSubServers().get(name.toLowerCase());
|
||||
if (Util.isNull(name)) return null;
|
||||
SubServer server;
|
||||
for (Host host : plugin.hosts.values()) {
|
||||
server = host.getSubServer(name);
|
||||
if (server != null) return server;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -536,8 +542,8 @@ public final class SubAPI implements BungeeAPI {
|
||||
* @return a Proxy
|
||||
*/
|
||||
public Proxy getProxy(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
Proxy proxy = getProxies().getOrDefault(name.toLowerCase(), null);
|
||||
if (Util.isNull(name)) return null;
|
||||
Proxy proxy = plugin.proxies.getOrDefault(name.toLowerCase(), null);
|
||||
if (proxy == null && plugin.mProxy != null && plugin.mProxy.getName().equalsIgnoreCase(name)) proxy = plugin.mProxy;
|
||||
return proxy;
|
||||
}
|
||||
@ -594,7 +600,7 @@ public final class SubAPI implements BungeeAPI {
|
||||
*/
|
||||
public RemotePlayer getRemotePlayer(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
for (RemotePlayer player : getRemotePlayers().values()) {
|
||||
for (RemotePlayer player : plugin.rPlayers.values()) {
|
||||
if (player.getName().equalsIgnoreCase(name)) return player;
|
||||
}
|
||||
return null;
|
||||
@ -608,7 +614,7 @@ public final class SubAPI implements BungeeAPI {
|
||||
*/
|
||||
public RemotePlayer getRemotePlayer(UUID id) {
|
||||
if (Util.isNull(id)) throw new NullPointerException();
|
||||
return getRemotePlayers().getOrDefault(id, null);
|
||||
return plugin.rPlayers.getOrDefault(id, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -620,7 +626,7 @@ public final class SubAPI implements BungeeAPI {
|
||||
*/
|
||||
public void setLang(String channel, String key, String value) {
|
||||
if (Util.isNull(channel, key, value)) throw new NullPointerException();
|
||||
LinkedHashMap<String, String> map = (plugin.exLang.keySet().contains(channel.toLowerCase()))?plugin.exLang.get(channel.toLowerCase()):new LinkedHashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = (plugin.exLang.containsKey(channel.toLowerCase()))?plugin.exLang.get(channel.toLowerCase()):new LinkedHashMap<String, String>();
|
||||
map.put(key, value);
|
||||
plugin.exLang.put(channel.toLowerCase(), map);
|
||||
}
|
||||
@ -641,7 +647,7 @@ public final class SubAPI implements BungeeAPI {
|
||||
* @return Lang Value
|
||||
*/
|
||||
public Map<String, String> getLang(String channel) {
|
||||
if (Util.isNull(channel)) throw new NullPointerException();
|
||||
if (Util.isNull(channel)) return null;
|
||||
return new LinkedHashMap<>(plugin.exLang.get(channel.toLowerCase()));
|
||||
}
|
||||
|
||||
@ -680,7 +686,7 @@ public final class SubAPI implements BungeeAPI {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R> R getObjectBySignature(String signature) {
|
||||
if (Util.isNull(signature)) throw new NullPointerException();
|
||||
return (R) knownSignatures.get(signature);
|
||||
return (R) knownSignatures.getOrDefault(signature, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,6 +110,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
|
||||
this.isPatched = isPatched;
|
||||
|
||||
Logger.get("SubServers").info("Loading SubServers.Bungee v" + version.toString() + " Libraries (for Minecraft " + api.getGameVersion()[api.getGameVersion().length - 1] + ")");
|
||||
Util.isException(() -> new RemotePlayer(null)); // runs <clinit>
|
||||
|
||||
this.out = out;
|
||||
if (!(new UniversalFile(dir, "config.yml").exists())) {
|
||||
@ -914,7 +915,11 @@ public final class SubProxy extends BungeeCommon implements Listener {
|
||||
*/
|
||||
@Override
|
||||
public ServerInfo getServerInfo(String name) {
|
||||
if (!ready) {
|
||||
return getServersCopy().get(name);
|
||||
} else {
|
||||
return api.getServer(name);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
@ -975,7 +980,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
|
||||
ProxiedPlayer p = getPlayer(player.getUniqueId());
|
||||
if (p != null) p.disconnect(new TextComponent(getTranslation("already_connected_proxy")));
|
||||
} else if (player.getProxy().getSubData()[0] != null) {
|
||||
((SubDataClient) player.getProxy().getSubData()[0]).sendPacket(new PacketExDisconnectPlayer(player.getUniqueId(), getTranslation("already_connected_proxy")));
|
||||
((SubDataClient) player.getProxy().getSubData()[0]).sendPacket(new PacketExDisconnectPlayer(Collections.singletonList(player.getUniqueId()), getTranslation("already_connected_proxy")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -189,11 +189,15 @@ public class Host {
|
||||
|
||||
if (players == null) {
|
||||
LinkedList<UUID> ids = new LinkedList<UUID>();
|
||||
for (SubServer server : getSubServers().values()) for (Pair<String, UUID> player : server.getRemotePlayers()) ids.add(player.value());
|
||||
HashMap<UUID, SubServer> servers = new HashMap<UUID, SubServer>();
|
||||
for (SubServer server : getSubServers().values()) for (Pair<String, UUID> player : server.getRemotePlayers()) {
|
||||
ids.add(player.value());
|
||||
servers.put(player.value(), server);
|
||||
}
|
||||
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
|
||||
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
|
||||
for (String player : data.getKeys()) {
|
||||
players.add(new RemotePlayer(data.getMap(player)));
|
||||
players.add(RemotePlayer.st4tic.construct(servers.get(UUID.fromString(player)), data.getMap(player)));
|
||||
}
|
||||
|
||||
this.players = players;
|
||||
|
@ -149,7 +149,7 @@ public class Proxy {
|
||||
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
|
||||
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
|
||||
for (String player : data.getKeys()) {
|
||||
players.add(new RemotePlayer(data.getMap(player)));
|
||||
players.add(RemotePlayer.st4tic.construct(this, data.getMap(player)));
|
||||
}
|
||||
|
||||
this.players = players;
|
||||
|
@ -16,6 +16,7 @@ import java.util.*;
|
||||
* Simplified RemotePlayer Data Class
|
||||
*/
|
||||
public class RemotePlayer {
|
||||
protected static StaticImpl st4tic = new StaticImpl();
|
||||
ObjectMap<String> raw;
|
||||
private Proxy proxy = null;
|
||||
private Server server = null;
|
||||
@ -37,7 +38,7 @@ public class RemotePlayer {
|
||||
* @param client SubData connection
|
||||
* @param raw Raw representation of the Remote Player
|
||||
*/
|
||||
RemotePlayer(DataClient client, ObjectMap<String> raw) {
|
||||
protected RemotePlayer(DataClient client, ObjectMap<String> raw) {
|
||||
this.client = client;
|
||||
load(raw);
|
||||
}
|
||||
@ -167,6 +168,35 @@ public class RemotePlayer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param messages Messages to send
|
||||
*/
|
||||
public static void broadcastMessage(String... messages) {
|
||||
broadcastMessage(messages, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public static void broadcastMessage(String message, Callback<Integer> response) {
|
||||
broadcastMessage(new String[]{ message }, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to all players
|
||||
*
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public static void broadcastMessage(String[] messages, Callback<Integer> response) {
|
||||
sendMessage(null, messages, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
@ -193,16 +223,65 @@ public class RemotePlayer {
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void sendMessage(String[] messages, Callback<Integer> response) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client().sendPacket(new PacketMessagePlayer(getUniqueId(), messages, null, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
st4tic.sendMessage(client(), new UUID[]{ getUniqueId() }, messages, response);
|
||||
}
|
||||
}));
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param messages Messages to send
|
||||
*/
|
||||
public static void sendMessage(UUID[] players, String... messages) {
|
||||
sendMessage(players, messages, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public static void sendMessage(UUID[] players, String message, Callback<Integer> response) {
|
||||
sendMessage(players, new String[]{ message }, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public static void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) {
|
||||
st4tic.sendMessage(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, messages, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends JSON format messages to all players
|
||||
*
|
||||
* @param messages Messages to send
|
||||
*/
|
||||
public static void broadcastRawMessage(String... messages) {
|
||||
broadcastRawMessage(messages, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends JSON format messages to all players
|
||||
*
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public static void broadcastRawMessage(String message, Callback<Integer> response) {
|
||||
broadcastRawMessage(new String[]{ message }, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends JSON format messages to all players
|
||||
*
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public static void broadcastRawMessage(String[] messages, Callback<Integer> response) {
|
||||
sendRawMessage(null, messages, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,20 +306,43 @@ public class RemotePlayer {
|
||||
/**
|
||||
* Sends JSON format messages to this player
|
||||
*
|
||||
* @param messages Messages to send
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void sendRawMessage(String[] messages, Callback<Integer> response) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client().sendPacket(new PacketMessagePlayer(getUniqueId(), null, messages, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
public void sendRawMessage(String[] message, Callback<Integer> response) {
|
||||
st4tic.sendRawMessage(client(), new UUID[]{ getUniqueId() }, message, response);
|
||||
}
|
||||
}));
|
||||
|
||||
/**
|
||||
* Sends JSON format messages to this player
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param messages Messages to send
|
||||
*/
|
||||
public static void sendRawMessage(UUID[] players, String... messages) {
|
||||
sendRawMessage(players, messages, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends JSON format messages to this player
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public static void sendRawMessage(UUID[] players, String message, Callback<Integer> response) {
|
||||
sendRawMessage(players, new String[]{ message }, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends JSON format messages to this player
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param message Message to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
public static void sendRawMessage(UUID[] players, String[] message, Callback<Integer> response) {
|
||||
st4tic.sendRawMessage(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, message, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -259,42 +361,35 @@ public class RemotePlayer {
|
||||
* @param response Success status
|
||||
*/
|
||||
public void transfer(String server, Callback<Integer> response) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client().sendPacket(new PacketTransferPlayer(getUniqueId(), server, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
st4tic.transfer(client(), new UUID[]{ getUniqueId() }, server, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param server Target server
|
||||
*/
|
||||
public void transfer(Server server) {
|
||||
transfer(server, i -> {});
|
||||
public static void transfer(UUID[] players, String server) {
|
||||
transfer(players, server, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param server Target server
|
||||
* @param response Success status
|
||||
*/
|
||||
public void transfer(Server server, Callback<Integer> response) {
|
||||
transfer(server.getName(), response);
|
||||
public static void transfer(UUID[] players, String server, Callback<Integer> response) {
|
||||
st4tic.transfer(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, server, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*/
|
||||
public void disconnect() {
|
||||
disconnect(i -> {});
|
||||
disconnect((String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -303,7 +398,7 @@ public class RemotePlayer {
|
||||
* @param response Success status
|
||||
*/
|
||||
public void disconnect(Callback<Integer> response) {
|
||||
disconnect(null, response);
|
||||
disconnect((String) null, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -322,16 +417,47 @@ public class RemotePlayer {
|
||||
* @param response Success status
|
||||
*/
|
||||
public void disconnect(String reason, Callback<Integer> response) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client().sendPacket(new PacketDisconnectPlayer(getUniqueId(), reason, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
st4tic.disconnect(client(), new UUID[]{ getUniqueId() }, reason, response);
|
||||
}
|
||||
}));
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to select
|
||||
*/
|
||||
public static void disconnect(UUID... players) {
|
||||
disconnect(players, (String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param response Success status
|
||||
*/
|
||||
public static void disconnect(UUID[] players, Callback<Integer> response) {
|
||||
disconnect(players, null, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param reason Disconnect Reason
|
||||
*/
|
||||
public static void disconnect(UUID[] players, String reason) {
|
||||
disconnect(players, reason, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param players Players to select
|
||||
* @param reason Disconnect Reason
|
||||
* @param response Success status
|
||||
*/
|
||||
public static void disconnect(UUID[] players, String reason, Callback<Integer> response) {
|
||||
st4tic.disconnect(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, reason, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -353,11 +479,134 @@ public class RemotePlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw representation of the Server
|
||||
*
|
||||
* @return Raw Server
|
||||
* RemotePlayer Static Implementation Class
|
||||
*/
|
||||
protected static ObjectMap<String> raw(RemotePlayer player) {
|
||||
return player.raw;
|
||||
protected static class StaticImpl {
|
||||
/**
|
||||
* Create an API representation of a Remote Player
|
||||
*
|
||||
* @param raw Raw representation of the Remote Player
|
||||
*/
|
||||
protected final RemotePlayer construct(ObjectMap<String> raw) {
|
||||
return construct((DataClient) null, raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an API representation of a Remote Player
|
||||
*
|
||||
* @param client SubData connection
|
||||
* @param raw Raw representation of the Remote Player
|
||||
*/
|
||||
protected RemotePlayer construct(DataClient client, ObjectMap<String> raw) {
|
||||
return new RemotePlayer(client, raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an API representation of a Remote Player
|
||||
*
|
||||
* @param server Server
|
||||
* @param raw Raw representation of the Remote Player
|
||||
*/
|
||||
final RemotePlayer construct(Server server, ObjectMap<String> raw) {
|
||||
RemotePlayer player = new RemotePlayer(server.client, raw);
|
||||
player.server = server;
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an API representation of a Remote Player
|
||||
*
|
||||
* @param proxy Proxy
|
||||
* @param raw Raw representation of the Remote Player
|
||||
*/
|
||||
final RemotePlayer construct(Proxy proxy, ObjectMap<String> raw) {
|
||||
RemotePlayer player = new RemotePlayer(proxy.client, raw);
|
||||
player.proxy = proxy;
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to this player
|
||||
*
|
||||
* @param client SubData Connection
|
||||
* @param players Players to send to
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
protected void sendMessage(SubDataClient client, UUID[] players, String[] messages, Callback<Integer> response) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketMessagePlayer(players, messages, null, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends JSON format messages to this player
|
||||
*
|
||||
* @param client SubData Connection
|
||||
* @param players Players to send to
|
||||
* @param messages Messages to send
|
||||
* @param response Success Status
|
||||
*/
|
||||
protected void sendRawMessage(SubDataClient client, UUID[] players, String[] messages, Callback<Integer> response) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketMessagePlayer(players, null, messages, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers this player to another server
|
||||
*
|
||||
* @param client SubData Connection
|
||||
* @param players Players to send to
|
||||
* @param server Target server
|
||||
* @param response Success Status
|
||||
*/
|
||||
protected void transfer(SubDataClient client, UUID[] players, String server, Callback<Integer> response) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketTransferPlayer(players, server, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects this player from the network
|
||||
*
|
||||
* @param client SubData Connection
|
||||
* @param players Players to send to
|
||||
* @param reason Disconnect Reason
|
||||
* @param response Success status
|
||||
*/
|
||||
protected void disconnect(SubDataClient client, UUID[] players, String reason, Callback<Integer> response) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
client.sendPacket(new PacketDisconnectPlayer(players, reason, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class Server {
|
||||
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
|
||||
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
|
||||
for (String player : data.getKeys()) {
|
||||
players.add(new RemotePlayer(data.getMap(player)));
|
||||
players.add(RemotePlayer.st4tic.construct(this, data.getMap(player)));
|
||||
}
|
||||
|
||||
this.players = players;
|
||||
|
@ -334,7 +334,7 @@ public final class SimplifiedData {
|
||||
client(client).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
|
||||
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
|
||||
for (String player : data.getKeys()) {
|
||||
players.put(UUID.fromString(player), new RemotePlayer(client, data.getMap(player)));
|
||||
players.put(UUID.fromString(player), RemotePlayer.st4tic.construct(client, data.getMap(player)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -360,7 +360,7 @@ public final class SimplifiedData {
|
||||
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
|
||||
RemotePlayer player = null;
|
||||
if (data.getKeys().size() > 0) {
|
||||
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
player = RemotePlayer.st4tic.construct(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -386,7 +386,7 @@ public final class SimplifiedData {
|
||||
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
|
||||
RemotePlayer player = null;
|
||||
if (data.getKeys().size() > 0) {
|
||||
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
player = RemotePlayer.st4tic.construct(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -64,7 +64,7 @@ public class SubServer extends Server {
|
||||
* @param raw JSON representation of the SubServer
|
||||
*/
|
||||
SubServer(Host host, ObjectMap<String> raw) {
|
||||
super(host.client, raw);
|
||||
this(host.client, raw);
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketDisconnectPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private UUID[] players;
|
||||
private String reason;
|
||||
private UUID id;
|
||||
|
||||
@ -27,14 +27,14 @@ public class PacketDisconnectPlayer implements PacketObjectIn<Integer>, PacketOb
|
||||
/**
|
||||
* New PacketDisconnectPlayer (Out)
|
||||
*
|
||||
* @param player Player
|
||||
* @param players Players
|
||||
* @param reason Reason
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDisconnectPlayer(UUID player, String reason, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(player, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
public PacketDisconnectPlayer(UUID[] players, String reason, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(players, callback)) throw new NullPointerException();
|
||||
this.players = players;
|
||||
this.reason = reason;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(id, callback);
|
||||
@ -44,7 +44,7 @@ public class PacketDisconnectPlayer implements PacketObjectIn<Integer>, PacketOb
|
||||
public ObjectMap<Integer> send(SubDataSender client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, id);
|
||||
data.set(0x0001, player);
|
||||
data.set(0x0001, players);
|
||||
if (reason != null) data.set(0x0002, reason);
|
||||
return data;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private UUID[] players;
|
||||
private String[] legacy, raw;
|
||||
private UUID id;
|
||||
|
||||
@ -27,15 +27,14 @@ public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjec
|
||||
/**
|
||||
* New PacketMessagePlayer (Out)
|
||||
*
|
||||
* @param player Player
|
||||
* @param players Players
|
||||
* @param legacy Messages (Legacy)
|
||||
* @param raw Messages (JSON)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketMessagePlayer(UUID player, String[] legacy, String[] raw, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(player, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
public PacketMessagePlayer(UUID[] players, String[] legacy, String[] raw, Callback<ObjectMap<Integer>>... callback) {
|
||||
this.players = players;
|
||||
this.legacy = legacy;
|
||||
this.raw = raw;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
@ -46,7 +45,7 @@ public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjec
|
||||
public ObjectMap<Integer> send(SubDataSender client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, id);
|
||||
data.set(0x0001, player);
|
||||
if (players != null) data.set(0x0001, players);
|
||||
if (legacy != null) data.set(0x0002, legacy);
|
||||
if (raw != null) data.set(0x0003, raw);
|
||||
return data;
|
||||
|
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketTransferPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private UUID[] players;
|
||||
private String server;
|
||||
private UUID id;
|
||||
|
||||
@ -27,14 +27,14 @@ public class PacketTransferPlayer implements PacketObjectIn<Integer>, PacketObje
|
||||
/**
|
||||
* New PacketTransferPlayer (Out)
|
||||
*
|
||||
* @param player Player
|
||||
* @param players Players
|
||||
* @param server Server
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketTransferPlayer(UUID player, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(player, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
public PacketTransferPlayer(UUID[] players, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(players, server)) throw new NullPointerException();
|
||||
this.players = players;
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(id, callback);
|
||||
@ -44,7 +44,7 @@ public class PacketTransferPlayer implements PacketObjectIn<Integer>, PacketObje
|
||||
public ObjectMap<Integer> send(SubDataSender client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, id);
|
||||
data.set(0x0001, player);
|
||||
data.set(0x0001, players);
|
||||
if (server != null) data.set(0x0002, server);
|
||||
return data;
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ public final class ExProxy extends BungeeCommon implements Listener {
|
||||
this.isPatched = isPatched;
|
||||
|
||||
Logger.get("SubServers").info("Loading SubServers.Sync v" + version.toString() + " Libraries (for Minecraft " + api.getGameVersion()[api.getGameVersion().length - 1] + ")");
|
||||
Util.isException(() -> new CachedPlayer((ProxiedPlayer) null)); // runs <clinit>
|
||||
|
||||
this.out = out;
|
||||
if (!(new UniversalFile(dir, "config.yml").exists())) {
|
||||
@ -478,7 +479,7 @@ public final class ExProxy extends BungeeCommon implements Listener {
|
||||
ProxiedPlayer p = getPlayer(player.getUniqueId());
|
||||
if (p != null) p.disconnect(new TextComponent(getTranslation("already_connected_proxy")));
|
||||
} else {
|
||||
((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(new PacketDisconnectPlayer(player.getUniqueId(), getTranslation("already_connected_proxy")));
|
||||
((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(new PacketDisconnectPlayer(new UUID[]{ player.getUniqueId() }, getTranslation("already_connected_proxy")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,11 @@ 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.ExProxy;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerImpl;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -44,25 +46,26 @@ public class PacketExDisconnectPlayer implements PacketObjectIn<Integer>, Packet
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void receive(SubDataSender client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
List<UUID> ids = data.getUUIDList(0x0001);
|
||||
try {
|
||||
UUID id = data.getUUID(0x0001);
|
||||
|
||||
int failures = 0;
|
||||
for (UUID id : ids) {
|
||||
ProxiedPlayer local;
|
||||
if ((local = plugin.getPlayer(id)) != null) {
|
||||
if (data.contains(0x0002)) {
|
||||
local.disconnect(data.getRawString(0x0002));
|
||||
} else local.disconnect();
|
||||
} else {
|
||||
local.disconnect();
|
||||
++failures;
|
||||
}
|
||||
client.sendPacket(new PacketExDisconnectPlayer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketExDisconnectPlayer(3, tracker));
|
||||
}
|
||||
client.sendPacket(new PacketExDisconnectPlayer(failures, tracker));
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketExDisconnectPlayer(2, tracker));
|
||||
client.sendPacket(new PacketExDisconnectPlayer(ids.size(), tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataSender;
|
||||
import net.ME1312.SubServers.Sync.ExProxy;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
@ -53,25 +54,42 @@ public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObj
|
||||
@Override
|
||||
public void receive(SubDataSender client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
List<UUID> ids = (data.contains(0x0001)?data.getUUIDList(0x0001):null);
|
||||
try {
|
||||
UUID id = data.getUUID(0x0001);
|
||||
String[] legacy = null;
|
||||
BaseComponent[] components = null;
|
||||
|
||||
ProxiedPlayer local;
|
||||
if ((local = plugin.getPlayer(id)) != null) {
|
||||
if (data.contains(0x0002))
|
||||
local.sendMessages(data.getRawStringList(0x0002).toArray(new String[0]));
|
||||
legacy = data.getRawStringList(0x0002).toArray(new String[0]);
|
||||
if (data.contains(0x0003)) {
|
||||
List<String> messages = data.getRawStringList(0x0003);
|
||||
LinkedList<BaseComponent> components = new LinkedList<BaseComponent>();
|
||||
for (String message : messages) components.addAll(Arrays.asList(ComponentSerializer.parse(message)));
|
||||
local.sendMessage(components.toArray(new BaseComponent[0]));
|
||||
LinkedList<BaseComponent> list = new LinkedList<BaseComponent>();
|
||||
for (String message : messages) list.addAll(Arrays.asList(ComponentSerializer.parse(message)));
|
||||
components = list.toArray(new BaseComponent[0]);
|
||||
}
|
||||
client.sendPacket(new PacketExMessagePlayer(0, tracker));
|
||||
|
||||
int failures = 0;
|
||||
if (ids == null || ids.size() == 0) {
|
||||
if (legacy != null) for (String s : legacy)
|
||||
ProxyServer.getInstance().broadcast(s);
|
||||
if (components != null)
|
||||
ProxyServer.getInstance().broadcast(components);
|
||||
} else {
|
||||
client.sendPacket(new PacketExMessagePlayer(3, tracker));
|
||||
for (UUID id : ids) {
|
||||
ProxiedPlayer local;
|
||||
if ((local = ProxyServer.getInstance().getPlayer(id)) != null) {
|
||||
if (legacy != null)
|
||||
local.sendMessages(legacy);
|
||||
if (components != null)
|
||||
local.sendMessage(components);
|
||||
} else {
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
}
|
||||
client.sendPacket(new PacketExMessagePlayer(failures, tracker));
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketExMessagePlayer(2, tracker));
|
||||
client.sendPacket(new PacketExMessagePlayer((ids == null || ids.size() == 0)? 1 : ids.size(), tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -50,27 +50,28 @@ public class PacketExTransferPlayer implements PacketObjectIn<Integer>, PacketOb
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void receive(SubDataSender client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
List<UUID> ids = data.getUUIDList(0x0001);
|
||||
try {
|
||||
UUID id = data.getUUID(0x0001);
|
||||
|
||||
ServerImpl server = plugin.servers.getOrDefault(data.getRawString(0x0002).toLowerCase(), null);
|
||||
if (server != null) {
|
||||
int failures = 0;
|
||||
for (UUID id : ids) {
|
||||
ProxiedPlayer local;
|
||||
if ((local = plugin.getPlayer(id)) != null) {
|
||||
ServerImpl server;
|
||||
if (data.contains(0x0002) && (server = plugin.servers.get(data.getRawString(0x0002).toLowerCase())) != null) {
|
||||
local.connect(server);
|
||||
client.sendPacket(new PacketExTransferPlayer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketExTransferPlayer(1, tracker));
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
client.sendPacket(new PacketExTransferPlayer(failures, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketExTransferPlayer(3, tracker));
|
||||
client.sendPacket(new PacketExTransferPlayer(ids.size(), tracker));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketExTransferPlayer(2, tracker));
|
||||
client.sendPacket(new PacketExTransferPlayer(ids.size(), tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package net.ME1312.SubServers.Sync.Server;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubData.Client.DataClient;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.RPSI;
|
||||
import net.ME1312.SubServers.Client.Common.Network.API.RemotePlayer;
|
||||
import net.ME1312.SubServers.Client.Common.Network.API.Server;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -12,9 +14,7 @@ import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Cached RemotePlayer Data Class
|
||||
@ -47,27 +47,32 @@ public class CachedPlayer extends RemotePlayer implements net.ME1312.SubServers.
|
||||
this(translate(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache a Remote Player
|
||||
*
|
||||
* @param player Remote Player
|
||||
*/
|
||||
public CachedPlayer(RemotePlayer player) {
|
||||
this(raw(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Cached Remote Player
|
||||
*
|
||||
* @param raw Raw representation of the Remote Player
|
||||
*/
|
||||
public CachedPlayer(ObjectMap<String> raw) {
|
||||
super(raw);
|
||||
this(null, raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Cached Remote Player
|
||||
*
|
||||
* @param client SubData connection
|
||||
* @param raw Raw representation of the Remote Player
|
||||
*/
|
||||
CachedPlayer(DataClient client, ObjectMap<String> raw) {
|
||||
super(client, raw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProxiedPlayer get() {
|
||||
return ProxyServer.getInstance().getPlayer(getUniqueId());
|
||||
return get(getUniqueId());
|
||||
}
|
||||
|
||||
private static ProxiedPlayer get(UUID player) {
|
||||
return ProxyServer.getInstance().getPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,78 +81,140 @@ public class CachedPlayer extends RemotePlayer implements net.ME1312.SubServers.
|
||||
return (name == null)? null : ProxyServer.getInstance().getServerInfo(name);
|
||||
}
|
||||
|
||||
// These overrides prevent sending unnecessary packets
|
||||
static {
|
||||
// These overrides provide for the static methods in BungeeCommon
|
||||
new RPSI() {
|
||||
@Override
|
||||
protected void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) {
|
||||
RemotePlayer.sendMessage(players, messages, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String[] messages, Callback<Integer> response) {
|
||||
ProxiedPlayer local = get();
|
||||
protected void sendMessage(UUID[] players, BaseComponent[] messages, Callback<Integer> response) {
|
||||
RemotePlayer.sendRawMessage(players, ComponentSerializer.toString(messages), response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void transfer(UUID[] players, String server, Callback<Integer> response) {
|
||||
RemotePlayer.transfer(players, server, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disconnect(UUID[] players, String reason, Callback<Integer> response) {
|
||||
RemotePlayer.disconnect(players, reason, response);
|
||||
}
|
||||
};
|
||||
// These overrides prevent sending unnecessary packets in ClientCommon
|
||||
st4tic = new StaticImpl() {
|
||||
@Override
|
||||
protected RemotePlayer construct(DataClient client, ObjectMap<String> raw) {
|
||||
return new CachedPlayer(client, raw);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(SubDataClient client, UUID[] players, String[] messages, Callback<Integer> response) {
|
||||
if (players != null && players.length > 0) {
|
||||
ArrayList<UUID> ids = new ArrayList<UUID>();
|
||||
for (UUID id : players) {
|
||||
ProxiedPlayer local = get(id);
|
||||
if (local != null) {
|
||||
local.sendMessages(messages);
|
||||
} else {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (ids.size() == 0) {
|
||||
response.run(0);
|
||||
} else {
|
||||
super.sendMessage(messages, response);
|
||||
super.sendMessage(client, ids.toArray(new UUID[0]), messages, response);
|
||||
}
|
||||
} else {
|
||||
super.sendMessage(client, players, messages, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(BaseComponent[] messages, Callback<Integer> response) {
|
||||
ProxiedPlayer local = get();
|
||||
protected void sendRawMessage(SubDataClient client, UUID[] players, String[] messages, Callback<Integer> response) {
|
||||
if (players != null && players.length > 0) {
|
||||
ArrayList<UUID> ids = new ArrayList<UUID>();
|
||||
BaseComponent[] components = null;
|
||||
for (UUID id : players) {
|
||||
ProxiedPlayer local = get(id);
|
||||
if (local != null) {
|
||||
local.sendMessage(messages);
|
||||
if (components == null) {
|
||||
LinkedList<BaseComponent> list = new LinkedList<BaseComponent>();
|
||||
for (String message : messages) list.addAll(Arrays.asList(ComponentSerializer.parse(message)));
|
||||
components = list.toArray(new BaseComponent[0]);
|
||||
}
|
||||
local.sendMessage(components);
|
||||
} else {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (ids.size() == 0) {
|
||||
response.run(0);
|
||||
} else {
|
||||
super.sendRawMessage(new String[]{ComponentSerializer.toString(messages)}, response);
|
||||
super.sendRawMessage(client, ids.toArray(new UUID[0]), messages, response);
|
||||
}
|
||||
} else {
|
||||
super.sendRawMessage(client, players, messages, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawMessage(String[] messages, Callback<Integer> response) {
|
||||
ProxiedPlayer local = get();
|
||||
if (local != null) {
|
||||
LinkedList<BaseComponent> components = new LinkedList<BaseComponent>();
|
||||
for (String message : messages) components.addAll(Arrays.asList(ComponentSerializer.parse(message)));
|
||||
local.sendMessage(components.toArray(new BaseComponent[0]));
|
||||
response.run(0);
|
||||
} else {
|
||||
super.sendRawMessage(messages, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transfer(String server, Callback<Integer> response) {
|
||||
ProxiedPlayer local = get();
|
||||
if (local != null) {
|
||||
protected void transfer(SubDataClient client, UUID[] players, String server, Callback<Integer> response) {
|
||||
if (players != null && players.length > 0) {
|
||||
ArrayList<UUID> ids = new ArrayList<UUID>();
|
||||
ServerImpl info = SubAPI.getInstance().getInternals().servers.get(server.toLowerCase());
|
||||
int failures = 0;
|
||||
for (UUID id : players) {
|
||||
ProxiedPlayer local = get(id);
|
||||
if (local != null) {
|
||||
if (info != null) {
|
||||
local.connect(info);
|
||||
response.run(0);
|
||||
} else response.run(1);
|
||||
} else ++failures;
|
||||
} else {
|
||||
super.transfer(server, response);
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (ids.size() == 0) {
|
||||
response.run(failures);
|
||||
} else {
|
||||
final int ff = failures;
|
||||
super.transfer(client, ids.toArray(new UUID[0]), server, i -> response.run(i + ff));
|
||||
}
|
||||
} else {
|
||||
super.transfer(client, players, server, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transfer(ServerInfo server, Callback<Integer> response) {
|
||||
ProxiedPlayer local = get();
|
||||
if (local != null) {
|
||||
local.connect(server);
|
||||
response.run(0);
|
||||
} else {
|
||||
super.transfer(server.getName(), response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(String reason, Callback<Integer> response) {
|
||||
ProxiedPlayer local = get();
|
||||
protected void disconnect(SubDataClient client, UUID[] players, String reason, Callback<Integer> response) {
|
||||
if (players != null && players.length > 0) {
|
||||
ArrayList<UUID> ids = new ArrayList<UUID>();
|
||||
for (UUID id : players) {
|
||||
ProxiedPlayer local = get(id);
|
||||
if (local != null) {
|
||||
if (reason != null) {
|
||||
local.disconnect(reason);
|
||||
} else local.disconnect();
|
||||
} else {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (ids.size() == 0) {
|
||||
response.run(0);
|
||||
} else {
|
||||
super.disconnect(reason, response);
|
||||
super.disconnect(client, ids.toArray(new UUID[0]), reason, response);
|
||||
}
|
||||
} else {
|
||||
super.disconnect(client, players, reason, response);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -96,14 +96,6 @@ public final class SubAPI extends ClientAPI implements BungeeAPI {
|
||||
return new HashMap<UUID, CachedPlayer>(plugin.rPlayers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRemotePlayers(Callback<Map<UUID, RemotePlayer>> callback) {
|
||||
super.getRemotePlayers(map -> {
|
||||
map.replaceAll((k, v) -> new CachedPlayer(v));
|
||||
callback.run(map);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player on this network by searching across all known proxies (Cached)
|
||||
*
|
||||
@ -118,11 +110,6 @@ public final class SubAPI extends ClientAPI implements BungeeAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRemotePlayer(String name, Callback<RemotePlayer> callback) {
|
||||
super.getRemotePlayer(name, p -> callback.run(new CachedPlayer(p)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player on this network by searching across all known proxies (Cached)
|
||||
*
|
||||
@ -134,11 +121,6 @@ public final class SubAPI extends ClientAPI implements BungeeAPI {
|
||||
return getRemotePlayers().getOrDefault(id, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRemotePlayer(UUID id, Callback<RemotePlayer> callback) {
|
||||
super.getRemotePlayer(id, p -> callback.run(new CachedPlayer(p)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Network Connections
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user