13
0
geforkt von Mirrors/Velocity

Add PlayerPluginMessageRegisterEvent

Dieser Commit ist enthalten in:
Camotoy 2021-02-09 13:51:43 -05:00
Ursprung 7e42c5b2e7
Commit d47b339908
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 42 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,37 @@
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.Player;
import java.util.List;
/**
* This event is fired when a client ({@link Player}) sends a plugin message through the
* register channel.
*/
public final class PlayerPluginMessageRegisterEvent {
private final Player player;
private final List<String> channels;
public PlayerPluginMessageRegisterEvent(Player player, List<String> channels) {
this.player = Preconditions.checkNotNull(player, "player");
this.channels = Preconditions.checkNotNull(channels, "channels");
}
public Player getPlayer() {
return player;
}
public List<String> getChannels() {
return channels;
}
@Override
public String toString() {
return "PlayerPluginMessageRegisterEvent{"
+ "player=" + player
+ ", channels=" + channels
+ '}';
}
}

Datei anzeigen

@ -8,6 +8,7 @@ import static com.velocitypowered.proxy.protocol.util.PluginMessageUtil.construc
import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult;
import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.event.player.PlayerPluginMessageRegisterEvent;
import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent;
import com.velocitypowered.api.event.player.TabCompleteEvent; import com.velocitypowered.api.event.player.TabCompleteEvent;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
@ -190,7 +191,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
logger.warn("A plugin message was received while the backend server was not " logger.warn("A plugin message was received while the backend server was not "
+ "ready. Channel: {}. Packet discarded.", packet.getChannel()); + "ready. Channel: {}. Packet discarded.", packet.getChannel());
} else if (PluginMessageUtil.isRegister(packet)) { } else if (PluginMessageUtil.isRegister(packet)) {
player.getKnownChannels().addAll(PluginMessageUtil.getChannels(packet)); List<String> channels = PluginMessageUtil.getChannels(packet);
player.getKnownChannels().addAll(channels);
server.getEventManager().fireAndForget(new PlayerPluginMessageRegisterEvent(player,
channels));
backendConn.write(packet.retain()); backendConn.write(packet.retain());
} else if (PluginMessageUtil.isUnregister(packet)) { } else if (PluginMessageUtil.isUnregister(packet)) {
player.getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet)); player.getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));