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> <version>2.11.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <!-- Unused until a future release -->
<groupId>org.xerial</groupId> <!--<dependency>-->
<artifactId>sqlite-jdbc</artifactId> <!-- <groupId>org.xerial</groupId>-->
<version>3.39.3.0</version> <!-- <artifactId>sqlite-jdbc</artifactId>-->
</dependency> <!-- <version>3.39.3.0</version>-->
<!--</dependency>-->
<dependency> <dependency>
<groupId>club.minnced</groupId> <groupId>club.minnced</groupId>
<artifactId>discord-webhooks</artifactId> <artifactId>discord-webhooks</artifactId>

View File

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

View File

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

View File

@ -33,6 +33,8 @@ public class CommandListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerPreprocessCommand2(PlayerCommandPreprocessEvent event) { 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()); User user = UserManager.getUser(event.getPlayer());
String message = event.getMessage(); 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) { private static String removeCrap(String s) {
return s return s.replaceAll("[^a-zA-Z0-9]", "");
.replace(" ", "")
.replace("_", "")
.replace("*", "")
.replace(".", "")
.replace("/", ""); // TODO: Replace with regex
} }
public static boolean validateUsername(String username) { public static boolean validateUsername(String username) {

View File

@ -3,6 +3,8 @@ chat-filter:
enabled: true enabled: true
# Should usernames be checked on join? # Should usernames be checked on join?
check-usernames: true 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? # Should posting the same message twice in a row be allowed?
double-posting: false double-posting: false
# Should there be an enforced delay between messages? # Should there be an enforced delay between messages?

View File

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