Fixes to ping adjustment for global player count

This commit is contained in:
ME1312 2023-01-10 00:57:31 -05:00
parent cf07e86a09
commit 8a5a0cdc4b
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
8 changed files with 69 additions and 52 deletions

View File

@ -947,21 +947,26 @@ public final class SubProxy extends BungeeCommon implements Listener {
}
}
@SuppressWarnings({"AssignmentUsedAsCondition", "deprecation"})
@EventHandler(priority = Byte.MIN_VALUE)
public void ping_passthrough(ProxyPingEvent e) {
boolean dynamic;
ServerInfo override;
if ((dynamic = SmartFallback.getForcedHost(e.getConnection()) == null) && getReconnectHandler() instanceof SmartFallback && (override = SmartFallback.getDNS(e.getConnection())) != null) {
final boolean dynamic;
if ((dynamic = SmartFallback.getForcedHost(e.getConnection()) == null) || !e.getConnection().getListener().isPingPassthrough()) {
e.getResponse().getPlayers().setOnline(rPlayers.size());
}
final ServerInfo override;
if (dynamic && getReconnectHandler() instanceof SmartFallback && (override = SmartFallback.getDNS(e.getConnection())) != null) {
if (!(override instanceof SubServer) || ((SubServer) override).isRunning()) {
if (!e.getConnection().getListener().isPingPassthrough()) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(override.getMotd()), e.getResponse().getFaviconObject()));
e.getResponse().setDescription(override.getMotd());
} else {
Container<Boolean> lock = new Container<>(true);
boolean mode = plugin != null;
if (mode) e.registerIntent(plugin);
final boolean mode;
final Container<Boolean> lock = new Container<>(true);
if (mode = plugin != null) e.registerIntent(plugin);
((BungeeServerInfo) override).ping((ping, error) -> {
if (error != null) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(getTranslation("ping_cannot_connect")), e.getResponse().getFaviconObject()));
e.getResponse().setDescription(getTranslation("ping_cannot_connect"));
} else e.setResponse(ping);
lock.value = false;
if (mode) e.completeIntent(plugin);
@ -969,28 +974,26 @@ public final class SubProxy extends BungeeCommon implements Listener {
if (!mode) while (lock.value) Try.all.run(() -> Thread.sleep(4));
}
}
} else if (dynamic) {
e.getResponse().getPlayers().setOnline(rPlayers.size());
}
}
@SuppressWarnings("deprecation")
@EventHandler(priority = Byte.MAX_VALUE)
public void ping(ProxyPingEvent e) {
ServerInfo override;
if ((override = SmartFallback.getForcedHost(e.getConnection())) != null || (override = SmartFallback.getDNS(e.getConnection())) != null) {
if ((override = SmartFallback.getForcedHost(e.getConnection())) != null || (getReconnectHandler() instanceof SmartFallback && (override = SmartFallback.getDNS(e.getConnection())) != null)) {
if (override instanceof SubServer && !((SubServer) override).isRunning()) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(api.getLang("SubServers", "Bungee.Ping.Offline")), e.getResponse().getFaviconObject()));
e.getResponse().setDescription(api.getLang("SubServers", "Bungee.Ping.Offline"));
}
} else {
int offline = 0;
for (String name : e.getConnection().getListener().getServerPriority()) {
ServerInfo server = api.getServer(name.toLowerCase());
if (server == null) server = getServerInfo(name);
if (server == null || (server instanceof SubServer && !((SubServer) server).isRunning())) offline++;
ServerInfo server = getServerInfo(name);
if (server instanceof SubServer && !((SubServer) server).isRunning()) ++offline;
}
if (offline >= e.getConnection().getListener().getServerPriority().size()) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(api.getLang("SubServers", "Bungee.Ping.Offline")), e.getResponse().getFaviconObject()));
e.getResponse().setDescription(api.getLang("SubServers", "Bungee.Ping.Offline"));
}
}
}

View File

