mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-17 14:37:43 +01:00
feat: PlayerChannelUnregisterEvent (#1686)
* feat: PlayerChannelUnregisterEvent * style: fix checkstyle issues
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Velocity Contributors
|
||||||
|
*
|
||||||
|
* The Velocity API is licensed under the terms of the MIT License. For more details,
|
||||||
|
* reference the LICENSE file in the api top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.velocitypowered.api.event.player;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is fired when a client ({@link Player}) sends a plugin message through the
|
||||||
|
* unregister channel. Velocity will not wait on this event to finish firing.
|
||||||
|
*/
|
||||||
|
public final class PlayerChannelUnregisterEvent {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private final List<ChannelIdentifier> channels;
|
||||||
|
|
||||||
|
public PlayerChannelUnregisterEvent(Player player, List<ChannelIdentifier> channels) {
|
||||||
|
this.player = Preconditions.checkNotNull(player, "player");
|
||||||
|
this.channels = Preconditions.checkNotNull(channels, "channels");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ChannelIdentifier> getChannels() {
|
||||||
|
return channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PlayerChannelUnregisterEvent{"
|
||||||
|
+ "player=" + player
|
||||||
|
+ ", channels=" + channels
|
||||||
|
+ '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ import com.mojang.brigadier.suggestion.Suggestion;
|
|||||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
import com.velocitypowered.api.event.player.CookieReceiveEvent;
|
import com.velocitypowered.api.event.player.CookieReceiveEvent;
|
||||||
import com.velocitypowered.api.event.player.PlayerChannelRegisterEvent;
|
import com.velocitypowered.api.event.player.PlayerChannelRegisterEvent;
|
||||||
|
import com.velocitypowered.api.event.player.PlayerChannelUnregisterEvent;
|
||||||
import com.velocitypowered.api.event.player.PlayerClientBrandEvent;
|
import com.velocitypowered.api.event.player.PlayerClientBrandEvent;
|
||||||
import com.velocitypowered.api.event.player.TabCompleteEvent;
|
import com.velocitypowered.api.event.player.TabCompleteEvent;
|
||||||
import com.velocitypowered.api.event.player.configuration.PlayerEnteredConfigurationEvent;
|
import com.velocitypowered.api.event.player.configuration.PlayerEnteredConfigurationEvent;
|
||||||
@@ -318,8 +319,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
new PlayerChannelRegisterEvent(player, ImmutableList.copyOf(channels)));
|
new PlayerChannelRegisterEvent(player, ImmutableList.copyOf(channels)));
|
||||||
backendConn.write(packet.retain());
|
backendConn.write(packet.retain());
|
||||||
} else if (PluginMessageUtil.isUnregister(packet)) {
|
} else if (PluginMessageUtil.isUnregister(packet)) {
|
||||||
player.getClientsideChannels()
|
List<ChannelIdentifier> channels =
|
||||||
.removeAll(PluginMessageUtil.getChannels(0, packet, this.player.getProtocolVersion()));
|
PluginMessageUtil.getChannels(0, packet, this.player.getProtocolVersion());
|
||||||
|
player.getClientsideChannels().removeAll(channels);
|
||||||
|
server.getEventManager()
|
||||||
|
.fireAndForget(
|
||||||
|
new PlayerChannelUnregisterEvent(player, ImmutableList.copyOf(channels)));
|
||||||
backendConn.write(packet.retain());
|
backendConn.write(packet.retain());
|
||||||
} else if (PluginMessageUtil.isMcBrand(packet)) {
|
} else if (PluginMessageUtil.isMcBrand(packet)) {
|
||||||
String brand = PluginMessageUtil.readBrandMessage(packet.content());
|
String brand = PluginMessageUtil.readBrandMessage(packet.content());
|
||||||
|
|||||||
Reference in New Issue
Block a user