Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new annotation to hide commands from tabcompletion and help #124

Merged
merged 2 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/java/co/aikar/commands/BaseCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ List<String> getCommandsForCompletion(CommandIssuer issuer, String[] args) {
continue;
}

if(value.isPrivate){
continue;
}

String[] split = ACFPatterns.SPACE.split(value.prefSubCommand);
cmds.add(split[cmdIndex]);
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/co/aikar/commands/CommandHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public CommandHelp(CommandManager manager, RootCommand rootCommand, CommandIssue
}

RegisteredCommand regCommand = e.getValue();
if (regCommand.hasPermission(issuer) && !seen.contains(regCommand)) {

if (!regCommand.isPrivate && regCommand.hasPermission(issuer) && !seen.contains(regCommand)) {
this.helpEntries.add(new HelpEntry(this, regCommand));
seen.add(regCommand);
}
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/co/aikar/commands/RegisteredCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.HelpSearchTags;
import co.aikar.commands.annotation.Private;
import co.aikar.commands.annotation.Syntax;
import co.aikar.commands.contexts.ContextResolver;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
String conditions;
public String helpSearchTags;

boolean isPrivate;

final int requiredResolvers;
final int consumeInputResolvers;
final int doesNotConsumeInputResolvers;
Expand All @@ -82,7 +85,7 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
this.prefSubCommand = prefSubCommand;

this.permission = annotations.getAnnotationValue(method, CommandPermission.class, Annotations.REPLACEMENTS | Annotations.NO_EMPTY);
this.complete = annotations.getAnnotationValue(method, CommandCompletion.class);
this.complete = annotations.getAnnotationValue(method, CommandCompletion.class);
this.helpText = annotations.getAnnotationValue(method, Description.class, Annotations.REPLACEMENTS | Annotations.DEFAULT_EMPTY);
this.conditions = annotations.getAnnotationValue(method, Conditions.class, Annotations.REPLACEMENTS | Annotations.NO_EMPTY);
this.helpSearchTags = annotations.getAnnotationValue(method, HelpSearchTags.class, Annotations.REPLACEMENTS | Annotations.NO_EMPTY);
Expand All @@ -91,6 +94,7 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
//noinspection unchecked
this.parameters = new CommandParameter[parameters.length];

this.isPrivate = annotations.hasAnnotation(method, Private.class);

int requiredResolvers = 0;
int consumeInputResolvers = 0;
Expand Down
34 changes: 34 additions & 0 deletions core/src/main/java/co/aikar/commands/annotation/Private.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2016-2018 Daniel Ennis (Aikar) - MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package co.aikar.commands.annotation;

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

/**
* Marks a command to not be included in stuff like tab completion and help pages
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface Private {
}
3 changes: 3 additions & 0 deletions example/src/main/java/co/aikar/acfexample/ACFExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ private void registerCommands() {
// 1: Create Command Manager for your respective platform
commandManager = new BukkitCommandManager(this);

// optional: enable unstable api to use help
commandManager.enableUnstableAPI("help");

// 2: Setup some replacement values that may be used inside of the annotations dynamically.
commandManager.getCommandReplacements().addReplacements(
// key - value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
package co.aikar.acfexample;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandHelp;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.HelpCommand;
import co.aikar.commands.annotation.Private;
import co.aikar.commands.annotation.Subcommand;
import org.bukkit.command.CommandSender;

Expand All @@ -37,4 +40,15 @@ public class SomeCommand_ExtraSubs extends BaseCommand {
public void onTestSub2(CommandSender sender, String hi) {
sender.sendMessage(hi);
}

@Private
@Subcommand("testsub private")
public void privateSub(CommandSender sender){
sender.sendMessage("Am a sneaky ninja!");
}

@HelpCommand
public void help(CommandSender sender, CommandHelp help){
help.showHelp();
}
}