feat(config): add option to check commands with the chat filter

This commit is contained in:
ColdDev 2022-10-24 16:20:21 +01:00
parent 97ebb635a7
commit 98ee42ad48
8 changed files with 34 additions and 14 deletions

11
pom.xml
View File

@ -44,11 +44,12 @@
<version>2.11.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.39.3.0</version>
</dependency>
<!-- Unused until a future release -->
<!--<dependency>-->
<!-- <groupId>org.xerial</groupId>-->
<!-- <artifactId>sqlite-jdbc</artifactId>-->
<!-- <version>3.39.3.0</version>-->
<!--</dependency>-->
<dependency>
<groupId>club.minnced</groupId>
<artifactId>discord-webhooks</artifactId>

View File

@ -17,6 +17,7 @@ public class Main extends JavaPlugin implements PluginMessageListener {
setupCommands();
setupTasks();
setupPluginChannels();
getLogger().info("Initialization is complete.");
}
public void onDisable() {
@ -25,6 +26,7 @@ public class Main extends JavaPlugin implements PluginMessageListener {
}
private void setupListeners() {
getLogger().info("Initializing events...");
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
getServer().getPluginManager().registerEvents(new ChatListener(this), this);
getServer().getPluginManager().registerEvents(new CommandListener(this), this);
@ -40,6 +42,7 @@ public class Main extends JavaPlugin implements PluginMessageListener {
}
private void setupPluginChannels() {
getLogger().info("Initializing plugin channels...");
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
}
@ -48,7 +51,6 @@ public class Main extends JavaPlugin implements PluginMessageListener {
getLogger().info("Initializing config...");
getConfig().options().copyDefaults(true);
saveConfig();
getLogger().info("Done!");
}
@SuppressWarnings("UnstableApiUsage")

View File

@ -19,6 +19,7 @@ public class ChatListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (!plugin.getConfig().getBoolean("chat-filter.enabled")) return;
User user = UserManager.getUser(event.getPlayer());
String message = event.getMessage();
if (user.hasPermission("uranium.bypass")) return;
@ -45,9 +46,9 @@ public class ChatListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerChat2(AsyncPlayerChatEvent event) {
if (!plugin.getConfig().getBoolean("chat-filter.enabled")) return;
User user = UserManager.getUser(event.getPlayer());
String message = event.getMessage();
if (!plugin.getConfig().getBoolean("chat-filter.enabled")) return;
if (!StringUtil.validateMessage(message)) {
event.setCancelled(true);

View File

@ -33,6 +33,8 @@ public class CommandListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerPreprocessCommand2(PlayerCommandPreprocessEvent event) {
if (!plugin.getConfig().getBoolean("chat-filter.enabled")) return;
if (!plugin.getConfig().getBoolean("chat-filter.check-commands")) return;
User user = UserManager.getUser(event.getPlayer());
String message = event.getMessage();

View File

@ -0,0 +1,17 @@
package uranium.tasks;
import uranium.Main;
public class IPCheck implements Runnable {
private final Main plugin;
public IPCheck(Main plugin) {
this.plugin = plugin;
}
public void run() {
}
}

View File

@ -23,12 +23,7 @@ public class StringUtil {
}
private static String removeCrap(String s) {
return s
.replace(" ", "")
.replace("_", "")
.replace("*", "")
.replace(".", "")
.replace("/", ""); // TODO: Replace with regex
return s.replaceAll("[^a-zA-Z0-9]", "");
}
public static boolean validateUsername(String username) {

View File

@ -3,6 +3,8 @@ chat-filter:
enabled: true
# Should usernames be checked on join?
check-usernames: true
# Should we also check the contents of commands?
check-commands: true
# Should posting the same message twice in a row be allowed?
double-posting: false
# Should there be an enforced delay between messages?

View File

@ -1,5 +1,5 @@
name: Uranium
version: 1.0.0-LITE
version: 1.0-LITE
main: uranium.Main
description: A moderation utility for Eaglercraft 1.8 servers.
author: Cold