mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2025-01-29 22:51:21 +01:00
Added support for Paper AsyncChatEvent (fixes #75)
This commit is contained in:
parent
d864bbe233
commit
550c3038b8
@ -45,6 +45,7 @@ import net.coreprotect.listener.player.SignChangeListener;
|
||||
import net.coreprotect.listener.world.LeavesDecayListener;
|
||||
import net.coreprotect.listener.world.PortalCreateListener;
|
||||
import net.coreprotect.listener.world.StructureGrowListener;
|
||||
import net.coreprotect.paper.listener.PaperChatListener;
|
||||
|
||||
public final class ListenerHandler {
|
||||
|
||||
@ -85,7 +86,6 @@ public final class ListenerHandler {
|
||||
pluginManager.registerEvents(new ArmorStandManipulateListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerBucketEmptyListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerBucketFillListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerChatListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerCommandListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerDeathListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerDropItemListener(), plugin);
|
||||
@ -101,6 +101,16 @@ public final class ListenerHandler {
|
||||
pluginManager.registerEvents(new StructureGrowListener(), plugin);
|
||||
pluginManager.registerEvents(new LeavesDecayListener(), plugin);
|
||||
pluginManager.registerEvents(new PortalCreateListener(), plugin);
|
||||
|
||||
// Paper Listeners / Fallbacks
|
||||
try {
|
||||
Class.forName("io.papermc.paper.event.player.AsyncChatEvent");
|
||||
pluginManager.registerEvents(new PaperChatListener(), plugin);
|
||||
}
|
||||
catch (Exception e) {
|
||||
pluginManager.registerEvents(new PlayerChatListener(), plugin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package net.coreprotect.paper.listener;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
|
||||
public final class PaperChatListener extends Queue implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerChat(AsyncChatEvent event) {
|
||||
String message = PlainTextComponentSerializer.plainText().serialize(event.message());
|
||||
if (message.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (!message.startsWith("/") && Config.getConfig(player.getWorld()).PLAYER_MESSAGES) {
|
||||
long timestamp = System.currentTimeMillis() / 1000L;
|
||||
Queue.queuePlayerChat(player, message, timestamp);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user