mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-25 19:56:24 +01:00
Fix possible player data desyncs
This commit is contained in:
parent
891913dbe3
commit
efc12e0649
@ -9,6 +9,7 @@ import net.ME1312.Galaxi.Library.ExtraDataHandler;
|
|||||||
import net.ME1312.Galaxi.Library.Container.NamedContainer;
|
import net.ME1312.Galaxi.Library.Container.NamedContainer;
|
||||||
import net.ME1312.Galaxi.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubData.Server.ClientHandler;
|
import net.ME1312.SubData.Server.ClientHandler;
|
||||||
|
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExSyncPlayer;
|
||||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||||
import net.ME1312.SubServers.Bungee.SubProxy;
|
import net.ME1312.SubServers.Bungee.SubProxy;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@ -49,6 +50,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
|||||||
return channels.toArray(new DataClient[0]);
|
return channels.toArray(new DataClient[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void setSubData(SubDataClient client, int channel) {
|
public void setSubData(SubDataClient client, int channel) {
|
||||||
boolean update = false;
|
boolean update = false;
|
||||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||||
@ -65,9 +67,20 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
|||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
DataClient[] subdata = getSubData();
|
DataClient[] subdata = getSubData();
|
||||||
if (subdata[0] == null && subdata.length <= 1 && !persistent) {
|
if (subdata[0] == null && subdata.length <= 1) {
|
||||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveProxyEvent(this));
|
SubProxy plugin = SubAPI.getInstance().getInternals();
|
||||||
SubAPI.getInstance().getInternals().proxies.remove(getName().toLowerCase());
|
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, this)) {
|
||||||
|
plugin.rPlayerLinkS.remove(id);
|
||||||
|
plugin.rPlayerLinkP.remove(id);
|
||||||
|
plugin.rPlayers.remove(id);
|
||||||
|
}
|
||||||
|
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null && proxy != this) {
|
||||||
|
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(getName(), null, (RemotePlayer[]) null));
|
||||||
|
}
|
||||||
|
if (!persistent) {
|
||||||
|
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveProxyEvent(this));
|
||||||
|
SubAPI.getInstance().getInternals().proxies.remove(getName().toLowerCase());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import java.util.*;
|
|||||||
public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private SubProxy plugin;
|
private SubProxy plugin;
|
||||||
private String name;
|
private String name;
|
||||||
private boolean mode;
|
private Boolean mode;
|
||||||
private RemotePlayer[] values;
|
private RemotePlayer[] values;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +41,6 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
|
|||||||
* @param values RemotePlayers
|
* @param values RemotePlayers
|
||||||
*/
|
*/
|
||||||
public PacketExSyncPlayer(String name, Boolean mode, RemotePlayer... values) {
|
public PacketExSyncPlayer(String name, Boolean mode, RemotePlayer... values) {
|
||||||
if (Util.isNull(mode)) throw new NullPointerException();
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.values = values;
|
this.values = values;
|
||||||
@ -73,7 +72,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.getBoolean(0x0001) != Boolean.FALSE) {
|
if (data.getBoolean(0x0001) != Boolean.FALSE) {
|
||||||
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
if (data.contains(0x0002)) for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
||||||
Server server = (object.getOrDefault("server", null) != null)?plugin.api.getServer(object.get("server").toString()):null;
|
Server server = (object.getOrDefault("server", null) != null)?plugin.api.getServer(object.get("server").toString()):null;
|
||||||
RemotePlayer player = new RemotePlayer(object.get("name").toString(), UUID.fromString(object.get("id").toString()), (Proxy) client.getHandler(), server,
|
RemotePlayer player = new RemotePlayer(object.get("name").toString(), UUID.fromString(object.get("id").toString()), (Proxy) client.getHandler(), server,
|
||||||
new InetSocketAddress(object.get("address").toString().split(":")[0], Integer.parseInt(object.get("address").toString().split(":")[1])));
|
new InetSocketAddress(object.get("address").toString().split(":")[0], Integer.parseInt(object.get("address").toString().split(":")[1])));
|
||||||
@ -84,7 +83,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
|
|||||||
if (server != null) plugin.rPlayerLinkS.put(player.getUniqueId(), server);
|
if (server != null) plugin.rPlayerLinkS.put(player.getUniqueId(), server);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
if (data.contains(0x0002)) for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
||||||
UUID id = UUID.fromString(object.get("id").toString());
|
UUID id = UUID.fromString(object.get("id").toString());
|
||||||
RemotePlayer player = plugin.rPlayers.get(id);
|
RemotePlayer player = plugin.rPlayers.get(id);
|
||||||
|
|
||||||
@ -95,7 +94,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null && proxy != client.getHandler()) {
|
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null && proxy != client.getHandler()) {
|
||||||
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(proxy.getName(), data.getBoolean(0x0001), forward.toArray(new RemotePlayer[0])));
|
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(((Proxy) client.getHandler()).getName(), data.getBoolean(0x0001), forward.toArray(new RemotePlayer[0])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,6 +314,10 @@ public final class ExProxy extends BungeeCord implements Listener {
|
|||||||
for (ListenerInfo listener : getConfig().getListeners()) {
|
for (ListenerInfo listener : getConfig().getListeners()) {
|
||||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rPlayerLinkS.clear();
|
||||||
|
rPlayerLinkP.clear();
|
||||||
|
rPlayers.clear();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -410,7 +414,7 @@ public final class ExProxy extends BungeeCord implements Listener {
|
|||||||
raw.set("server", e.getServer().getInfo().getName());
|
raw.set("server", e.getServer().getInfo().getName());
|
||||||
RemotePlayer player = new RemotePlayer(raw);
|
RemotePlayer player = new RemotePlayer(raw);
|
||||||
rPlayers.put(player.getUniqueId(), player);
|
rPlayers.put(player.getUniqueId(), player);
|
||||||
rPlayerLinkP.put(player.getUniqueId(), player.getProxy());
|
rPlayerLinkP.put(player.getUniqueId(), player.getProxy().toLowerCase());
|
||||||
if (e.getServer().getInfo() instanceof ServerImpl) rPlayerLinkS.put(player.getUniqueId(), (ServerImpl) e.getServer().getInfo());
|
if (e.getServer().getInfo() instanceof ServerImpl) rPlayerLinkS.put(player.getUniqueId(), (ServerImpl) e.getServer().getInfo());
|
||||||
if (api.getSubDataNetwork()[0] != null) {
|
if (api.getSubDataNetwork()[0] != null) {
|
||||||
((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(new PacketExSyncPlayer(true, player));
|
((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(new PacketExSyncPlayer(true, player));
|
||||||
|
@ -16,7 +16,7 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private ExProxy plugin;
|
private ExProxy plugin;
|
||||||
private boolean mode;
|
private Boolean mode;
|
||||||
private RemotePlayer[] values;
|
private RemotePlayer[] values;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +36,6 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
|
|||||||
* @param values RemotePlayers
|
* @param values RemotePlayers
|
||||||
*/
|
*/
|
||||||
public PacketExSyncPlayer(Boolean mode, RemotePlayer... values) {
|
public PacketExSyncPlayer(Boolean mode, RemotePlayer... values) {
|
||||||
if (Util.isNull(mode)) throw new NullPointerException();
|
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
@ -65,7 +64,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.getBoolean(0x0001) != Boolean.FALSE) {
|
if (data.getBoolean(0x0001) != Boolean.FALSE) {
|
||||||
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
if (data.contains(0x0002)) for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
||||||
ServerImpl server = (object.getOrDefault("server", null) != null)?plugin.servers.getOrDefault(object.get("server").toString().toLowerCase(), null):null;
|
ServerImpl server = (object.getOrDefault("server", null) != null)?plugin.servers.getOrDefault(object.get("server").toString().toLowerCase(), null):null;
|
||||||
RemotePlayer player = new RemotePlayer(new ObjectMap<>(object));
|
RemotePlayer player = new RemotePlayer(new ObjectMap<>(object));
|
||||||
|
|
||||||
@ -74,7 +73,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
|
|||||||
if (server != null) plugin.rPlayerLinkS.put(player.getUniqueId(), server);
|
if (server != null) plugin.rPlayerLinkS.put(player.getUniqueId(), server);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
if (data.contains(0x0002)) for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
|
||||||
UUID id = UUID.fromString(object.get("id").toString());
|
UUID id = UUID.fromString(object.get("id").toString());
|
||||||
plugin.rPlayerLinkS.remove(id);
|
plugin.rPlayerLinkS.remove(id);
|
||||||
plugin.rPlayerLinkP.remove(id);
|
plugin.rPlayerLinkP.remove(id);
|
||||||
|
@ -23,10 +23,7 @@ import net.md_5.bungee.conf.Configuration;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -161,6 +158,18 @@ public class SubProtocol extends SubDataProtocol {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayList<RemotePlayer> localPlayers = new ArrayList<RemotePlayer>();
|
||||||
|
for (UUID id : new ArrayList<UUID>(plugin.rPlayers.keySet())) {
|
||||||
|
if (plugin.getPlayer(id) != null) {
|
||||||
|
localPlayers.add(plugin.rPlayers.get(id));
|
||||||
|
} else {
|
||||||
|
plugin.rPlayerLinkS.remove(id);
|
||||||
|
plugin.rPlayerLinkP.remove(id);
|
||||||
|
plugin.rPlayers.remove(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subdata.sendPacket(new PacketExSyncPlayer(null, localPlayers.toArray(new RemotePlayer[0])));
|
||||||
|
|
||||||
plugin.api.getServers(servers -> {
|
plugin.api.getServers(servers -> {
|
||||||
for (Server server : servers.values()) {
|
for (Server server : servers.values()) {
|
||||||
plugin.merge(server);
|
plugin.merge(server);
|
||||||
|
Loading…
Reference in New Issue
Block a user