From f01997baa30edc12355c6326b917f1f38ab643dc Mon Sep 17 00:00:00 2001 From: A248 Date: Fri, 18 Aug 2023 19:25:23 -0500 Subject: [PATCH] Fix a test I broke again --- .../extra/StandardArgumentParser.java | 22 ++++++++++--------- .../extra/StandardArgumentParserTest.java | 12 ++++------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/bans-core/src/main/java/space/arim/libertybans/core/commands/extra/StandardArgumentParser.java b/bans-core/src/main/java/space/arim/libertybans/core/commands/extra/StandardArgumentParser.java index e183377a7..6279e2e81 100644 --- a/bans-core/src/main/java/space/arim/libertybans/core/commands/extra/StandardArgumentParser.java +++ b/bans-core/src/main/java/space/arim/libertybans/core/commands/extra/StandardArgumentParser.java @@ -184,16 +184,18 @@ private MessagesConfig.All.NotFound notFound() { } return how.defaultValue(scopeManager); } - String permissionSuffix = scopeManager.deconstruct(explicitScope, (type, value) -> { - return switch (type) { - case GLOBAL -> "global"; - case SERVER -> "server." + value; - case CATEGORY -> "category." + value; - }; - }); - if (requirePermissions && !sender.hasPermission("libertybans.scope." + permissionSuffix)) { - sender.sendMessage(all().scopes().noPermission().replaceText("%SCOPE%", formatter.formatScope(explicitScope))); - return null; + if (requirePermissions) { + String permissionSuffix = scopeManager.deconstruct(explicitScope, (type, value) -> { + return switch (type) { + case GLOBAL -> "global"; + case SERVER -> "server." + value; + case CATEGORY -> "category." + value; + }; + }); + if (!sender.hasPermission("libertybans.scope." + permissionSuffix)) { + sender.sendMessage(all().scopes().noPermission().replaceText("%SCOPE%", formatter.formatScope(explicitScope))); + return null; + } } return how.explicitScope(explicitScope); } diff --git a/bans-core/src/test/java/space/arim/libertybans/core/commands/extra/StandardArgumentParserTest.java b/bans-core/src/test/java/space/arim/libertybans/core/commands/extra/StandardArgumentParserTest.java index 110a99ae5..ddc149dd3 100644 --- a/bans-core/src/test/java/space/arim/libertybans/core/commands/extra/StandardArgumentParserTest.java +++ b/bans-core/src/test/java/space/arim/libertybans/core/commands/extra/StandardArgumentParserTest.java @@ -42,11 +42,11 @@ import space.arim.libertybans.core.commands.ComponentMatcher; import space.arim.libertybans.core.config.Configs; import space.arim.libertybans.core.config.MessagesConfig; +import space.arim.libertybans.core.config.ScopeConfig; import space.arim.libertybans.core.env.CmdSender; import space.arim.libertybans.core.env.UUIDAndAddress; import space.arim.libertybans.core.scope.InternalScopeManager; import space.arim.libertybans.core.scope.ScopeParsing; -import space.arim.libertybans.core.scope.ScopeType; import space.arim.libertybans.core.uuid.UUIDManager; import space.arim.libertybans.it.util.RandomUtil; import space.arim.omnibus.util.concurrent.CentralisedFuture; @@ -56,7 +56,6 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.function.BiFunction; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -310,7 +309,7 @@ public void unknownAddressVictimForName() { public class ParseScopeFromCommand { @BeforeEach - public void setup() { + public void setup(@Mock ScopeConfig scopeConfig) { lenient().when(scopeManager.parseFrom(any())).thenAnswer((invocation) -> { return new ScopeParsing() { @Override @@ -329,11 +328,8 @@ public ServerScope globalScope() { } }.parseInputOptionally(invocation.getArgument(0)); }); - lenient().when(scopeManager.deconstruct(any(), any())).thenAnswer((invocation) -> { - BiFunction computeResult = invocation.getArgument(1); - return computeResult.apply(ScopeType.GLOBAL, ""); - }); - when(sender.hasPermission(any())).thenReturn(true); + when(configs.getScopeConfig()).thenReturn(scopeConfig); + when(scopeConfig.requirePermissions()).thenReturn(false); } @Test