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);
}
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations