Skip to content

Commit b6b6df3

Browse files
committed
Added Command#onlyOp section to only allow op players to execute target command
1 parent 0a7fb64 commit b6b6df3

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>me.despical</groupId>
55
<artifactId>command-framework</artifactId>
6-
<version>1.2.2</version>
6+
<version>1.2.4</version>
77

88
<properties>
99
<java.version>8</java.version>

src/main/java/me/despical/commandframework/Command.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@
8787
int max() default -1;
8888

8989
/**
90-
* The time between using command again. Use egative
91-
* integers for infinite.
90+
* The time between using command again. Use a negative
91+
* integer for no cooldown.
9292
*
93-
* @return value of time between using command again.
93+
* @return value of time to use command again.
9494
*/
9595
int cooldown() default -1;
9696

@@ -101,6 +101,16 @@
101101
*/
102102
boolean allowInfiniteArgs() default false;
103103

104+
/**
105+
* Only op players can execute this command.
106+
* <p>
107+
* Permissions will be ignored if this option
108+
* is enabled.
109+
*
110+
* @return allow only op players.
111+
*/
112+
boolean onlyOp() default false;
113+
104114
/**
105115
* Enum value of command sender type to define who will
106116
* use the command.

src/main/java/me/despical/commandframework/CommandFramework.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class CommandFramework implements CommandExecutor, TabCompleter {
9797
public static String ONLY_BY_PLAYERS = ChatColor.RED + "This command is only executable by players!";
9898
public static String ONLY_BY_CONSOLE = ChatColor.RED + "This command is only executable by console!";
9999
public static String NO_PERMISSION = ChatColor.RED + "You don't have enough permission to execute this command!";
100+
public static String MUST_HAVE_OP = ChatColor.RED + "You must have OP to execute this command!";
100101
public static String SHORT_OR_LONG_ARG_SIZE = ChatColor.RED + "Required argument length is less or greater than needed!";
101102
public static String WAIT_BEFORE_USING_AGAIN = ChatColor.RED + "You have to wait %ds before using this command again!";
102103

@@ -338,7 +339,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.comm
338339
final Command command = entry.getKey();
339340
final String permission = command.permission();
340341

341-
if (!permission.isEmpty() && !sender.hasPermission(permission)) {
342+
if (command.onlyOp() && !sender.isOp()) {
343+
sender.sendMessage(MUST_HAVE_OP);
344+
return true;
345+
}
346+
347+
if ((!permission.isEmpty() && !sender.hasPermission(permission))) {
342348
sender.sendMessage(NO_PERMISSION);
343349
return true;
344350
}

0 commit comments

Comments
 (0)