Fix constructor overrides

This commit is contained in:
ME1312 2021-06-15 04:23:26 -04:00
parent 1fff679005
commit 0a6fdb337f
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
6 changed files with 47 additions and 58 deletions

View File

@ -1,7 +1,6 @@
package net.ME1312.SubServers.Client.Common.Network.API; package net.ME1312.SubServers.Client.Common.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback; import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Pair; import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap; import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue; import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
@ -197,7 +196,7 @@ public class Host {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> { client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>(); LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) { for (String player : data.getKeys()) {
players.add(RemotePlayer.st4tic.construct(servers.get(UUID.fromString(player)), data.getMap(player))); players.add(RemotePlayer.instance.construct(servers.get(UUID.fromString(player)), data.getMap(player)));
} }
this.players = players; this.players = players;

View File

@ -10,7 +10,6 @@ import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender; import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender; import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient; import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Client.Common.ClientAPI; import net.ME1312.SubServers.Client.Common.ClientAPI;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadPlayerInfo; import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadProxyInfo; import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadProxyInfo;
@ -149,7 +148,7 @@ public class Proxy {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> { client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>(); LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) { for (String player : data.getKeys()) {
players.add(RemotePlayer.st4tic.construct(this, data.getMap(player))); players.add(RemotePlayer.instance.construct(this, data.getMap(player)));
} }
this.players = players; this.players = players;

View File

@ -16,7 +16,7 @@ import java.util.*;
* Simplified RemotePlayer Data Class * Simplified RemotePlayer Data Class
*/ */
public class RemotePlayer { public class RemotePlayer {
protected static StaticImpl st4tic = new StaticImpl(); protected static StaticImpl instance = new StaticImpl();
ObjectMap<String> raw; ObjectMap<String> raw;
private Proxy proxy = null; private Proxy proxy = null;
private Server server = null; private Server server = null;
@ -223,7 +223,7 @@ public class RemotePlayer {
* @param response Success Status * @param response Success Status
*/ */
public void sendMessage(String[] messages, Callback<Integer> response) { public void sendMessage(String[] messages, Callback<Integer> response) {
st4tic.sendMessage(client(), new UUID[]{ getUniqueId() }, messages, response); instance.sendMessage(client(), new UUID[]{ getUniqueId() }, messages, response);
} }
/** /**
@ -255,7 +255,7 @@ public class RemotePlayer {
* @param response Success Status * @param response Success Status
*/ */
public static void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) { public static void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) {
st4tic.sendMessage(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, messages, response); instance.sendMessage(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, messages, response);
} }
/** /**
@ -313,7 +313,7 @@ public class RemotePlayer {
* @param response Success Status * @param response Success Status
*/ */
public void sendRawMessage(String[] message, Callback<Integer> response) { public void sendRawMessage(String[] message, Callback<Integer> response) {
st4tic.sendRawMessage(client(), new UUID[]{ getUniqueId() }, message, response); instance.sendRawMessage(client(), new UUID[]{ getUniqueId() }, message, response);
} }
/** /**
@ -345,7 +345,7 @@ public class RemotePlayer {
* @param response Success Status * @param response Success Status
*/ */
public static void sendRawMessage(UUID[] players, String[] messages, Callback<Integer> response) { public static void sendRawMessage(UUID[] players, String[] messages, Callback<Integer> response) {
st4tic.sendRawMessage(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, messages, response); instance.sendRawMessage(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, messages, response);
} }
/** /**
@ -364,7 +364,7 @@ public class RemotePlayer {
* @param response Success status * @param response Success status
*/ */
public void transfer(String server, Callback<Integer> response) { public void transfer(String server, Callback<Integer> response) {
st4tic.transfer(client(), new UUID[]{ getUniqueId() }, server, response); instance.transfer(client(), new UUID[]{ getUniqueId() }, server, response);
} }
/** /**
@ -385,7 +385,7 @@ public class RemotePlayer {
* @param response Success status * @param response Success status
*/ */
public static void transfer(UUID[] players, String server, Callback<Integer> response) { public static void transfer(UUID[] players, String server, Callback<Integer> response) {
st4tic.transfer(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, server, response); instance.transfer(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, server, response);
} }
/** /**
@ -420,7 +420,7 @@ public class RemotePlayer {
* @param response Success status * @param response Success status
*/ */
public void disconnect(String reason, Callback<Integer> response) { public void disconnect(String reason, Callback<Integer> response) {
st4tic.disconnect(client(), new UUID[]{ getUniqueId() }, reason, response); instance.disconnect(client(), new UUID[]{ getUniqueId() }, reason, response);
} }
/** /**
@ -460,7 +460,7 @@ public class RemotePlayer {
* @param response Success status * @param response Success status
*/ */
public static void disconnect(UUID[] players, String reason, Callback<Integer> response) { public static void disconnect(UUID[] players, String reason, Callback<Integer> response) {
st4tic.disconnect(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, reason, response); instance.disconnect(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, reason, response);
} }
/** /**
@ -511,7 +511,7 @@ public class RemotePlayer {
* @param raw Raw representation of the Remote Player * @param raw Raw representation of the Remote Player
*/ */
final RemotePlayer construct(Server server, ObjectMap<String> raw) { final RemotePlayer construct(Server server, ObjectMap<String> raw) {
RemotePlayer player = new RemotePlayer(server.client, raw); RemotePlayer player = construct(server.client, raw);
player.server = server; player.server = server;
return player; return player;
} }
@ -523,7 +523,7 @@ public class RemotePlayer {
* @param raw Raw representation of the Remote Player * @param raw Raw representation of the Remote Player
*/ */
final RemotePlayer construct(Proxy proxy, ObjectMap<String> raw) { final RemotePlayer construct(Proxy proxy, ObjectMap<String> raw) {
RemotePlayer player = new RemotePlayer(proxy.client, raw); RemotePlayer player = construct(proxy.client, raw);
player.proxy = proxy; player.proxy = proxy;
return player; return player;
} }

View File

@ -9,7 +9,6 @@ import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender; import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender; import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient; import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Client.Common.ClientAPI; import net.ME1312.SubServers.Client.Common.ClientAPI;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadPlayerInfo; import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadServerInfo; import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadServerInfo;
@ -157,7 +156,7 @@ public class Server {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> { client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>(); LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) { for (String player : data.getKeys()) {
players.add(RemotePlayer.st4tic.construct(this, data.getMap(player))); players.add(RemotePlayer.instance.construct(this, data.getMap(player)));
} }
this.players = players; this.players = players;

View File

@ -334,7 +334,7 @@ public final class SimplifiedData {
client(client).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> { client(client).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>(); TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) { for (String player : data.getKeys()) {
players.put(UUID.fromString(player), RemotePlayer.st4tic.construct(client, data.getMap(player))); players.put(UUID.fromString(player), RemotePlayer.instance.construct(client, data.getMap(player)));
} }
try { try {
@ -360,7 +360,7 @@ public final class SimplifiedData {
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> { client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null; RemotePlayer player = null;
if (data.getKeys().size() > 0) { if (data.getKeys().size() > 0) {
player = RemotePlayer.st4tic.construct(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst())); player = RemotePlayer.instance.construct(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
} }
try { try {
@ -386,7 +386,7 @@ public final class SimplifiedData {
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> { client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null; RemotePlayer player = null;
if (data.getKeys().size() > 0) { if (data.getKeys().size() > 0) {
player = RemotePlayer.st4tic.construct(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst())); player = RemotePlayer.instance.construct(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
} }
try { try {

View File

@ -107,7 +107,7 @@ public class CachedPlayer extends RemotePlayer implements net.ME1312.SubServers.
} }
}; };
// These overrides prevent sending unnecessary packets in ClientCommon // These overrides prevent sending unnecessary packets in ClientCommon
st4tic = new StaticImpl() { instance = new StaticImpl() {
@Override @Override
protected RemotePlayer construct(DataClient client, ObjectMap<String> raw) { protected RemotePlayer construct(DataClient client, ObjectMap<String> raw) {
return new CachedPlayer(client, raw); return new CachedPlayer(client, raw);
@ -168,54 +168,46 @@ public class CachedPlayer extends RemotePlayer implements net.ME1312.SubServers.
@Override @Override
protected void transfer(SubDataClient client, UUID[] players, String server, Callback<Integer> response) { protected void transfer(SubDataClient client, UUID[] players, String server, Callback<Integer> response) {
if (players != null && players.length > 0) { ArrayList<UUID> ids = new ArrayList<UUID>();
ArrayList<UUID> ids = new ArrayList<UUID>(); ServerImpl info = SubAPI.getInstance().getInternals().servers.get(server.toLowerCase());
ServerImpl info = SubAPI.getInstance().getInternals().servers.get(server.toLowerCase()); int failures = 0;
int failures = 0; for (UUID id : players) {
for (UUID id : players) { ProxiedPlayer local = get(id);
ProxiedPlayer local = get(id); if (local != null) {
if (local != null) { if (info != null) {
if (info != null) { local.connect(info);
local.connect(info); } else ++failures;
} else ++failures;
} else {
ids.add(id);
}
}
if (ids.size() == 0) {
response.run(failures);
} else { } else {
final int ff = failures; ids.add(id);
super.transfer(client, ids.toArray(new UUID[0]), server, i -> response.run(i + ff));
} }
}
if (ids.size() == 0) {
response.run(failures);
} else { } else {
super.transfer(client, players, server, response); final int ff = failures;
super.transfer(client, ids.toArray(new UUID[0]), server, i -> response.run(i + ff));
} }
} }
@Override @Override
protected void disconnect(SubDataClient client, UUID[] players, String reason, Callback<Integer> response) { protected void disconnect(SubDataClient client, UUID[] players, String reason, Callback<Integer> response) {
if (players != null && players.length > 0) { ArrayList<UUID> ids = new ArrayList<UUID>();
ArrayList<UUID> ids = new ArrayList<UUID>(); for (UUID id : players) {
for (UUID id : players) { ProxiedPlayer local = get(id);
ProxiedPlayer local = get(id); if (local != null) {
if (local != null) { if (reason != null) {
if (reason != null) { local.disconnect(reason);
local.disconnect(reason); } else local.disconnect();
} else local.disconnect();
} else {
ids.add(id);
}
}
if (ids.size() == 0) {
response.run(0);
} else { } else {
super.disconnect(client, ids.toArray(new UUID[0]), reason, response); ids.add(id);
} }
}
if (ids.size() == 0) {
response.run(0);
} else { } else {
super.disconnect(client, players, reason, response); super.disconnect(client, ids.toArray(new UUID[0]), reason, response);
} }
} }
}; };