Add 'punish' filter and automatic banning functionality
Extended the RegexManager filterText method to include a 'punish' case that triggers an automatic ban for users who violate the filter. This commit also updates the PluginMessageListener to handle 'punish' commands, thus completing the execution of an auto-ban function.
This commit is contained in:
parent
8a5b407359
commit
bd8fa02f1e
|
|
@ -8,10 +8,13 @@ import com.alttd.chat.objects.ModifiableString;
|
|||
import com.alttd.chat.util.ALogger;
|
||||
import net.luckperms.api.cacheddata.CachedPermissionData;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegexManager {
|
||||
|
|
@ -43,10 +46,14 @@ public class RegexManager {
|
|||
}
|
||||
|
||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, String channel) { // TODO loop all objects in the list and check if they violate based on the MATCHER
|
||||
return filterText(playerName, uuid, modifiableString, true, channel);
|
||||
return filterText(playerName, uuid, modifiableString, true, channel, null);
|
||||
}
|
||||
|
||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel) {
|
||||
return filterText(playerName, uuid, modifiableString, matcher, channel, null);
|
||||
}
|
||||
|
||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel, Consumer<FilterType> filterAction) {
|
||||
User user = ChatAPI.get().getLuckPerms().getUserManager().getUser(uuid);
|
||||
if (user == null) {
|
||||
ALogger.warn("Tried to check chat filters for a user who doesn't exist in LuckPerms");
|
||||
|
|
@ -74,6 +81,25 @@ public class RegexManager {
|
|||
chatFilter.replaceMatcher(modifiableString);
|
||||
}
|
||||
break;
|
||||
case PUNISH:
|
||||
if (permissionData.checkPermission("chat.bypass-punish").asBoolean())
|
||||
break;
|
||||
if (chatFilter.matches(modifiableString)) {
|
||||
ALogger.info(playerName + " triggered the punish filter for " + chatFilter.getName()
|
||||
+ " with: " + modifiableString.string() + ".");
|
||||
|
||||
if (filterAction == null){
|
||||
ALogger.info("No filterAction was provided, not doing anything");
|
||||
return false;
|
||||
}
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) {
|
||||
ALogger.warn("Tried to punish a player who triggered the filter, but the player is offline.");
|
||||
return false;
|
||||
}
|
||||
filterAction.accept(FilterType.PUNISH);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ public enum FilterType {
|
|||
EMOTE("emote"),
|
||||
CHAT("chat"),
|
||||
REPLACEMATCHER("replacematcher"),
|
||||
BLOCK("block");
|
||||
BLOCK("block"),
|
||||
PUNISH("punish");
|
||||
|
||||
private final String name;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@ import com.alttd.chat.config.Config;
|
|||
import com.alttd.chat.handler.ChatHandler;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatFilter;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.ModifiableString;
|
||||
import com.alttd.chat.objects.Toggleable;
|
||||
import com.alttd.chat.objects.*;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.GalaxyUtility;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
|
|
@ -87,7 +86,16 @@ public class ChatListener implements Listener {
|
|||
ModifiableString modifiableString = new ModifiableString(input);
|
||||
|
||||
// todo a better way for this
|
||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "chat")) {
|
||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, true, "chat", filterType -> {
|
||||
if (!filterType.equals(FilterType.PUNISH)) {
|
||||
ALogger.warn("Received another FilterType than punish when filtering chat and executing a filter action");
|
||||
return;
|
||||
}
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("punish");
|
||||
out.writeUTF(player.getName());
|
||||
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
||||
})) {
|
||||
event.setCancelled(true);
|
||||
GalaxyUtility.sendBlockedNotification("Language", player,
|
||||
modifiableString.component(),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
import com.google.common.io.ByteStreams;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
|
|
@ -18,6 +19,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PluginMessageListener {
|
||||
|
|
@ -93,6 +95,13 @@ public class PluginMessageListener {
|
|||
proxy.getAllServers().forEach(registeredServer ->
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData()));
|
||||
}
|
||||
case "punish" -> {
|
||||
String playerName = in.readUTF();
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
ConsoleCommandSource consoleCommandSource = proxy.getConsoleCommandSource();
|
||||
proxy.getCommandManager().executeAsync(consoleCommandSource, String.format("ban %s Automatic ban, please appeal if you feel review is needed.", playerName));
|
||||
ALogger.info(String.format("Auto banned %s due to violating the `punish` filter.", playerName));
|
||||
}
|
||||
default -> {
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user