Search in sources :

Example 1 with ChatWrapper

use of me.dreamerzero.chatregulator.wrapper.event.ChatWrapper in project ChatRegulator by 4drian3d.

the class ChatListener method onChat.

/**
 * Chat Listener for detections
 * @param event the chat event
 * @param continuation the event cycle
 */
@Subscribe(order = PostOrder.FIRST)
public void onChat(final PlayerChatEvent event, final Continuation continuation) {
    if (!event.getResult().isAllowed()) {
        continuation.resume();
        return;
    }
    final Player player = event.getPlayer();
    final AtomicReference<String> message = new AtomicReference<String>(event.getMessage());
    final InfractionPlayer infractor = InfractionPlayer.get(player);
    final EventWrapper<PlayerChatEvent> wrapper = new ChatWrapper(event, continuation);
    if (unicode(infractor, message, wrapper, plugin) || caps(infractor, message, wrapper, plugin) || flood(infractor, message, wrapper, plugin) || regular(infractor, message, wrapper, plugin) || spam(infractor, message, wrapper, plugin)) {
        return;
    }
    if (Configuration.getConfig().getFormatConfig().enabled()) {
        message.set(Replacer.applyFormat(message.get()));
        event.setResult(ChatResult.message(message.get()));
    }
    infractor.lastMessage(message.get());
    continuation.resume();
}
Also used : InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) Player(com.velocitypowered.api.proxy.Player) PlayerChatEvent(com.velocitypowered.api.event.player.PlayerChatEvent) ChatWrapper(me.dreamerzero.chatregulator.wrapper.event.ChatWrapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

Subscribe (com.velocitypowered.api.event.Subscribe)1 PlayerChatEvent (com.velocitypowered.api.event.player.PlayerChatEvent)1 Player (com.velocitypowered.api.proxy.Player)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 InfractionPlayer (me.dreamerzero.chatregulator.InfractionPlayer)1 ChatWrapper (me.dreamerzero.chatregulator.wrapper.event.ChatWrapper)1