Search in sources :

Example 1 with ChatEvent

use of net.md_5.bungee.api.event.ChatEvent in project DisplayItem-Spigot by crashdemons.

the class ChatEventExecutor method onChatInternal.

public void onChatInternal(@NotNull ChatEvent event) {
    if (event instanceof ReplacedChatEvent)
        return;
    boolean isShareCommand = event instanceof ShareCommandEvent;
    boolean isPrivateMessage = false;
    if (isShareCommand) {
        ShareCommandEvent shareEvent = (ShareCommandEvent) event;
        isPrivateMessage = shareEvent.isPrivateMessage();
    }
    Player player = event.getPlayer();
    String format = event.getFormat();
    String message = event.getMessage();
    String replacestr = DisplayItem.plugin.getConfig().getString("displayitem.replacement");
    String metareplacestr = DisplayItem.plugin.getConfig().getString("displayitem.metareplacement");
    boolean itemNeedsReplacing = message.contains(replacestr);
    if (!isShareCommand && !player.hasPermission("displayitem.replace"))
        itemNeedsReplacing = false;
    if (itemNeedsReplacing && checkSpam(player, message))
        itemNeedsReplacing = false;
    if (itemNeedsReplacing) {
        event.setCancelled(true);
        SplitChatMessage chatLineSplit = replaceItem(player, format, message, isShareCommand);
        ReplacedChatEvent replacementEvent = new ReplacedChatEvent(event);
        String legacyMessage = "";
        for (BaseComponent component : chatLineSplit.content) {
            legacyMessage += component.toLegacyText();
        }
        // DisplayItem.plugin.getLogger().info("debug: <"+legacyMessage+">");
        replacementEvent.setMessage(legacyMessage);
        replacementEvent.setMessageComponents(chatLineSplit.content);
        if (sendModifiedChatEvent && (!isPrivateMessage || !blockPrivateChatEvent)) {
            Bukkit.getServer().getPluginManager().callEvent(replacementEvent);
            if (replacementEvent.isCancelled())
                return;
        }
        for (Player p : event.getRecipients()) {
            p.spigot().sendMessage(chatLineSplit.toComponents());
        }
    }
    // make sure we replace [I]->[i] on the original event, regardless of it being cancelled.
    if ((!metareplacestr.isEmpty()) && message.contains(metareplacestr)) {
        message = message.replace(metareplacestr, replacestr);
        event.setMessage(message);
    }
}
Also used : Player(org.bukkit.entity.Player) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ShareCommandEvent(com.github.crashdemons.displayitem_spigot.events.ShareCommandEvent) ReplacedChatEvent(com.github.crashdemons.displayitem_spigot.events.ReplacedChatEvent)

Example 2 with ChatEvent

use of net.md_5.bungee.api.event.ChatEvent in project LibertyBans by A248.

the class ChatListener method onChatHigh.

@EventHandler(priority = EventPriority.HIGH)
public void onChatHigh(ChatEvent event) {
    Connection sender = event.getSender();
    if (!(sender instanceof ProxiedPlayer)) {
        return;
    }
    Component message = withdraw(event);
    if (message == null) {
        debugResultPermitted(event);
        return;
    }
    event.setCancelled(true);
    audienceRepresenter.toAudience((ProxiedPlayer) sender).sendMessage(message);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Connection(net.md_5.bungee.api.connection.Connection) Component(net.kyori.adventure.text.Component) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with ChatEvent

use of net.md_5.bungee.api.event.ChatEvent in project LibertyBans by A248.

the class ChatListenerTest method enforceMuted.

@Test
public void enforceMuted(@Mock ProxiedPlayer sender, @Mock Audience senderAudience, @Mock ProxiedPlayer receiver) {
    String message = "hello";
    ChatEvent chatEvent = new ChatEvent(sender, receiver, message);
    Component denyMessage = Component.text("Denied");
    when(guardian.checkChat(any(), (InetAddress) any(), isNull())).thenReturn(futuresFactory.completedFuture(denyMessage));
    lenient().when(guardian.checkChat(any(), (InetAddress) any(), isNotNull())).thenReturn(futuresFactory.completedFuture(null));
    when(audienceRepresenter.toAudience(sender)).thenReturn(senderAudience);
    fire(chatEvent);
    assertTrue(chatEvent.isCancelled());
    verify(senderAudience).sendMessage(denyMessage);
    verifyNoMoreInteractions(senderAudience);
}
Also used : ChatEvent(net.md_5.bungee.api.event.ChatEvent) Component(net.kyori.adventure.text.Component) Test(org.junit.jupiter.api.Test)

Example 4 with ChatEvent

use of net.md_5.bungee.api.event.ChatEvent in project LibertyBans by A248.

the class ChatListenerTest method allowNotMuted.

@Test
public void allowNotMuted(@Mock ProxiedPlayer sender, @Mock Audience senderAudience, @Mock ProxiedPlayer receiver) {
    String message = "hello";
    ChatEvent chatEvent = new ChatEvent(sender, receiver, message);
    when(guardian.checkChat(any(), (InetAddress) any(), any())).thenReturn(futuresFactory.completedFuture(null));
    lenient().when(audienceRepresenter.toAudience(sender)).thenReturn(senderAudience);
    fire(chatEvent);
    assertFalse(chatEvent.isCancelled());
    assertEquals(chatEvent.getMessage(), message, "Message untampered with");
    verifyNoMoreInteractions(senderAudience);
}
Also used : ChatEvent(net.md_5.bungee.api.event.ChatEvent) Test(org.junit.jupiter.api.Test)

Example 5 with ChatEvent

use of net.md_5.bungee.api.event.ChatEvent in project HCore by deHasher.

the class Extra method onChatEvent.

@EventHandler(priority = EventPriority.HIGHEST)
public void onChatEvent(ChatEvent e) {
    if (!(e.getSender() instanceof ProxiedPlayer))
        return;
    ProxiedPlayer player = (ProxiedPlayer) e.getSender();
    String message = e.getMessage().replace("!", "");
    if (message.startsWith("/"))
        message = message.replace("/", "");
    if (message.startsWith("/"))
        message = message.replace("/", "");
    if (!Tools.isPerm(player, Permissions.hcore_bypass_advertisement) && Methods.isAdv(message)) {
        Informer.send(player, HCore.lang.getString("errors.is-adv"));
        e.setCancelled(true);
    }
    if (Tools.isLog4j(message)) {
        for (ProxiedPlayer mod : HCore.getBungee().getPlayers()) {
            if (!Tools.isPerm(mod, Permissions.hcore_inform_log4j))
                continue;
            Informer.send(mod, HCore.lang.getString("info.log4j").replace("{player}", player.getName()).replace("{server}", player.getServer().getInfo().getName()).replace("{code}", message.replace("$", "¥")));
        }
        e.setCancelled(true);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)16 EventHandler (net.md_5.bungee.event.EventHandler)15 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 UUID (java.util.UUID)3 Component (net.kyori.adventure.text.Component)3 Connection (net.md_5.bungee.api.connection.Connection)3 ICPlaceholder (com.loohp.interactivechat.objectholders.ICPlaceholder)2 BackendInteractiveChatData (com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 ProxyServer (net.md_5.bungee.api.ProxyServer)2 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 Server (net.md_5.bungee.api.connection.Server)2 ChatEvent (net.md_5.bungee.api.event.ChatEvent)2 Test (org.junit.jupiter.api.Test)2 BungeeUser (com.alessiodp.core.bungeecord.user.BungeeUser)1 ReplacedChatEvent (com.github.crashdemons.displayitem_spigot.events.ReplacedChatEvent)1