下面列出了怎么用org.bukkit.command.TabCompleter的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void registerCommand(String commandName, CommandExecutor executor, String description, String usage, String... aliases) {
PluginCommand command = getCommand(commandName);
if(command == null) {
forceRegisterCommand(commandName, executor, description, usage, aliases);
return;
}
command.setExecutor(executor);
if(executor instanceof TabCompleter) {
TabCompleter completer = (TabCompleter) executor;
command.setTabCompleter(completer);
}
if(executor instanceof Listener) {
Listener listener = (Listener) executor;
PluginManager manager = Bukkit.getPluginManager();
manager.registerEvents(listener, this);
}
}
public BukkitCommand(
Plugin plugin, CommandExecutor executor, TabCompleter completer, CommandMapping command) {
super(
command.getPrimaryAlias(),
command.getDescription().getShortDescription(),
"/" + command.getPrimaryAlias() + " " + command.getDescription().getUsage(),
Lists.newArrayList(command.getAllAliases()));
this.plugin = plugin;
this.executor = executor;
this.completer = completer;
this.permissions = command.getDescription().getPermissions();
super.setPermission(Joiner.on(';').join(permissions));
}
/**
* Registers a CommandExecutor with the server
*
* @param plugin the plugin instance
* @param command the command instance
* @param permission the command permission
* @param permissionMessage the message sent when the sender doesn't the required permission
* @param description the command description
* @param aliases the command aliases
* @param <T> the command executor class type
* @return the command executor
*/
@Nonnull
public static <T extends CommandExecutor> T registerCommand(@Nonnull Plugin plugin, @Nonnull T command, String permission, String permissionMessage, String description, @Nonnull String... aliases) {
Preconditions.checkArgument(aliases.length != 0, "No aliases");
for (String alias : aliases) {
try {
PluginCommand cmd = COMMAND_CONSTRUCTOR.newInstance(alias, plugin);
getCommandMap().register(plugin.getDescription().getName(), cmd);
getKnownCommandMap().put(plugin.getDescription().getName().toLowerCase() + ":" + alias.toLowerCase(), cmd);
getKnownCommandMap().put(alias.toLowerCase(), cmd);
cmd.setLabel(alias.toLowerCase());
if (permission != null) {
cmd.setPermission(permission);
if (permissionMessage != null) {
cmd.setPermissionMessage(permissionMessage);
}
}
if (description != null) {
cmd.setDescription(description);
}
cmd.setExecutor(command);
if (command instanceof TabCompleter) {
cmd.setTabCompleter((TabCompleter) command);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return command;
}
@Override
public TabCompleter getTabCompleter() {
return new AbstractTabCompleter() {
@Override
protected List<String> getTabList(CommandSender commandSender, String term) {
return CONFIGS;
}
};
}
public ShopSubCommand(String name, boolean playerCommand, CommandExecutor executor, TabCompleter tabCompleter) {
this.name = name;
this.playerCommand = playerCommand;
this.executor = executor;
this.tabCompleter = tabCompleter;
}
@Override
public TabCompleter getTabCompleter() {
return tabCompleter;
}
@Override
public void setTabCompleter(TabCompleter tabCompleter) {
this.tabCompleter = tabCompleter;
}
@Override
public void setTabCompleter(TabCompleter tabCompleter) {
throw new IllegalArgumentException("Not allowed for built in commands");
}
@Override
public TabCompleter getTabCompleter() {
return tabCompleter;
}
@Override
public TabCompleter getTabCompleter() {
return completer;
}
@Override
public TabCompleter getTabCompleter() {
return tabCompleter;
}
public AdminCommand(final uSkyBlock plugin, ConfirmHandler confirmHandler, AnimationHandler animationHandler) {
super("usb", null, marktr("Ultimate SkyBlock Admin"));
OnlinePlayerTabCompleter playerCompleter = new OnlinePlayerTabCompleter();
TabCompleter challengeCompleter = new ChallengeTabCompleter();
TabCompleter allPlayerCompleter = new AllPlayerTabCompleter(playerCompleter);
TabCompleter biomeCompleter = new BiomeTabCompleter();
addTab("oplayer", playerCompleter);
addTab("player", allPlayerCompleter);
addTab("island", allPlayerCompleter);
addTab("leader", allPlayerCompleter);
addTab("challenge", challengeCompleter);
addTab("biome", biomeCompleter);
addTab("rank", new RankTabCompleter(plugin));
add(new ReloadCommand());
add(new ImportCommand());
add(new GenTopTenCommand(plugin));
//add(new RegisterIslandToPlayerCommand());
add(new AdminChallengeCommand(plugin));
add(new OrphanCommand(plugin));
add(new AdminIslandCommand(plugin, confirmHandler));
add(new PurgeCommand(plugin));
add(new GotoIslandCommand(plugin));
add(new AbstractPlayerInfoCommand("info", "usb.admin.info", marktr("show player-information")) {
@Override
protected void doExecute(CommandSender sender, PlayerInfo playerInfo) {
sender.sendMessage(playerInfo.toString());
}
});
add(new FlatlandFixCommand(plugin));
add(new DebugCommand(plugin));
add(new WGCommand(plugin));
add(new VersionCommand(plugin));
add(new CooldownCommand(plugin));
add(new PerkCommand(plugin));
add(new LanguageCommand(plugin));
add(new FlushCommand(plugin));
add(new JobsCommand(plugin));
add(new ConfigCommand(plugin));
add(new DocumentCommand(plugin, "doc", "usb.admin.doc"));
add(new RegionCommand(plugin, animationHandler));
add(new SetMaintenanceCommand(plugin));
add(new NBTCommand());
add(new ProtectAllCommand(plugin));
add(new ChunkCommand(plugin));
}
/**
* The constructor
*
* @param permission the permission
* @param genericCommand the generic command string
* @param usageMessage the usage message
* @param tabCompleter tab completer instance
* @param flags command flags
*/
private Command(Class<? extends CommandExecutor> commandExecutorClass, Permission permission, String genericCommand, MessageWrapper usageMessage, TabCompleter tabCompleter, Flag... flags) {
this.permission = permission;
this.usageMessage = usageMessage;
this.genericCommand = genericCommand;
this.tabCompleter = tabCompleter;
this.clazz = commandExecutorClass;
Collections.addAll(this.flags, flags);
}
/**
* Gets tab completer
*
* @return tab completer instance
*/
TabCompleter getTabCompleter();
/**
* Sets the tab completer
*
* @param tabCompleter tab completer
*/
void setTabCompleter(TabCompleter tabCompleter);
/**
* The constructor
*
* @param permission the permission
* @param genericCommand the generic command string
* @param tabCompleter tab completer instance
* @param flags command flags
*/
private Command(Class<? extends CommandExecutor> commandExecutorClass, Permission permission, String genericCommand, TabCompleter tabCompleter, Flag... flags) {
this(commandExecutorClass, permission, genericCommand, null, tabCompleter, flags);
}