@ -26,8 +26,8 @@ import static net.ME1312.SubServers.Client.Bukkit.Library.ObjectPermission.permi
* Default GUI Renderer Class
*/
public class DefaultUIRenderer extends UIRenderer {
private static int MAX_VISITED_OBJECTS = 2;
private List<Runnable> windowHistory = new LinkedList<Runnable>();
private static final int MAX_VISITED_OBJECTS = 2;
private final List<Runnable> windowHistory = new LinkedList<Runnable>();
Object[] lastVisitedObjects = new Object[MAX_VISITED_OBJECTS];
int lastPage = 1;
Runnable lastMenu = null;

View File

@ -20,7 +20,7 @@ import java.util.function.Consumer;
* Run Event Packet
*/
public class PacketInExRunEvent implements PacketObjectIn<Integer> {
private static HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
private static final HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
/**
* New PacketInRunEvent
@ -159,9 +159,11 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
synchronized (callbacks) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
}
}
}

View File

@ -20,7 +20,7 @@ import java.util.function.Consumer;
* Run Event Packet
*/
public class PacketInExRunEvent implements PacketObjectIn<Integer> {
private static HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
private static final HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
/**
* New PacketInRunEvent
@ -131,9 +131,11 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
synchronized (callbacks) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
}
}
}

View File

@ -17,7 +17,7 @@ import java.util.function.Consumer;
* Run Event Packet
*/
public class PacketInExRunEvent implements PacketObjectIn<Integer> {
private static HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
private static final HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
/**
* New PacketInRunEvent
@ -128,9 +128,11 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
synchronized (callbacks) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
}
}
}

View File

@ -437,21 +437,26 @@ public final class ExProxy extends BungeeCommon implements Listener {
super.stopListeners();
}
@SuppressWarnings({"AssignmentUsedAsCondition", "deprecation"})
@EventHandler(priority = Byte.MIN_VALUE)
public void ping_passthrough(ProxyPingEvent e) {
boolean dynamic;
ServerInfo override;
if ((dynamic = SmartFallback.getForcedHost(e.getConnection()) == null) && getReconnectHandler() instanceof SmartFallback && (override = SmartFallback.getDNS(e.getConnection())) != null) {
final boolean dynamic;
if ((dynamic = SmartFallback.getForcedHost(e.getConnection()) == null) || !e.getConnection().getListener().isPingPassthrough()) {
e.getResponse().getPlayers().setOnline(rPlayers.size());
}
final ServerInfo override;
if (dynamic && getReconnectHandler() instanceof SmartFallback && (override = SmartFallback.getDNS(e.getConnection())) != null) {
if (!(override instanceof SubServerImpl) || ((SubServerImpl) override).isRunning()) {
if (!e.getConnection().getListener().isPingPassthrough()) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(override.getMotd()), e.getResponse().getFaviconObject()));
e.getResponse().setDescription(override.getMotd());
} else {
Container<Boolean> lock = new Container<>(true);
boolean mode = plugin != null;
if (mode) e.registerIntent(plugin);
final boolean mode;
final Container<Boolean> lock = new Container<>(true);
if (mode = plugin != null) e.registerIntent(plugin);
((BungeeServerInfo) override).ping((ping, error) -> {
if (error != null) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(getTranslation("ping_cannot_connect")), e.getResponse().getFaviconObject()));
e.getResponse().setDescription(getTranslation("ping_cannot_connect"));
} else e.setResponse(ping);
lock.value = false;
if (mode) e.completeIntent(plugin);
@ -459,27 +464,26 @@ public final class ExProxy extends BungeeCommon implements Listener {
if (!mode) while (lock.value) Try.all.run(() -> Thread.sleep(4));
}
}
} else if (dynamic) {
e.getResponse().getPlayers().setOnline(rPlayers.size());
}
}
@SuppressWarnings("deprecation")
@EventHandler(priority = Byte.MAX_VALUE)
public void ping(ProxyPingEvent e) {
ServerInfo override;
if ((override = SmartFallback.getForcedHost(e.getConnection())) != null || (override = SmartFallback.getDNS(e.getConnection())) != null) {
if ((override = SmartFallback.getForcedHost(e.getConnection())) != null || (getReconnectHandler() instanceof SmartFallback && (override = SmartFallback.getDNS(e.getConnection())) != null)) {
if (override instanceof SubServerImpl && !((SubServerImpl) override).isRunning()) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(api.getLang("SubServers", "Bungee.Ping.Offline")), e.getResponse().getFaviconObject()));
e.getResponse().setDescription(api.getLang("SubServers", "Bungee.Ping.Offline"));
}
} else {
int offline = 0;
for (String name : e.getConnection().getListener().getServerPriority()) {
ServerInfo server = getServerInfo(name);
if (server instanceof SubServerImpl && !((SubServerImpl) server).isRunning()) offline++;
if (server instanceof SubServerImpl && !((SubServerImpl) server).isRunning()) ++offline;
}
if (offline >= e.getConnection().getListener().getServerPriority().size()) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(api.getLang("SubServers", "Bungee.Ping.Offline")), e.getResponse().getFaviconObject()));
e.getResponse().setDescription(api.getLang("SubServers", "Bungee.Ping.Offline"));
}
}
}

View File

@ -19,7 +19,7 @@ import java.util.function.Consumer;
* Run Event Packet
*/
public class PacketInExRunEvent implements PacketObjectIn<Integer> {
private static HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
private static final HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
/**
* New PacketInExRunEvent
@ -130,9 +130,11 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
synchronized (callbacks) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
}
}
}

View File

@ -17,7 +17,7 @@ import java.util.function.Consumer;
* Run Event Packet
*/
public class PacketInExRunEvent implements PacketObjectIn<Integer> {
private static HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
private static final HashMap<String, List<Consumer<ObjectMap<String>>>> callbacks = new HashMap<String, List<Consumer<ObjectMap<String>>>>();
/**
* New PacketInExRunEvent
@ -128,9 +128,11 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@SuppressWarnings("unchecked")
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
synchronized (callbacks) {
if (callbacks.containsKey(data.getString(0x0000))) {
for (Consumer<ObjectMap<String>> callback : PacketInExRunEvent.callbacks.remove(data.getString(0x0000))) {
callback.accept(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
}
}
}
}