Move preview listener into ChatMessageListener

This commit is contained in:
Noel Németh 2022-06-10 22:09:46 +02:00
parent ab84bd63b3
commit d0a7f4544b
3 changed files with 9 additions and 16 deletions

View File

@ -6,12 +6,15 @@ import net.minestom.server.command.CommandManager;
import net.minestom.server.entity.Player;
import net.minestom.server.event.EventDispatcher;
import net.minestom.server.event.player.PlayerChatEvent;
import net.minestom.server.event.player.PlayerChatPreviewEvent;
import net.minestom.server.message.ChatPosition;
import net.minestom.server.message.MessageSender;
import net.minestom.server.message.Messenger;
import net.minestom.server.network.ConnectionManager;
import net.minestom.server.network.packet.client.play.ClientChatMessagePacket;
import net.minestom.server.network.packet.client.play.ClientChatPreviewPacket;
import net.minestom.server.network.packet.client.play.ClientCommandChatPacket;
import net.minestom.server.network.packet.server.play.ChatPreviewPacket;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -70,4 +73,9 @@ public class ChatMessageListener {
return Component.text(message);
}
public static void previewListener(ClientChatPreviewPacket packet, Player player) {
final PlayerChatPreviewEvent event = new PlayerChatPreviewEvent(player, packet.queryId(), packet.query());
MinecraftServer.getGlobalEventHandler().callCancellable(event,
() -> player.sendPacket(new ChatPreviewPacket(event.getId(), event.getResult())));
}
}

View File

@ -1,15 +0,0 @@
package net.minestom.server.listener;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerChatPreviewEvent;
import net.minestom.server.network.packet.client.play.ClientChatPreviewPacket;
import net.minestom.server.network.packet.server.play.ChatPreviewPacket;
public class ChatPreviewListener {
public static void listener(ClientChatPreviewPacket packet, Player player) {
final PlayerChatPreviewEvent event = new PlayerChatPreviewEvent(player, packet.queryId(), packet.query());
MinecraftServer.getGlobalEventHandler().callCancellable(event,
() -> player.sendPacket(new ChatPreviewPacket(event.getId(), event.getResult())));
}
}

View File

@ -57,7 +57,7 @@ public final class PacketListenerManager {
setListener(ClientAdvancementTabPacket.class, AdvancementTabListener::listener);
setListener(ClientSpectatePacket.class, SpectateListener::listener);
setListener(ClientEditBookPacket.class, BookListener::listener);
setListener(ClientChatPreviewPacket.class, ChatPreviewListener::listener);
setListener(ClientChatPreviewPacket.class, ChatMessageListener::previewListener);
}
/**