1
0

add blocked message alert

This commit is contained in:
Lee
2024-03-28 19:25:04 +00:00
parent 9a599f319e
commit 74deffbf82
6 changed files with 35 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import cc.fascinated.account.Account;
import cc.fascinated.account.AccountManager;
import cc.fascinated.config.Lang;
import cc.fascinated.utils.Manager;
import cc.fascinated.utils.MessageUtils;
import cc.fascinated.utils.Style;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
@ -38,6 +39,10 @@ public class ChatManager extends Manager {
// Check if the message contains a domain and is not the server's domain.
if (domainPattern.matcher(messageContent).find() && !messageContent.contains("aetheria.cc")) {
blockedMessage = true;
MessageUtils.messageOps(Lang.BLOCKED_MESSAGE_ALERT.getAsString()
.replace("%player%", account.getName())
.replace("%message%", messageContent)
);
}
// Block the message if it is the same as the last message sent.

View File

@ -6,6 +6,7 @@ import cc.fascinated.command.Command;
import cc.fascinated.config.Lang;
import cc.fascinated.utils.BuildData;
import cc.fascinated.utils.ChatUtils;
import cc.fascinated.utils.Style;
import net.kyori.adventure.text.Component;
import java.util.List;
@ -22,7 +23,7 @@ public class GitCommand extends Command {
List<String> voteLinks = Lang.GIT_COMMAND.getAsStringList();
for (String line : voteLinks) {
account.sendMessage(Component.text(ChatUtils.color(line)
account.sendMessage(Style.getMiniMessage().deserialize(line
.replace("%version%", buildData.getBuildVersion())
.replace("%build%", buildData.getBuildId())
.replace("%date%", buildData.getBuildDate())

View File

@ -12,6 +12,7 @@ import java.util.List;
public enum Lang {
PREFIX("prefix"),
ADMIN_PREFIX("admin-prefix"),
HELP_COMMAND("help-command"),
GIT_COMMAND("git-command"),
SEED_COMMAND("seed-command"),
@ -23,6 +24,7 @@ public enum Lang {
VOTE_COMMAND_FORMAT("vote-command.format"),
VOTE_COMMAND_LINKS("vote-command.links"),
BLOCKED_MESSAGE("blocked-message"),
BLOCKED_MESSAGE_ALERT("blocked-message-alert"),
CHAT_FORMAT("chat-format");
/**

View File

@ -0,0 +1,20 @@
package cc.fascinated.utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class MessageUtils {
/**
* Send a message to all players with OP.
*
* @param message the message to send
*/
public static void messageOps(String message) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.isOp()) {
player.sendMessage(Style.getMiniMessage().deserialize(message));
}
}
}
}

View File

@ -21,6 +21,9 @@ public class Style {
tagResolvers.add(TagResolver.resolver("prefix", (context, argumentQueue) -> {
return Tag.inserting(MiniMessage.miniMessage().deserialize(Lang.PREFIX.getAsString()));
}));
tagResolvers.add(TagResolver.resolver("admin-prefix", (context, argumentQueue) -> {
return Tag.inserting(MiniMessage.miniMessage().deserialize(Lang.ADMIN_PREFIX.getAsString()));
}));
miniMessage = MiniMessage.builder()
.tags(TagResolver.builder()

View File

@ -1,7 +1,9 @@
prefix: "<gold><bold>AETHERIA</bold></gold> <gray>»</gray> <white>"
admin-prefix: "<grey>[</grey><bold><red>ADMIN</red></bold><grey>]</grey> <white>"
chat-format: "<<%chatcolor%>%name%</%chatcolor%>> <white>%message%"
blocked-message: "<prefix><red>Your message has been blocked."
blocked-message-alert: "<admin-prefix><red>%player% <grey>tried to send a blocked message: <white>%message%"
help-command:
- "<prefix>Commands:"
@ -12,7 +14,7 @@ help-command:
git-command:
- "<prefix>Build information:"
- " <yellow>Version: <white>%version%"
- " <yellow>Build: <white>%build%"
- " <yellow>Build: <hover:show_text:Click to see the commit><click:open_url:https://git.fascinated.cc/Fascinated/aetheria-anarchy-plugin/commit/%build%><white>%build%"
- " <yellow>Build date: <white>%date%"
seed-command: "<prefix>The seed is: <hover:show_text:Click to copy the seed><click:copy_to_clipboard:%seed%><yellow>%seed%"
total-joins-command: "<prefix>Total joins: <yellow>%joins%"