本文整理汇总了Java中org.bukkit.command.PluginIdentifiableCommand类的典型用法代码示例。如果您正苦于以下问题:Java PluginIdentifiableCommand类的具体用法?Java PluginIdentifiableCommand怎么用?Java PluginIdentifiableCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PluginIdentifiableCommand类属于org.bukkit.command包,在下文中一共展示了PluginIdentifiableCommand类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: register
import org.bukkit.command.PluginIdentifiableCommand; //导入依赖的package包/类
@Override
public boolean register(String label, String fallbackPrefix, Command command) {
// TODO: Label
// TODO: Fallback prefix
Object plugin = Pore.getPlugin();
if (command instanceof PluginIdentifiableCommand) {
plugin = Pore.getPlugin(((PluginIdentifiableCommand) command).getPlugin());
}
List<String> aliases = Lists.newArrayList(command.getAliases());
String name = command.getName();
if (!name.equals(label)) {
aliases.add(0, label);
}
aliases.add(0, name);
Optional<CommandMapping> result = handle.register(plugin, new PoreCommandCallable(command), aliases);
if (result.isPresent()) {
command.register(this);
return true;
} else {
return false;
}
}
示例2: inject
import org.bukkit.command.PluginIdentifiableCommand; //导入依赖的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) {
//
// }
}
}
示例3: uninject
import org.bukkit.command.PluginIdentifiableCommand; //导入依赖的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);
}
}
}
}
}
示例4: registerCommand
import org.bukkit.command.PluginIdentifiableCommand; //导入依赖的package包/类
/**
* Attempts to register a command with the corresponding server's command map. Note that this method uses Reflection
* to access the command map and may fail due to that. The command map is cached once retrieved.
*
* @param command the command to register
* @throws IllegalStateException if retrieval of the command map fails
* @deprecated This method always uses the static fallback prefix "mtc". Prefer {@link #registerCommand(Command,
* String)}.
*/
@Deprecated
public <T extends Command & PluginIdentifiableCommand> void registerCommand(T command) throws IllegalStateException {
registerCommand(command, "mtc");
}