Remove some unnecessary conversions

This commit is contained in:
ME1312 2021-06-14 00:42:06 -04:00
parent 2c7175e558
commit 517074f2b3
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
8 changed files with 76 additions and 35 deletions

View File

@ -26,6 +26,15 @@ public interface BungeeAPI {
return ((BungeeCommon) ProxyServer.getInstance()).api.run(); return ((BungeeCommon) ProxyServer.getInstance()).api.run();
} }
/**
* Gets the BungeeCommon Internals
*
* @deprecated Use BungeeAPI Methods when available
* @return BungeeCommon Internals
*/
@Deprecated
BungeeCommon getInternals();
/** /**
* Get the number of players on this network across all known proxies * Get the number of players on this network across all known proxies
* *

View File

@ -12,12 +12,10 @@ import java.util.Map;
* BungeeCord Common Layout Class * BungeeCord Common Layout Class
*/ */
public abstract class BungeeCommon extends BungeeCord { public abstract class BungeeCommon extends BungeeCord {
private static BungeeCommon instance;
final ReturnRunnable<BungeeAPI> api; final ReturnRunnable<BungeeAPI> api;
protected BungeeCommon(ReturnRunnable<BungeeAPI> api) throws IOException { protected BungeeCommon(ReturnRunnable<BungeeAPI> api) throws IOException {
this.api = api; this.api = api;
instance = this;
} }
/** /**
@ -33,13 +31,4 @@ public abstract class BungeeCommon extends BungeeCord {
* @return Server Map Copy * @return Server Map Copy
*/ */
public abstract Map<String, ServerInfo> getServersCopy(); public abstract Map<String, ServerInfo> getServersCopy();
/**
* Gets the ProxyServer Common Object
*
* @return ProxyServer Common
*/
public static BungeeCommon getInstance() {
return instance;
}
} }

View File

@ -75,6 +75,16 @@ public interface RemotePlayer {
sendMessage(messages, i -> {}); sendMessage(messages, i -> {});
} }
/**
* Sends messages to this player
*
* @param message Message to send
* @param response Success Status
*/
default void sendMessage(String message, Callback<Integer> response) {
sendMessage(new String[]{ message }, response);
}
/** /**
* Sends messages to this player * Sends messages to this player
* *
@ -92,6 +102,16 @@ public interface RemotePlayer {
sendMessage(messages, i -> {}); sendMessage(messages, i -> {});
} }
/**
* Sends messages to this player
*
* @param message Message to send
* @param response Success Status
*/
default void sendMessage(BaseComponent message, Callback<Integer> response) {
sendMessage(new BaseComponent[]{ message }, response);
}
/** /**
* Sends messages to this player * Sends messages to this player
* *
@ -153,17 +173,17 @@ public interface RemotePlayer {
/** /**
* Disconnects this player from the network * Disconnects this player from the network
* *
* @param message Disconnect Message * @param reason Disconnect Reason
*/ */
default void disconnect(String message) { default void disconnect(String reason) {
disconnect(message, i -> {}); disconnect(reason, i -> {});
} }
/** /**
* Disconnects this player from the network * Disconnects this player from the network
* *
* @param message Disconnect Message * @param reason Disconnect Reason
* @param response Success status * @param response Success status
*/ */
void disconnect(String message, Callback<Integer> response); void disconnect(String reason, Callback<Integer> response);
} }

View File

