use of com.github.crashdemons.displayitem_spigot.events.ReplacedChatEvent 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);
}
}
Aggregations