Command conditions
This page explains how to use the CommandCondition interface to restrict command execution based on custom conditions
Implementing a Custom CommandCondition
CommandConditionStep 1: Define the @IsOpped Annotation
@IsOpped Annotation@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface IsOpped {}@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class IsOppedStep 2: Implement the IsOppedCondition
IsOppedConditionpublic enum IsOppedCondition implements CommandCondition<BukkitCommandActor> {
INSTANCE;
@Override
public void test(@NotNull ExecutionContext<BukkitCommandActor> context, @NotNull StringStream input) {
boolean requiresOp = context.command().annotations().contains(IsOpped.class);
if (requiresOp && !context.actor().sender().isOp()) {
throw new CommandErrorException("You must be an operator to execute this command.");
}
}
}object IsOppedCondition : CommandCondition<BukkitCommandActor> {
override fun test(context: ExecutionContext<BukkitCommandActor>, input: StringStream) {
val requiresOp = context.command().annotations().contains(IsOpped::class.java)
if (requiresOp && !context.actor().sender().isOp()) {
throw CommandErrorException("You must be an operator to execute this command.")
}
}
}
Step 3: Register the Condition
Step 4: Applying the @IsOpped Annotation to Commands
@IsOpped Annotation to CommandsLast updated
Was this helpful?