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.account.AccountManager;
|
||||||
import cc.fascinated.config.Lang;
|
import cc.fascinated.config.Lang;
|
||||||
import cc.fascinated.utils.Manager;
|
import cc.fascinated.utils.Manager;
|
||||||
|
import cc.fascinated.utils.MessageUtils;
|
||||||
import cc.fascinated.utils.Style;
|
import cc.fascinated.utils.Style;
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
import net.kyori.adventure.text.Component;
|
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.
|
// Check if the message contains a domain and is not the server's domain.
|
||||||
if (domainPattern.matcher(messageContent).find() && !messageContent.contains("aetheria.cc")) {
|
if (domainPattern.matcher(messageContent).find() && !messageContent.contains("aetheria.cc")) {
|
||||||
blockedMessage = true;
|
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.
|
// 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.config.Lang;
|
||||||
import cc.fascinated.utils.BuildData;
|
import cc.fascinated.utils.BuildData;
|
||||||
import cc.fascinated.utils.ChatUtils;
|
import cc.fascinated.utils.ChatUtils;
|
||||||
|
import cc.fascinated.utils.Style;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -22,7 +23,7 @@ public class GitCommand extends Command {
|
|||||||
|
|
||||||
List<String> voteLinks = Lang.GIT_COMMAND.getAsStringList();
|
List<String> voteLinks = Lang.GIT_COMMAND.getAsStringList();
|
||||||
for (String line : voteLinks) {
|
for (String line : voteLinks) {
|
||||||
account.sendMessage(Component.text(ChatUtils.color(line)
|
account.sendMessage(Style.getMiniMessage().deserialize(line
|
||||||
.replace("%version%", buildData.getBuildVersion())
|
.replace("%version%", buildData.getBuildVersion())
|
||||||
.replace("%build%", buildData.getBuildId())
|
.replace("%build%", buildData.getBuildId())
|
||||||
.replace("%date%", buildData.getBuildDate())
|
.replace("%date%", buildData.getBuildDate())
|
||||||
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||||||
public enum Lang {
|
public enum Lang {
|
||||||
|
|
||||||
PREFIX("prefix"),
|
PREFIX("prefix"),
|
||||||
|
ADMIN_PREFIX("admin-prefix"),
|
||||||
HELP_COMMAND("help-command"),
|
HELP_COMMAND("help-command"),
|
||||||
GIT_COMMAND("git-command"),
|
GIT_COMMAND("git-command"),
|
||||||
SEED_COMMAND("seed-command"),
|
SEED_COMMAND("seed-command"),
|
||||||
@ -23,6 +24,7 @@ public enum Lang {
|
|||||||
VOTE_COMMAND_FORMAT("vote-command.format"),
|
VOTE_COMMAND_FORMAT("vote-command.format"),
|
||||||
VOTE_COMMAND_LINKS("vote-command.links"),
|
VOTE_COMMAND_LINKS("vote-command.links"),
|
||||||
BLOCKED_MESSAGE("blocked-message"),
|
BLOCKED_MESSAGE("blocked-message"),
|
||||||
|
BLOCKED_MESSAGE_ALERT("blocked-message-alert"),
|
||||||
CHAT_FORMAT("chat-format");
|
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) -> {
|
tagResolvers.add(TagResolver.resolver("prefix", (context, argumentQueue) -> {
|
||||||
return Tag.inserting(MiniMessage.miniMessage().deserialize(Lang.PREFIX.getAsString()));
|
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()
|
miniMessage = MiniMessage.builder()
|
||||||
.tags(TagResolver.builder()
|
.tags(TagResolver.builder()
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
prefix: "<gold><bold>AETHERIA</bold></gold> <gray>»</gray> <white>"
|
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%"
|
chat-format: "<<%chatcolor%>%name%</%chatcolor%>> <white>%message%"
|
||||||
blocked-message: "<prefix><red>Your message has been blocked."
|
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:
|
help-command:
|
||||||
- "<prefix>Commands:"
|
- "<prefix>Commands:"
|
||||||
@ -12,7 +14,7 @@ help-command:
|
|||||||
git-command:
|
git-command:
|
||||||
- "<prefix>Build information:"
|
- "<prefix>Build information:"
|
||||||
- " <yellow>Version: <white>%version%"
|
- " <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%"
|
- " <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%"
|
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%"
|
total-joins-command: "<prefix>Total joins: <yellow>%joins%"
|
||||||
|
Reference in New Issue
Block a user