本文整理汇总了Java中org.bukkit.command.PluginCommand.setLabel方法的典型用法代码示例。如果您正苦于以下问题:Java PluginCommand.setLabel方法的具体用法?Java PluginCommand.setLabel怎么用?Java PluginCommand.setLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.command.PluginCommand
的用法示例。
在下文中一共展示了PluginCommand.setLabel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerCommand
import org.bukkit.command.PluginCommand; //导入方法依赖的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: setupBukkitCommand
import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
private PluginCommand setupBukkitCommand() {
try {
final Constructor<PluginCommand> c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
c.setAccessible(true);
final PluginCommand bukkitCommand = c.newInstance(name, Skript.getInstance());
bukkitCommand.setAliases(aliases);
bukkitCommand.setDescription(description);
bukkitCommand.setLabel(label);
bukkitCommand.setPermission(permission);
bukkitCommand.setPermissionMessage(permissionMessage);
bukkitCommand.setUsage(usage);
bukkitCommand.setExecutor(this);
return bukkitCommand;
} catch (final Exception e) {
Skript.outdatedError(e);
throw new EmptyStacktraceException();
}
}
示例3: createNewBukkitCommand
import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
/**
* Creates a new Bukkit command.
*
* @param nukkitCommand
* The Nukkit command.
* @return The plugin command.
* @throws ClassCastException
* If the nukkitCommand is not provided by a Bukkit plugin.
*/
private PluginCommand createNewBukkitCommand(cn.nukkit.command.PluginCommand<?> nukkitCommand) {
Plugin bukkitPlugin = PokkitPlugin.toBukkit(nukkitCommand.getPlugin());
try {
Constructor<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor(String.class,
Plugin.class);
constructor.setAccessible(true);
PluginCommand bukkitCommand = constructor.newInstance(nukkitCommand.getName(), bukkitPlugin);
bukkitCommand.setAliases(Arrays.asList(nukkitCommand.getAliases()));
bukkitCommand.setDescription(nukkitCommand.getDescription());
bukkitCommand.setLabel(nukkitCommand.getLabel());
bukkitCommand.setPermission(nukkitCommand.getPermission());
bukkitCommand.setPermissionMessage(nukkitCommand.getPermissionMessage());
bukkitCommand.setUsage(nukkitCommand.getUsage());
return bukkitCommand;
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
示例4: addExecutor
import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
@SneakyThrows
public static void addExecutor(Plugin plugin, Command command) {
Field f = SimplePluginManager.class.getDeclaredField("commandMap");
f.setAccessible(true);
CommandMap map = (CommandMap) f.get(plugin.getServer().getPluginManager());
Constructor<PluginCommand> init = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
init.setAccessible(true);
PluginCommand inject = init.newInstance(command.getName(), plugin);
inject.setExecutor((who, __, label, input) -> command.execute(who, label, input));
inject.setAliases(command.getAliases());
inject.setDescription(command.getDescription());
inject.setLabel(command.getLabel());
inject.setName(command.getName());
inject.setPermission(command.getPermission());
inject.setPermissionMessage(command.getPermissionMessage());
inject.setUsage(command.getUsage());
map.register(plugin.getName().toLowerCase(), inject);
}