Skip to content

Commit

Permalink
Added optional permission to tab completer
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed Apr 4, 2023
1 parent 096c67e commit 5bc666c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To add this project as a dependency to your project, add the following to your p
<dependency>
<groupId>com.github.Despical</groupId>
<artifactId>CommandFramework</artifactId>
<version>1.1.7</version>
<version>1.1.8</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -52,7 +52,7 @@ repositories {
```
```
dependencies {
compileOnly group: "com.github.Despical", name: "CommandFramework", version: "1.1.7";
compileOnly group: "com.github.Despical", name: "CommandFramework", version: "1.1.8";
}
```

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.despical</groupId>
<artifactId>command-framework</artifactId>
<version>1.1.7</version>
<version>1.1.8</version>

<properties>
<java.version>8</java.version>
Expand Down Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>com.github.Despical</groupId>
<artifactId>Commons</artifactId>
<version>1.6.0</version>
<version>1.6.1</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull org.bu

if (entry == null) return null;

final String permission = entry.getKey().permission();

if (!permission.isEmpty() && !sender.hasPermission(permission)) return null;

try {
final Object instance = entry.getValue().getKey().invoke(entry.getValue().getValue(), new CommandArguments(sender, cmd, label, args));

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/me/despical/commandframework/Completer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.lang.annotation.Target;

/**
* An utility class in framework to create argument completions
* A utility class in framework to create argument completions
* for commands.
*
* @author Despical
Expand All @@ -42,6 +42,13 @@
*/
String name();

/**
* The permission that sender must have to receive tab complete.
*
* @return name of the permission
*/
String permission() default "";

/**
* An alternative name list of command. Check {@link #name()}
* to understand how command names work.
Expand Down

0 comments on commit 5bc666c

Please sign in to comment.