Send proper messages when blocking a message
This commit is contained in:
parent
fc76d07b4c
commit
7603bc0db6
|
|
@ -6,9 +6,12 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -169,4 +172,23 @@ public class Utility {
|
|||
: miniMessage.parse(stringBuilder.toString());
|
||||
}
|
||||
|
||||
|
||||
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
|
||||
MiniMessage miniMessage = MiniMessage.get();
|
||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
||||
Component blockedNotification = miniMessage.parse("<red>[" + prefix + "] "
|
||||
+ getDisplayName(player.getUniqueId())
|
||||
+ (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")
|
||||
+ input + "</red>");
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
|
||||
}
|
||||
});
|
||||
player.sendMessage(miniMessage.parse("<red>The language you used in your message is not allowed, " +
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
}
|
||||
|
||||
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
|
||||
sendBlockedNotification(prefix, player, PlainComponentSerializer.plain().serialize(input), target);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,18 +38,21 @@ public class ChatHandler {
|
|||
public void privateMessage(Player player, String target, String message) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
user.setReplyTarget(target);
|
||||
message = RegexManager.replaceText(message); // todo a better way for this
|
||||
if(message == null) return; // the message was blocked
|
||||
|
||||
if(!player.hasPermission("chat.format")) {
|
||||
message = miniMessage.stripTokens(message);
|
||||
String updatedMessage = RegexManager.replaceText(message); // todo a better way for this
|
||||
if(updatedMessage == null) {
|
||||
Utility.sendBlockedNotification("DM Language", player, message, target);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
if(message.contains("[i]"))
|
||||
message = message.replace("[i]", "<[i]>");
|
||||
if(!player.hasPermission("chat.format")) {
|
||||
updatedMessage = miniMessage.stripTokens(updatedMessage);
|
||||
}
|
||||
|
||||
if(updatedMessage.contains("[i]"))
|
||||
updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
||||
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.of("message", message),
|
||||
Template.of("message", updatedMessage),
|
||||
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
|
||||
Component component = miniMessage.parse("<message>", templates);
|
||||
|
|
@ -73,20 +76,23 @@ public class ChatHandler {
|
|||
Component senderName = user.getDisplayName();
|
||||
Component prefix = user.getPrefix();
|
||||
|
||||
message = RegexManager.replaceText(message); // todo a better way for this
|
||||
if(message == null) return; // the message was blocked
|
||||
|
||||
if(!player.hasPermission("chat.format")) {
|
||||
message = miniMessage.stripTokens(message);
|
||||
String updatedMessage = RegexManager.replaceText(message); // todo a better way for this
|
||||
if(updatedMessage == null) {
|
||||
Utility.sendBlockedNotification("GC Language", player, message, "");
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
if(message.contains("[i]"))
|
||||
message = message.replace("[i]", "<[i]>"); // end of todo
|
||||
if(!player.hasPermission("chat.format")) {
|
||||
updatedMessage = miniMessage.stripTokens(updatedMessage);
|
||||
}
|
||||
|
||||
if(updatedMessage.contains("[i]"))
|
||||
updatedMessage = updatedMessage.replace("[i]", "<[i]>"); // end of todo
|
||||
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.of("sender", senderName),
|
||||
Template.of("prefix", prefix),
|
||||
Template.of("message", message),
|
||||
Template.of("message", updatedMessage),
|
||||
Template.of("server", Bukkit.getServerName()),
|
||||
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
|
||||
|
|
|
|||
|
|
@ -5,15 +5,14 @@ import com.alttd.chat.handler.ChatHandler;
|
|||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import io.papermc.paper.chat.ChatRenderer;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
|
@ -21,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChatListener implements Listener, ChatRenderer {
|
||||
|
||||
|
|
@ -41,16 +39,7 @@ public class ChatListener implements Listener, ChatRenderer {
|
|||
message = RegexManager.replaceText(message); // todo a better way for this
|
||||
if(message == null) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
||||
Component blockedNotification = miniMessage.parse("<red>[Language] "
|
||||
+ Objects.requireNonNull(player.getCustomName()) + " tried to say: "
|
||||
+ PlainComponentSerializer.plain().serialize(input) + "</red>");
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);//TODO make configurable
|
||||
}
|
||||
});
|
||||
player.sendMessage(miniMessage.parse("<red>The language you used in your message is not allowed, " +
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
Utility.sendBlockedNotification("Language", player, input, "");
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.alttd.chat.database.Queries;
|
|||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
|
@ -44,6 +45,10 @@ public class PlayerListener implements Listener {
|
|||
|
||||
message = RegexManager.replaceText(message); // todo a better way for this
|
||||
|
||||
if (message == null) {
|
||||
Utility.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), "");
|
||||
}
|
||||
|
||||
component = message == null ? Component.empty() : Component.text(message);
|
||||
|
||||
event.line(i, component);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user