本文整理汇总了Java中org.bukkit.command.TabCompleter类的典型用法代码示例。如果您正苦于以下问题:Java TabCompleter类的具体用法?Java TabCompleter怎么用?Java TabCompleter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TabCompleter类属于org.bukkit.command包,在下文中一共展示了TabCompleter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerCommand
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
/**
* Registers a CommandExecutor with the server
*
* @param plugin the plugin instance
* @param command the command instance
* @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, @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());
cmd.setExecutor(command);
if (command instanceof TabCompleter) {
cmd.setTabCompleter((TabCompleter) command);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return command;
}
示例2: inject
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
/**
*
* @author jiongjionger,Vlvxingze
*/
public static void inject(Plugin plg) {
if (plg != null) {
try {
SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
for (Command command : simpleCommandMap.getCommands()) {
if (command instanceof PluginCommand) {
PluginCommand pluginCommand = (PluginCommand) command;
if (plg.equals(pluginCommand.getPlugin())) {
FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
FieldAccessor<TabCompleter> tabField = Reflection.getField(PluginCommand.class, "completer", TabCompleter.class);
CommandInjector commandInjector = new CommandInjector(plg, commandField.get(pluginCommand), tabField.get(pluginCommand));
commandField.set(pluginCommand, commandInjector);
tabField.set(pluginCommand, commandInjector);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例3: uninject
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
public static void uninject(Plugin plg) {
if (plg != null) {
try {
SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
for (Command command : simpleCommandMap.getCommands()) {
if (command instanceof PluginCommand) {
PluginCommand pluginCommand = (PluginCommand) command;
if (plg.equals(pluginCommand.getPlugin())) {
FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
FieldAccessor<TabCompleter> tabField = Reflection.getField(PluginCommand.class, "completer", TabCompleter.class);
CommandExecutor executor = commandField.get(pluginCommand);
if (executor instanceof CommandInjector) {
commandField.set(pluginCommand, ((CommandInjector) executor).getCommandExecutor());
}
TabCompleter completer = tabField.get(pluginCommand);
if (completer instanceof CommandInjector) {
tabField.set(pluginCommand, ((CommandInjector) executor).getTabCompleter());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例4: onEnable
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
@Override
public void onEnable() {
instance = this;
funcMgr = new FunctionManager(this);
cfg = new Configuration(this);
cfg.load();
i18n = new I18n(this, cfg.language);
cmd = new CommandHandler(this, i18n);
script = new ScriptsManager(this);
getCommand(PLUGIN_COMMAND_NAME).setExecutor(cmd);
getCommand(PLUGIN_COMMAND_NAME).setTabCompleter((TabCompleter) cmd);
funcMgr.registerTriggerListeners();
}
示例5: loadCommands
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void loadCommands() {
InputStream resource = getResource("META-INF/.pl.commands.yml");
if (resource == null)
return;
yamlParser.parse(resource, CommandsFile.class).blockingGet().getCommands().forEach((command, handler) -> {
PluginCommand bukkitCmd = getCommand(command);
if (bukkitCmd == null)
throw new IllegalStateException("could not find command '" + command + "' for plugin...");
Class<?> handlerType;
try {
handlerType = Class.forName(handler.handler);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("could not find class " + handler + " for command " + command + "!", e);
}
if (!JCmd.class.isAssignableFrom(handlerType)) {
if (!CommandExecutor.class.isAssignableFrom(handlerType))
throw new IllegalStateException(handlerType.getName() + " is not a valid handler class, does not extend JCmd");
CommandExecutor instance = (CommandExecutor) injector.get().getInstance(handlerType);
bukkitCmd.setExecutor(instance);
if (instance instanceof TabCompleter)
bukkitCmd.setTabCompleter((TabCompleter) instance);
} else {
Class<? extends JCmd> commandType = (Class<? extends JCmd>) handlerType;
JCommandExecutor executor = new JCommandExecutor(commandType, injector);
bukkitCmd.setExecutor(executor);
bukkitCmd.setTabCompleter(executor);
}
getLogger().info("loaded command /" + command + " => " + handlerType.getSimpleName());
});
}
示例6: tabComplete
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
List<String> completions = null;
try {
if (this.completer != null) {
completions = this.completer.onTabComplete(sender, this, alias, args);
}
if (completions == null && this.executor instanceof TabCompleter) {
completions = ((TabCompleter) this.executor).onTabComplete(sender, this, alias, args);
}
}
catch (Throwable ex) {
StringBuilder message = new StringBuilder();
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
for (String arg : args) {
message.append(arg).append(' ');
}
message.deleteCharAt(message.length() - 1).append("' in plugin ").append(this.owningPlugin.getDescription().getFullName());
throw new CommandException(message.toString(), ex);
}
if (completions == null) {
return super.tabComplete(sender, alias, args);
}
return completions;
}
示例7: tabComplete
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
@Override
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
List<String> completions = null;
try {
if (completer != null) {
completions = completer.onTabComplete(sender, this, alias, args);
}
if (completions == null && executor instanceof TabCompleter) {
completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
}
} catch (Throwable ex) {
StringBuilder message = new StringBuilder();
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
for (String arg : args) {
message.append(arg).append(' ');
}
message.deleteCharAt(message.length() - 1).append("' in plugin ")
.append(owningPlugin.getDescription().getFullName());
throw new CommandException(message.toString(), ex);
}
if (completions == null) {
return super.tabComplete(sender, alias, args);
}
return completions;
}
示例8: registerCommand
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
private void registerCommand(String command, CommandExecutor executor, TabCompleter tabCompleter) {
if (tabCompleter == null && !(executor instanceof TabCompleter))
throw new UnsupportedOperationException();
PluginCommand commandObject = this.getCommand(command);
if (commandObject == null) return;
commandObject.setExecutor(executor);
commandObject.setTabCompleter(tabCompleter != null ? tabCompleter : (TabCompleter) executor);
}
示例9: onEnable
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
@Override
public void onEnable() {
instance = this;
cfg = new Configuration(this);
cfg.load();
i18n = new I18n(this, cfg.language);
commandHandler = new CommandHandler(this, i18n);
getCommand("nyaautils").setExecutor(commandHandler);
getCommand("nyaautils").setTabCompleter((TabCompleter) commandHandler);
lpListener = new LootProtectListener(this);
dpListener = new DropProtectListener(this);
dsListener = new DamageStatListener(this);
elytraEnhanceListener = new ElytraEnhanceListener(this);
teleport = new Teleport(this);
exhibitionListener = new ExhibitionListener(this);
mailboxListener = new MailboxListener(this);
fuelManager = new FuelManager(this);
timerManager = new TimerManager(this);
timerListener = new TimerListener(this);
worldEditPlugin = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
realmListener = new RealmListener(this);
try {
systemBalance = NyaaComponent.get(ISystemBalance.class);
} catch (ComponentNotAvailableException e) {
systemBalance = null;
}
ess = (IEssentials) getServer().getPluginManager().getPlugin("Essentials");
particleTask = new ParticleTask(this);
particleListener = new ParticleListener(this);
signEditListener = new SignEditListener(this);
}
示例10: tabComplete
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
@Override
public List<String> tabComplete( CommandSender sender, String alias, String[] args )
throws CommandException, IllegalArgumentException {
checkNotNull( sender );
checkNotNull( alias );
checkNotNull( args );
List<String> completions = null;
try {
// if we have a completer, get the completions from it
if ( completer != null ) {
completions = completer.onTabComplete( sender, this, alias, args );
}
// if not succeeded, try bukkits completer
if ( completions == null && executor instanceof TabCompleter ) {
completions = ( (TabCompleter) executor ).onTabComplete( sender, this, alias, args );
}
} catch ( Throwable ex ) {
StringBuilder message = new StringBuilder();
message.append( "Unhandled exception during tab completion for command '/" ).append( alias ).append( ' ' );
for ( String arg : args ) {
message.append( arg ).append( ' ' );
}
message.deleteCharAt( message.length() - 1 ).append( "' in plugin " )
.append( plugin.getDescription().getFullName() );
throw new CommandException( message.toString(), ex );
}
if ( completions == null ) {
return super.tabComplete( sender, alias, args );
}
return completions;
}
示例11: inject
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
public static void inject(Plugin toInjectPlugin) {
PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = Reflection
.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(pluginManager);
for (Command command : commandMap.getCommands()) {
if (command instanceof PluginCommand) {
PluginIdentifiableCommand pluginCommand = (PluginIdentifiableCommand) command;
Plugin plugin = pluginCommand.getPlugin();
if (plugin.equals(toInjectPlugin)) {
FieldAccessor<CommandExecutor> executorField = Reflection
.getField(PluginCommand.class, "executor", CommandExecutor.class);
FieldAccessor<TabCompleter> completerField = Reflection
.getField(PluginCommand.class, "completer", TabCompleter.class);
CommandExecutor executor = executorField.get(pluginCommand);
TabCompleter completer = completerField.get(pluginCommand);
CommandInjector commandInjector = new CommandInjector(executor, completer);
executorField.set(pluginCommand, commandInjector);
completerField.set(pluginCommand, commandInjector);
}
}
//idea: inject also vanilla commands?
// if (command instanceof VanillaCommand) {
//
// }
}
}
示例12: uninject
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
public static void uninject(Plugin toUninject) {
PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = Reflection
.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(pluginManager);
for (Command command : commandMap.getCommands()) {
if (command instanceof PluginCommand) {
PluginIdentifiableCommand pluginCommand = (PluginIdentifiableCommand) command;
Plugin plugin = pluginCommand.getPlugin();
if (plugin.equals(toUninject)) {
FieldAccessor<CommandExecutor> executorField = Reflection
.getField(PluginCommand.class, "executor", CommandExecutor.class);
FieldAccessor<TabCompleter> completerField = Reflection
.getField(PluginCommand.class, "completer", TabCompleter.class);
CommandExecutor executor = executorField.get(pluginCommand);
if (executor instanceof CommandInjector) {
executorField.set(pluginCommand, ((CommandInjector) executor).originalExecutor);
}
TabCompleter completer = completerField.get(pluginCommand);
if (completer instanceof CommandInjector) {
completerField.set(pluginCommand, ((CommandInjector) completer).originalCompleter);
}
}
}
}
}
示例13: newCommand
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
/**
* コマンド登録メソッド
*
* @param pluginInstance プラグイン
* @param prefix prefix
* @param commandName コマンド名
* @param aliases コマンドの他の名前
* @param using コマンドの使用方法
* @param description コマンドの説明文
* @param permission コマンドの権限
* @param commandExecutor コマンドの実行クラスのインスタンス
* @param tabInstance タブ補間のインスタンス
*/
public static void newCommand(Plugin pluginInstance, String prefix, String commandName, List<String> aliases, String using, String description, String permission, CommandExecutor commandExecutor, TabCompleter tabInstance) {
CommandFactory factory = new CommandFactory(pluginInstance, commandName);
factory.setAliases((aliases == null ? new ArrayList<>(0) : aliases));
factory.setDescription((description == null ? "" : description));
factory.setUsage((using == null ? "" : using));
factory.setPermission((permission == null ? "" : permission));
if (commandExecutor != null) {
factory.setExecutor(commandExecutor);
}
if (tabInstance != null) {
factory.setTabCompleter(tabInstance);
}
factory.register();
}
示例14: getTabCompleter
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
@Override
public TabCompleter getTabCompleter() {
return new AbstractTabCompleter() {
@Override
protected List<String> getTabList(CommandSender commandSender, String term) {
return CONFIGS;
}
};
}
示例15: tabComplete
import org.bukkit.command.TabCompleter; //导入依赖的package包/类
@Override
public List<String> tabComplete(CommandSender sender, String alias,
String[] args) throws CommandException,
IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
List<String> completions = null;
try {
if (completer != null) {
completions = completer.onTabComplete(sender, this, alias,
args);
}
if (completions == null && executor instanceof TabCompleter) {
completions = ((TabCompleter) executor).onTabComplete(
sender, this, alias, args);
}
} catch (Throwable ex) {
StringBuilder message = new StringBuilder();
message.append(
"Unhandled exception during tab completion for command '/")
.append(alias).append(' ');
for (String arg : args) {
message.append(arg).append(' ');
}
message.deleteCharAt(message.length() - 1)
.append("' in plugin ")
.append(owningPlugin.getDescription().getFullName());
throw new CommandException(message.toString(), ex);
}
if (completions == null) {
return super.tabComplete(sender, alias, args);
}
return completions;
}