@ -17,6 +17,8 @@ import net.md_5.bungee.chat.ComponentSerializer;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Collections;
import java.util.UUID; import java.util.UUID;
/** /**
@ -140,7 +142,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
SubDataClient client = getProxyConnection(); SubDataClient client = getProxyConnection();
if (client != null) { if (client != null) {
StackTraceElement[] origin = new Exception().getStackTrace(); StackTraceElement[] origin = new Exception().getStackTrace();
client.sendPacket(new PacketExMessagePlayer(getUniqueId(), messages, null, data -> { client.sendPacket(new PacketExMessagePlayer(getUniqueId(), Arrays.asList(messages), null, data -> {
try { try {
response.run(data.getInt(0x0001)); response.run(data.getInt(0x0001));
} catch (Throwable e) { } catch (Throwable e) {
@ -162,7 +164,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
SubDataClient client = getProxyConnection(); SubDataClient client = getProxyConnection();
if (client != null) { if (client != null) {
StackTraceElement[] origin = new Exception().getStackTrace(); StackTraceElement[] origin = new Exception().getStackTrace();
client.sendPacket(new PacketExMessagePlayer(getUniqueId(), null, new String[]{ ComponentSerializer.toString(messages) }, data -> { client.sendPacket(new PacketExMessagePlayer(getUniqueId(), null, Collections.singletonList(ComponentSerializer.toString(messages)), data -> {
try { try {
response.run(data.getInt(0x0001)); response.run(data.getInt(0x0001));
} catch (Throwable e) { } catch (Throwable e) {
@ -223,17 +225,17 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
} }
@Override @Override
public void disconnect(String message, Callback<Integer> response) { public void disconnect(String reason, Callback<Integer> response) {
if (local != null) { if (local != null) {
if (message != null) { if (reason != null) {
local.disconnect(message); local.disconnect(reason);
} else local.disconnect(); } else local.disconnect();
response.run(0); response.run(0);
} else { } else {
SubDataClient client = getProxyConnection(); SubDataClient client = getProxyConnection();
if (client != null) { if (client != null) {
StackTraceElement[] origin = new Exception().getStackTrace(); StackTraceElement[] origin = new Exception().getStackTrace();
client.sendPacket(new PacketExDisconnectPlayer(getUniqueId(), message, data -> { client.sendPacket(new PacketExDisconnectPlayer(getUniqueId(), reason, data -> {
try { try {
response.run(data.getInt(0x0001)); response.run(data.getInt(0x0001));
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -8,6 +8,7 @@ import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient; import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
@ -16,7 +17,7 @@ import java.util.UUID;
public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> { public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>(); private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private UUID player; private UUID player;
private String[] legacy, raw; private List<String> legacy, raw;
private UUID id; private UUID id;
/** /**
@ -33,7 +34,7 @@ public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObj
* @param callback Callbacks * @param callback Callbacks
*/ */
@SafeVarargs @SafeVarargs
public PacketExMessagePlayer(UUID player, String[] legacy, String[] raw, Callback<ObjectMap<Integer>>... callback) { public PacketExMessagePlayer(UUID player, List<String> legacy, List<String> raw, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(player, callback)) throw new NullPointerException(); if (Util.isNull(player, callback)) throw new NullPointerException();
this.player = player; this.player = player;
this.legacy = legacy; this.legacy = legacy;

View File

@ -75,7 +75,7 @@ public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjec
client.sendPacket(new PacketMessagePlayer(0, tracker)); client.sendPacket(new PacketMessagePlayer(0, tracker));
} else if ((remote = plugin.api.getRemotePlayer(id)) != null) { } else if ((remote = plugin.api.getRemotePlayer(id)) != null) {
if (remote.getProxy().getSubData()[0] != null) { if (remote.getProxy().getSubData()[0] != null) {
((SubDataClient) remote.getProxy().getSubData()[0]).sendPacket(new PacketExMessagePlayer(remote.getUniqueId(), (data.contains(0x0002)?data.getRawStringList(0x0002).toArray(new String[0]):null), (data.contains(0x0003)?data.getRawStringList(0x0003).toArray(new String[0]):null), r -> { ((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)); client.sendPacket(new PacketMessagePlayer(r.getInt(0x0001), tracker));
})); }));
} else { } else {

View File

@ -176,6 +176,16 @@ public class RemotePlayer {
sendMessage(messages, i -> {}); sendMessage(messages, i -> {});
} }
/**
* Sends messages to this player
*
* @param message Message to send
* @param response Success Status
*/
public void sendMessage(String message, Callback<Integer> response) {
sendMessage(new String[]{ message }, response);
}
/** /**
* Sends messages to this player * Sends messages to this player
* *
@ -204,6 +214,16 @@ public class RemotePlayer {
sendRawMessage(messages, i -> {}); sendRawMessage(messages, i -> {});
} }
/**
* Sends JSON format messages to this player
*
* @param message Message to send
* @param response Success Status
*/
public void sendRawMessage(String message, Callback<Integer> response) {
sendRawMessage(new String[]{ message }, response);
}
/** /**
* Sends JSON format messages to this player * Sends JSON format messages to this player
* *
@ -289,21 +309,21 @@ public class RemotePlayer {
/** /**
* Disconnects this player from the network * Disconnects this player from the network
* *
* @param message Disconnect Message * @param reason Disconnect Reason
*/ */
public void disconnect(String message) { public void disconnect(String reason) {
disconnect(message, i -> {}); disconnect(reason, i -> {});
} }
/** /**
* Disconnects this player from the network * Disconnects this player from the network
* *
* @param message Disconnect Message * @param reason Disconnect Reason
* @param response Success status * @param response Success status
*/ */
public void disconnect(String message, Callback<Integer> response) { public void disconnect(String reason, Callback<Integer> response) {
StackTraceElement[] origin = new Exception().getStackTrace(); StackTraceElement[] origin = new Exception().getStackTrace();
client().sendPacket(new PacketDisconnectPlayer(getUniqueId(), message, data -> { client().sendPacket(new PacketDisconnectPlayer(getUniqueId(), reason, data -> {
try { try {
response.run(data.getInt(0x0001)); response.run(data.getInt(0x0001));
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -139,15 +139,15 @@ public class CachedPlayer extends RemotePlayer implements net.ME1312.SubServers.
} }
@Override @Override
public void disconnect(String message, Callback<Integer> response) { public void disconnect(String reason, Callback<Integer> response) {
ProxiedPlayer local = get(); ProxiedPlayer local = get();
if (local != null) { if (local != null) {
if (message != null) { if (reason != null) {
local.disconnect(message); local.disconnect(reason);
} else local.disconnect(); } else local.disconnect();
response.run(0); response.run(0);
} else { } else {
super.disconnect(message, response); super.disconnect(reason, response);
} }
} }
} }