diff --git a/common/src/main/java/com/discordsrv/common/command/discord/commands/subcommand/ExecuteCommand.java b/common/src/main/java/com/discordsrv/common/command/discord/commands/subcommand/ExecuteCommand.java index 13ac1d24..6803fc62 100644 --- a/common/src/main/java/com/discordsrv/common/command/discord/commands/subcommand/ExecuteCommand.java +++ b/common/src/main/java/com/discordsrv/common/command/discord/commands/subcommand/ExecuteCommand.java @@ -10,7 +10,7 @@ import com.discordsrv.api.discord.events.interaction.command.DiscordCommandAutoC import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.command.game.GameCommandExecutionHelper; import com.discordsrv.common.config.main.DiscordCommandConfig; -import com.discordsrv.common.config.main.generic.GameCommandFilterConfig; +import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig; import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.NamedLogger; import net.dv8tion.jda.api.entities.Message; @@ -59,7 +59,7 @@ public class ExecuteCommand implements Consumer(), false, new ArrayList<>(Arrays.asList("list", "whitelist")) ) ); - filters.add( - new GameCommandFilterConfig( + executionConditions.add( + new GameCommandExecutionConditionConfig( new ArrayList<>(), true, new ArrayList<>(Arrays.asList( @@ -92,7 +92,7 @@ public class ConsoleConfig { public boolean enabled = true; @Comment("At least one condition has to match to allow execution") - public List filters = new ArrayList<>(); + public List executionConditions = new ArrayList<>(); @Comment("If a command is inputted starting with /, a warning response will be given if this is enabled") public boolean enableSlashWarning = true; diff --git a/common/src/main/java/com/discordsrv/common/config/main/DiscordCommandConfig.java b/common/src/main/java/com/discordsrv/common/config/main/DiscordCommandConfig.java index a67fdb2b..ab182585 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/DiscordCommandConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/DiscordCommandConfig.java @@ -1,7 +1,7 @@ package com.discordsrv.common.config.main; import com.discordsrv.common.config.configurate.annotation.Constants; -import com.discordsrv.common.config.main.generic.GameCommandFilterConfig; +import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig; import org.spongepowered.configurate.objectmapping.ConfigSerializable; import org.spongepowered.configurate.objectmapping.meta.Comment; @@ -18,8 +18,8 @@ public class DiscordCommandConfig { public static class ExecuteConfig { public ExecuteConfig() { - filters.add( - new GameCommandFilterConfig( + executionConditions.add( + new GameCommandExecutionConditionConfig( new ArrayList<>(), false, new ArrayList<>(Arrays.asList("say", "/gamemode(?: (?:survival|spectator)(?: .+)?)?/")) @@ -42,7 +42,7 @@ public class DiscordCommandConfig { public OutputMode outputMode = OutputMode.MARKDOWN; @Comment("At least one condition has to match to allow execution") - public List filters = new ArrayList<>(); + public List executionConditions = new ArrayList<>(); @Comment("If commands should be suggested while typing\n" + "Suggestions go through the server's main thread (on servers with a main thread) to ensure compatability.") diff --git a/common/src/main/java/com/discordsrv/common/config/main/generic/GameCommandFilterConfig.java b/common/src/main/java/com/discordsrv/common/config/main/generic/GameCommandExecutionConditionConfig.java similarity index 92% rename from common/src/main/java/com/discordsrv/common/config/main/generic/GameCommandFilterConfig.java rename to common/src/main/java/com/discordsrv/common/config/main/generic/GameCommandExecutionConditionConfig.java index 4b45ad7d..0a874504 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/generic/GameCommandFilterConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/generic/GameCommandExecutionConditionConfig.java @@ -12,17 +12,18 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; @ConfigSerializable -public class GameCommandFilterConfig { +public class GameCommandExecutionConditionConfig { - public GameCommandFilterConfig() {} + @SuppressWarnings("unused") // Configurate + public GameCommandExecutionConditionConfig() {} - public GameCommandFilterConfig(List roleAndUserIds, boolean blacklist, List commands) { + public GameCommandExecutionConditionConfig(List roleAndUserIds, boolean blacklist, List commands) { this.roleAndUserIds = roleAndUserIds; this.blacklist = blacklist; this.commands = commands; } - @Comment("The role and user ids which this filter applies to") + @Comment("The role and user ids that should be allowed to run the commands specified in this condition") public List roleAndUserIds = new ArrayList<>(); @Comment("true for blacklist (blocking commands), false for whitelist (allowing commands)") diff --git a/common/src/main/java/com/discordsrv/common/config/main/generic/ThreadConfig.java b/common/src/main/java/com/discordsrv/common/config/main/generic/ThreadConfig.java index d3c82547..7ec0dfcd 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/generic/ThreadConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/generic/ThreadConfig.java @@ -19,10 +19,12 @@ package com.discordsrv.common.config.main.generic; import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Comment; @ConfigSerializable public class ThreadConfig { + @Comment("Specify the text or forum channel id and the name of the thread (the thread will be automatically created if it doesn't exist)") public Long channelId = 0L; public String threadName = "Minecraft Server chat bridge"; diff --git a/common/src/main/java/com/discordsrv/common/console/SingleConsoleHandler.java b/common/src/main/java/com/discordsrv/common/console/SingleConsoleHandler.java index 258f6cc6..a07575ca 100644 --- a/common/src/main/java/com/discordsrv/common/console/SingleConsoleHandler.java +++ b/common/src/main/java/com/discordsrv/common/console/SingleConsoleHandler.java @@ -16,7 +16,7 @@ import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.command.game.GameCommandExecutionHelper; import com.discordsrv.common.config.main.ConsoleConfig; import com.discordsrv.common.config.main.generic.DestinationConfig; -import com.discordsrv.common.config.main.generic.GameCommandFilterConfig; +import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig; import com.discordsrv.common.console.entry.LogEntry; import com.discordsrv.common.console.entry.LogMessage; import com.discordsrv.common.console.message.ConsoleMessage; @@ -133,7 +133,7 @@ public class SingleConsoleHandler { } boolean pass = false; - for (GameCommandFilterConfig filter : config.commandExecution.filters) { + for (GameCommandExecutionConditionConfig filter : config.commandExecution.executionConditions) { if (filter.isAcceptableCommand(member, user, command, false, helper)) { pass = true; break; diff --git a/common/src/test/java/com/discordsrv/common/command/game/GameCommandFilterTest.java b/common/src/test/java/com/discordsrv/common/command/game/GameCommandFilterTest.java index 678c86a3..eac341a5 100644 --- a/common/src/test/java/com/discordsrv/common/command/game/GameCommandFilterTest.java +++ b/common/src/test/java/com/discordsrv/common/command/game/GameCommandFilterTest.java @@ -1,6 +1,6 @@ package com.discordsrv.common.command.game; -import com.discordsrv.common.config.main.generic.GameCommandFilterConfig; +import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionConfig; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -15,67 +15,72 @@ public class GameCommandFilterTest { @Test public void test1() { - Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test", "test", false, helper)); + Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test", "test", false, helper)); } @Test public void test2() { - Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("test", "tester", false, helper)); + Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("test", "tester", false, helper)); } @Test public void argumentTest() { - Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test arg", "test arg", false, helper)); + Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test arg", false, helper)); } @Test public void suggestTest() { - Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test arg", "test", true, helper)); + Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test", true, helper)); } @Test public void extraTest() { - Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("test arg", "test arg extra arguments after that", false, helper)); + Assertions.assertTrue( + GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test arg extra arguments after that", false, helper)); } @Test public void argumentOverflowTest1() { - Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("test arg", "test argument", false, helper)); + Assertions.assertFalse( + GameCommandExecutionConditionConfig.isCommandMatch("test arg", "test argument", false, helper)); } @Test public void sameCommandTest1() { - Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("plugin1:test", "test", false, helper)); + Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("plugin1:test", "test", false, helper)); } @Test public void sameCommandTest2() { - Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("plugin2:test", "test", false, helper)); + Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("plugin2:test", "test", false, helper)); } @Test public void regexTest1() { - Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("/test/", "test", false, helper)); + Assertions.assertTrue(GameCommandExecutionConditionConfig.isCommandMatch("/test/", "test", false, helper)); } @Test public void regexTest2() { - Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("/test/", "test extra", false, helper)); + Assertions.assertFalse(GameCommandExecutionConditionConfig.isCommandMatch("/test/", "test extra", false, helper)); } @Test public void regexTest3() { - Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("/test( argument)?/", "test argument", false, helper)); + Assertions.assertTrue( + GameCommandExecutionConditionConfig.isCommandMatch("/test( argument)?/", "test argument", false, helper)); } @Test public void regexTest4() { - Assertions.assertFalse(GameCommandFilterConfig.isCommandMatch("/test( argument)?/", "test fail", false, helper)); + Assertions.assertFalse( + GameCommandExecutionConditionConfig.isCommandMatch("/test( argument)?/", "test fail", false, helper)); } @Test public void regexTest5() { - Assertions.assertTrue(GameCommandFilterConfig.isCommandMatch("/test( argument)?/", "test", true, helper)); + Assertions.assertTrue( + GameCommandExecutionConditionConfig.isCommandMatch("/test( argument)?/", "test", true, helper)); } public static class ExecutionHelper implements GameCommandExecutionHelper {