Skip to content

Commit

Permalink
Merge pull request #19 from ArcanePlugins/ver/1.1.x
Browse files Browse the repository at this point in the history
Ver/1.1.x
  • Loading branch information
lokka30 authored Jan 18, 2025
2 parents 4fc8fbb + 74b66dc commit 61efc24
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
4 changes: 2 additions & 2 deletions blackwidowlib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<parent>
<groupId>io.github.arcaneplugins.blackwidow</groupId>
<artifactId>blackwidow</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</parent>

<artifactId>blackwidowlib</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -150,6 +151,77 @@ public void testChainsMustStartWithSlash() {
}
}

/**
* Ensures wildcard base command rules detect all base commands.
*
* @author lokka30
* @since 1.1.5
*/
@Test
public void testWildcardBaseCmd() {
final BiFunction<String, Policy, Boolean> test = (cmd, policy) -> {
final Evaluation eval = Evaluator.evaluate(
"/hello",
Collections.singletonList(new Chain(
"wildcard-base-cmd",
true,
Policy.DENY,
Collections.singletonList("/*"),
false,
EvalCause.setValues()
)),
Policy.ALLOW,
false,
EvalCause.CMD_EXECUTION,
debugLogger,
warningLogger
);

return eval.policy() == policy && !eval.dueToException();
};

Assertions.assertTrue(test.apply("/hello", Policy.DENY), "failed wildcard base cmd match");
Assertions.assertTrue(test.apply("/something abc", Policy.DENY), "failed wildcard base cmd match with an argument");
}

/**
* Ensures wildcard argument command rules detect all command arguments.
*
* @author lokka30
* @since 1.1.5
*/
@Test
public void testWildcardArgs() {
final BiFunction<String, Policy, Boolean> test = (cmd, policy) -> {
final Evaluation eval = Evaluator.evaluate(
cmd,
Collections.singletonList(new Chain(
"wildcard-arg-cmd",
true,
policy,
Collections.singletonList("/hello * world *"),
false,
EvalCause.setValues()
)),
Policy.ALLOW,
false,
EvalCause.CMD_EXECUTION,
debugLogger,
warningLogger
);

return eval.policy() == policy && !eval.dueToException();
};

Assertions.assertTrue(test.apply("/hello something world anything123", Policy.DENY));
Assertions.assertTrue(test.apply("/hello another world thing withmorestuff at the end", Policy.DENY));
Assertions.assertTrue(test.apply("/hello * world *", Policy.DENY));
Assertions.assertTrue(test.apply("/hello * world * hasmorestuff", Policy.DENY));

Assertions.assertTrue(test.apply("/nothello a world a", Policy.ALLOW));
Assertions.assertTrue(test.apply("/hello something notworld anotherthinghere", Policy.ALLOW));
}

/**
* Example to ensure all commands expected to be denied are.. denied.
*
Expand Down
6 changes: 3 additions & 3 deletions blackwidowpluginbukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<parent>
<groupId>io.github.arcaneplugins.blackwidow</groupId>
<artifactId>blackwidow</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</parent>

<artifactId>blackwidowpluginbukkit</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>

<properties>
<maven.compiler.source>21</maven.compiler.source>
Expand All @@ -47,7 +47,7 @@
<dependency>
<groupId>io.github.arcaneplugins.blackwidow</groupId>
<artifactId>blackwidowlib</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public final class HasPermissionRequirement extends Requirement {

public static final String ID = "has-perission";
public static final String ID = "has-permission";

private final String permission;

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<groupId>io.github.arcaneplugins.blackwidow</groupId>
<artifactId>blackwidow</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<packaging>pom</packaging>
<modules>
<module>blackwidowlib</module>
Expand Down

0 comments on commit 61efc24

Please sign in to comment.