fix: don't track client side channels by ourselves, use API from newer Velocity

The plugin requires at least Velocity 3.0 build 490 now
This commit is contained in:
ZX夏夜之风 2025-11-09 11:21:25 +08:00
parent 016f3ad029
commit 6b6173951f
5 changed files with 8 additions and 25 deletions

@ -1 +1 @@
Subproject commit c3583e182ca6585e40d1eef0da8c18547c0b1bc1 Subproject commit b6b6b20fe97cd9cb0d6b4e817d3e7db72aca2d8d

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
networkTimeout=10000 networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -54,7 +54,7 @@ import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdenti
public class Ambassador { public class Ambassador {
//Don't forget to update checkCompatibleVersion() when changing this value //Don't forget to update checkCompatibleVersion() when changing this value
private static final String minVelocityVersion = "velocity-3.3.0-SNAPSHOT-330"; private static final String minVelocityVersion = "velocity-3.3.0-SNAPSHOT-490";
public ProxyServer server; public ProxyServer server;
public final Logger logger; public final Logger logger;
@ -64,15 +64,6 @@ public class Ambassador {
public AmbassadorConfig config; public AmbassadorConfig config;
private static final MapWithExpiration<String, RegisteredServer> TEMPORARY_FORCED = new MapWithExpiration<>(); private static final MapWithExpiration<String, RegisteredServer> TEMPORARY_FORCED = new MapWithExpiration<>();
private static final ListMultimap<String, ChannelIdentifier> PLAYER_REGISTERED_CHANNELS = ArrayListMultimap.create();
public List<ChannelIdentifier> getPlayerRegisteredChannels(String username) {
return PLAYER_REGISTERED_CHANNELS.get(username);
}
public void removePlayerRegisteredChannels(String username) {
PLAYER_REGISTERED_CHANNELS.removeAll(username);
}
private static Ambassador instance; private static Ambassador instance;
public static Ambassador getInstance() { public static Ambassador getInstance() {
@ -92,11 +83,11 @@ public class Ambassador {
boolean checkCompatibleVersion() { boolean checkCompatibleVersion() {
//Update this when changing minVelocityVersion //Update this when changing minVelocityVersion
try { try {
Class.forName("com.velocitypowered.proxy.protocol.packet.DisconnectPacket"); ConnectedPlayer.class.getMethod("getClientsideChannels");
} catch (ClassNotFoundException e) { } catch (NoSuchMethodException e) {
throw new RuntimeException(e); return false;
} }
return true; return true;
} }
@Subscribe(order = PostOrder.LAST) @Subscribe(order = PostOrder.LAST)

View File

@ -199,7 +199,7 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
return ClientResetType.CRP; return ClientResetType.CRP;
} else if (Ambassador.getInstance().config.getServerSwitchCancellationTime() >= 0 && } else if (Ambassador.getInstance().config.getServerSwitchCancellationTime() >= 0 &&
(player.getModInfo().get().getMods().stream().anyMatch((mod -> mod.getId().equals("serverredirect"))) (player.getModInfo().get().getMods().stream().anyMatch((mod -> mod.getId().equals("serverredirect")))
|| Ambassador.getInstance().getPlayerRegisteredChannels(player.getUsername()).stream().anyMatch(identifier -> identifier.getId().equals("srvredirect:red"))) || player.getClientsideChannels().stream().anyMatch(identifier -> identifier.getId().equals("srvredirect:red")))
&& player.getVirtualHost().isPresent()) { && player.getVirtualHost().isPresent()) {
return ClientResetType.SR; return ClientResetType.SR;
} }

View File

@ -75,7 +75,6 @@ public class VelocityEventHandler {
return new ModInfo.Mod(id.getId(), ""); return new ModInfo.Mod(id.getId(), "");
}).toList())); }).toList()));
*/ */
Ambassador.getInstance().getPlayerRegisteredChannels(player.getUsername()).addAll(event.getChannels());
VelocityForgeClientConnectionPhase clientPhase = (VelocityForgeClientConnectionPhase) player.getPhase(); VelocityForgeClientConnectionPhase clientPhase = (VelocityForgeClientConnectionPhase) player.getPhase();
//If reset typ is still unknown, set it! //If reset typ is still unknown, set it!
@ -83,11 +82,4 @@ public class VelocityEventHandler {
clientPhase.updateResetType(player); clientPhase.updateResetType(player);
} }
} }
// fixme remove unregistered channels when player channel unregister event is fired (that event does not exist?!)
@Subscribe
public void onPlayerDisconnectEvent(DisconnectEvent event) {
Ambassador.getInstance().removePlayerRegisteredChannels(event.getPlayer().getUsername());
}
} }