Skip to content

Commit

Permalink
Fix constructor overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Jun 15, 2021
1 parent 1fff679 commit 0a6fdb3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 58 deletions.
@@ -1,7 +1,6 @@
package net.ME1312.SubServers.Client.Common.Network.API;

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.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
Expand Down Expand Up @@ -197,7 +196,7 @@ public void getRemotePlayers(Callback<Collection<RemotePlayer>> callback) {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
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;
Expand Down
Expand Up @@ -10,7 +10,6 @@
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Client.Common.ClientAPI;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadProxyInfo;
Expand Down Expand Up @@ -149,7 +148,7 @@ public void getPlayers(Callback<Collection<RemotePlayer>> callback) {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
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;
Expand Down
Expand Up @@ -16,7 +16,7 @@
* Simplified RemotePlayer Data Class
*/
public class RemotePlayer {
protected static StaticImpl st4tic = new StaticImpl();
protected static StaticImpl instance = new StaticImpl();
ObjectMap<String> raw;
private Proxy proxy = null;
private Server server = null;
Expand Down Expand Up @@ -223,7 +223,7 @@ public void sendMessage(String message, Callback<Integer> response) {
* @param response Success Status
*/
public void sendMessage(String[] messages, Callback<Integer> response) {
st4tic.sendMessage(client(), new UUID[]{ getUniqueId() }, messages, response);
instance.sendMessage(client(), new UUID[]{ getUniqueId() }, messages, response);
}

/**
Expand Down Expand Up @@ -255,7 +255,7 @@ public static void sendMessage(UUID[] players, String message, Callback<Integer>
* @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);
instance.sendMessage(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, messages, response);
}

/**
Expand Down Expand Up @@ -313,7 +313,7 @@ public void sendRawMessage(String message, Callback<Integer> response) {
* @param response Success Status
*/
public void sendRawMessage(String[] message, Callback<Integer> response) {
st4tic.sendRawMessage(client(), new UUID[]{ getUniqueId() }, message, response);
instance.sendRawMessage(client(), new UUID[]{ getUniqueId() }, message, response);
}

/**
Expand Down Expand Up @@ -345,7 +345,7 @@ public static void sendRawMessage(UUID[] players, String message, Callback<Integ
* @param response Success Status
*/
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);
}

/**
Expand All @@ -364,7 +364,7 @@ public void transfer(String server) {
* @param response Success status
*/
public void transfer(String server, Callback<Integer> response) {
st4tic.transfer(client(), new UUID[]{ getUniqueId() }, server, response);
instance.transfer(client(), new UUID[]{ getUniqueId() }, server, response);
}

/**
Expand All @@ -385,7 +385,7 @@ public static void transfer(UUID[] players, String server) {
* @param response Success status
*/
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);
}

/**
Expand Down Expand Up @@ -420,7 +420,7 @@ public void disconnect(String reason) {
* @param response Success status
*/
public void disconnect(String reason, Callback<Integer> response) {
st4tic.disconnect(client(), new UUID[]{ getUniqueId() }, reason, response);
instance.disconnect(client(), new UUID[]{ getUniqueId() }, reason, response);
}

/**
Expand Down Expand Up @@ -460,7 +460,7 @@ public static void disconnect(UUID[] players, String 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);
instance.disconnect(SimplifiedData.client(ClientAPI.getInstance().getSubDataNetwork()[0]), players, reason, response);
}

/**
Expand Down Expand Up @@ -511,7 +511,7 @@ protected RemotePlayer construct(DataClient client, ObjectMap<String> raw) {
* @param raw Raw representation of the Remote Player
*/
final RemotePlayer construct(Server server, ObjectMap<String> raw) {
RemotePlayer player = new RemotePlayer(server.client, raw);
RemotePlayer player = construct(server.client, raw);
player.server = server;
return player;
}
Expand All @@ -523,7 +523,7 @@ final RemotePlayer construct(Server server, ObjectMap<String> raw) {
* @param raw Raw representation of the Remote Player
*/
final RemotePlayer construct(Proxy proxy, ObjectMap<String> raw) {
RemotePlayer player = new RemotePlayer(proxy.client, raw);
RemotePlayer player = construct(proxy.client, raw);
player.proxy = proxy;
return player;
}
Expand Down
Expand Up @@ -9,7 +9,6 @@
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Client.Common.ClientAPI;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadServerInfo;
Expand Down Expand Up @@ -157,7 +156,7 @@ public void getRemotePlayers(Callback<Collection<RemotePlayer>> callback) {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
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;
Expand Down
Expand Up @@ -334,7 +334,7 @@ public static void requestRemotePlayers(DataClient client, Callback<Map<UUID, Re
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), RemotePlayer.st4tic.construct(client, data.getMap(player)));
players.put(UUID.fromString(player), RemotePlayer.instance.construct(client, data.getMap(player)));
}

try {
Expand All @@ -360,7 +360,7 @@ public static void requestRemotePlayer(DataClient client, String name, Callback<
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
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 {
Expand All @@ -386,7 +386,7 @@ public static void requestRemotePlayer(DataClient client, UUID id, Callback<Remo
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
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 {
Expand Down
Expand Up @@ -107,7 +107,7 @@ protected void disconnect(UUID[] players, String reason, Callback<Integer> respo
}
};
// These overrides prevent sending unnecessary packets in ClientCommon
st4tic = new StaticImpl() {
instance = new StaticImpl() {
@Override
protected RemotePlayer construct(DataClient client, ObjectMap<String> raw) {
return new CachedPlayer(client, raw);
Expand Down Expand Up @@ -168,54 +168,46 @@ protected void sendRawMessage(SubDataClient client, UUID[] players, String[] mes

@Override
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);
} else ++failures;
} else {
ids.add(id);
}
}

if (ids.size() == 0) {
response.run(failures);
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);
} else ++failures;
} else {
final int ff = failures;
super.transfer(client, ids.toArray(new UUID[0]), server, i -> response.run(i + ff));
ids.add(id);
}
}

if (ids.size() == 0) {
response.run(failures);
} 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
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);
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 {
super.disconnect(client, ids.toArray(new UUID[0]), reason, response);
ids.add(id);
}
}

if (ids.size() == 0) {
response.run(0);
} else {
super.disconnect(client, players, reason, response);
super.disconnect(client, ids.toArray(new UUID[0]), reason, response);
}
}
};
Expand Down

0 comments on commit 0a6fdb3

Please sign in to comment.