2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2026-04-09 08:30:26 +00:00

Allow to customize ping events priority via handle-motd-order (#108)

Currently, the bungee implementation is using NORMAL priority for the
ping event handler, while the velocity implementation is using LAST.
Regardless of which choice may be the better one, this is an
inconsistency that this patch addresses by using NORMAL as the default
for both platforms.

Additionally to addressing the inconsistency, this patch adds a new
config option `handle-motd-order` which uses velocity's event priority
nomenclature to allow configuring the behavior of the MOTD handling on
both platforms.

In cases where there is a MOTD plugin that incorrectly overrides a
player count using the local player count, one may choose to use order
LAST to override the value back to the global player count.

In cases where there is a MOTD plugin that relies on a player count
value from the ping response, one may choose to use order FIRST to make
sure the response will have the correct global player count.

Fixes https://github.com/ProxioDev/ValioBungee/issues/107
This commit is contained in:
Dawid Sawicki
2024-07-05 02:22:39 +02:00
committed by mohammed jasem alaajel
parent 9b01ca21f6
commit 36d56fe52e
6 changed files with 97 additions and 7 deletions

View File

@@ -17,7 +17,7 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import net.kyori.adventure.text.Component;
import com.imaginarycode.minecraft.redisbungee.api.config.HandleMotdOrder;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.AbstractReconnectHandler;
import net.md_5.bungee.api.ProxyServer;
@@ -29,6 +29,7 @@ import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
import java.util.*;
@@ -42,8 +43,31 @@ public class RedisBungeeListener implements Listener {
this.plugin = plugin;
}
@EventHandler
public void onPing(ProxyPingEvent event) {
@EventHandler(priority = EventPriority.LOWEST)
private void onPingFirst(ProxyPingEvent event) {
if (plugin.configuration().handleMotdOrder() != HandleMotdOrder.FIRST) {
return;
}
onPing0(event);
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPingNormal(ProxyPingEvent event) {
if (plugin.configuration().handleMotdOrder() != HandleMotdOrder.NORMAL) {
return;
}
onPing0(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
private void onPingLast(ProxyPingEvent event) {
if (plugin.configuration().handleMotdOrder() != HandleMotdOrder.LAST) {
return;
}
onPing0(event);
}
private void onPing0(ProxyPingEvent event) {
if (!plugin.configuration().handleMotd()) return;
if (plugin.configuration().getExemptAddresses().contains(event.getConnection().getAddress().getAddress())) return;
ServerInfo forced = AbstractReconnectHandler.getForcedHost(event.getConnection());

View File

@@ -17,6 +17,7 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.api.config.HandleMotdOrder;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PluginMessageEvent;
@@ -41,8 +42,31 @@ public class RedisBungeeListener {
this.plugin = plugin;
}
@Subscribe(order = PostOrder.LAST) // some plugins changes it online players so we need to be executed as last
public void onPing(ProxyPingEvent event) {
@Subscribe(order = PostOrder.FIRST)
public void onPingFirst(ProxyPingEvent event) {
if (plugin.configuration().handleMotdOrder() != HandleMotdOrder.FIRST) {
return;
}
onPing0(event);
}
@Subscribe(order = PostOrder.NORMAL)
public void onPingNormal(ProxyPingEvent event) {
if (plugin.configuration().handleMotdOrder() != HandleMotdOrder.NORMAL) {
return;
}
onPing0(event);
}
@Subscribe(order = PostOrder.LAST)
public void onPingLast(ProxyPingEvent event) {
if (plugin.configuration().handleMotdOrder() != HandleMotdOrder.LAST) {
return;
}
onPing0(event);
}
private void onPing0(ProxyPingEvent event) {
if (!plugin.configuration().handleMotd()) return;
if (plugin.configuration().getExemptAddresses().contains(event.getConnection().getRemoteAddress().getAddress())) return;