add blocked message alert
This commit is contained in:
@ -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.
|
||||
|
@ -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())
|
||||
|
@ -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");
|
||||
|
||||
/**
|
||||
|
20
src/main/java/cc/fascinated/utils/MessageUtils.java
Normal file
20
src/main/java/cc/fascinated/utils/MessageUtils.java
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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()
|
||||
|
Reference in New Issue
Block a user