Skip to content

Commit

Permalink
implemented op only commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Badbird5907 committed Jun 13, 2022
1 parent 89216ee commit 1c184f9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface BukkitCommandSender extends CoreCommandSender {

boolean isConsole();

boolean isOp();

Player getPlayer();

UUID getUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.octopvp.commander.Commander;
import net.octopvp.commander.CommanderImpl;
import net.octopvp.commander.bukkit.annotation.ConsoleOnly;
import net.octopvp.commander.bukkit.annotation.OpOnly;
import net.octopvp.commander.bukkit.annotation.PlayerOnly;
import net.octopvp.commander.bukkit.impl.BukkitCommandSenderImpl;
import net.octopvp.commander.bukkit.impl.BukkitHelpService;
Expand Down Expand Up @@ -38,6 +39,11 @@ public static Commander getCommander(Plugin plugin) {
if (!sender.isConsole()) {
throw new CommandParseException("You must be a console to use this command.");
}
}else if (ctx.getCommandInfo().isAnnotationPresent(OpOnly.class)) {
BukkitCommandSender sender = (BukkitCommandSender) ctx.getCommandSender();
if (!sender.isOp()) {
throw new CommandParseException("You must be a console to use this command.");
}
}
})
;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.octopvp.commander.bukkit.annotation;

import net.octopvp.commander.annotation.DistributeOnMethods;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@DistributeOnMethods
public @interface OpOnly {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public boolean isConsole() {
return commandSender instanceof ConsoleCommandSender;
}

@Override
public boolean isOp() {
return commandSender.isOp();
}

@Override
public Player getPlayer() {
if (!(isPlayer())) throw new CommandException("You must be a player to do this!");
Expand Down

0 comments on commit 1c184f9

Please sign in to comment.