From 506086f43290fd117df285a01c2d653f5faea3b2 Mon Sep 17 00:00:00 2001 From: darkcat Date: Fri, 10 Jan 2025 14:36:11 +0300 Subject: [PATCH] Use AsyncChatEvent --- build.gradle | 3 ++- .../listeners/ChatListenerWithPriority.java | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 5c32299..9d4a7a5 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ repositories { maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' } maven { url 'https://repo.xenondevs.xyz/releases' } maven { url 'https://repo.maven.apache.org/maven2/' } + maven { url 'https://repo.papermc.io/repository/maven-public/' } } dependencies { @@ -38,7 +39,7 @@ dependencies { implementation 'com.github.Anon8281:UniversalScheduler:0.1.6' - compileOnly 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT' + compileOnly 'io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT' compileOnly 'me.clip:placeholderapi:2.11.6' compileOnly 'io.lettuce:lettuce-core:6.4.0.RELEASE' compileOnly 'org.jetbrains:annotations:24.1.0' diff --git a/src/main/java/dev/unnm3d/redischat/chat/listeners/ChatListenerWithPriority.java b/src/main/java/dev/unnm3d/redischat/chat/listeners/ChatListenerWithPriority.java index 64699aa..bbdba53 100644 --- a/src/main/java/dev/unnm3d/redischat/chat/listeners/ChatListenerWithPriority.java +++ b/src/main/java/dev/unnm3d/redischat/chat/listeners/ChatListenerWithPriority.java @@ -1,47 +1,48 @@ package dev.unnm3d.redischat.chat.listeners; import dev.unnm3d.redischat.RedisChat; +import io.papermc.paper.event.player.AsyncChatEvent; import lombok.Getter; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; @Getter public enum ChatListenerWithPriority { LOWEST(new ChatListener() { @EventHandler(priority = EventPriority.LOWEST) - public void onChat(AsyncPlayerChatEvent event) { + public void onChat(AsyncChatEvent event) { listenChat(event); } }), LOW(new ChatListener() { @EventHandler(priority = EventPriority.LOW) - public void onChat(AsyncPlayerChatEvent event) { + public void onChat(AsyncChatEvent event) { listenChat(event); } }), NORMAL(new ChatListener() { @EventHandler(priority = EventPriority.NORMAL) - public void onChat(AsyncPlayerChatEvent event) { + public void onChat(AsyncChatEvent event) { listenChat(event); } }), HIGH(new ChatListener() { @EventHandler(priority = EventPriority.HIGH) - public void onChat(AsyncPlayerChatEvent event) { + public void onChat(AsyncChatEvent event) { listenChat(event); } }), HIGHEST(new ChatListener() { @EventHandler(priority = EventPriority.HIGHEST) - public void onChat(AsyncPlayerChatEvent event) { + public void onChat(AsyncChatEvent event) { listenChat(event); } }), MONITOR(new ChatListener() { @EventHandler(priority = EventPriority.MONITOR) - public void onChat(AsyncPlayerChatEvent event) { + public void onChat(AsyncChatEvent event) { listenChat(event); } }); @@ -57,10 +58,10 @@ public void onChat(AsyncPlayerChatEvent event) { private abstract static class ChatListener implements Listener { private final RedisChat plugin = RedisChat.getInstance(); - public void listenChat(AsyncPlayerChatEvent event) { + public void listenChat(AsyncChatEvent event) { if (event.isCancelled()) return; event.setCancelled(true); - plugin.getChannelManager().outgoingMessage(event.getPlayer(), event.getMessage()); + plugin.getChannelManager().outgoingMessage(event.getPlayer(), PlainTextComponentSerializer.plainText().serialize(event.message())); } } }