本文整理汇总了Java中org.bukkit.command.PluginCommand类的典型用法代码示例。如果您正苦于以下问题:Java PluginCommand类的具体用法?Java PluginCommand怎么用?Java PluginCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PluginCommand类属于org.bukkit.command包,在下文中一共展示了PluginCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: unregisterCommand
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
/**
* Unregisters a CommandExecutor with the server
*
* @param command the command instance
* @param <T> the command executor class type
* @return the command executor
*/
@Nonnull
public static <T extends CommandExecutor> T unregisterCommand(@Nonnull T command) {
CommandMap map = getCommandMap();
try {
//noinspection unchecked
Map<String, Command> knownCommands = (Map<String, Command>) KNOWN_COMMANDS_FIELD.get(map);
Iterator<Command> iterator = knownCommands.values().iterator();
while (iterator.hasNext()) {
Command cmd = iterator.next();
if (cmd instanceof PluginCommand) {
CommandExecutor executor = ((PluginCommand) cmd).getExecutor();
if (command == executor) {
cmd.unregister(map);
iterator.remove();
}
}
}
} catch (Exception e) {
throw new RuntimeException("Could not unregister command", e);
}
return command;
}
示例3: inject
import org.bukkit.command.PluginCommand; //导入依赖的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();
}
}
}
示例4: uninject
import org.bukkit.command.PluginCommand; //导入依赖的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();
}
}
}
示例5: get
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
@Override
@Nullable
protected String[] get(Event arg0) {
String cmd = commandsk.getSingle(arg0);
String commandStr = cmd.startsWith("/") ? cmd.substring(1) : cmd;
PluginCommand command = Bukkit.getServer().getPluginCommand(commandStr);
if (command != null) {
if (command.getDescription() != null) {
return new String[] {command.getDescription()};
} else {
Skript.error("Command does not have a description!");
return null;
}
}
Skript.error("Command not found!");
return null;
}
示例6: get
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
@Override
@Nullable
protected String[] get(Event arg0) {
String cmd = commandsk.getSingle(arg0);
String commandStr = cmd.startsWith("/") ? cmd.substring(1) : cmd;
PluginCommand command = Bukkit.getServer().getPluginCommand(commandStr);
if (command != null) {
if (command.getPermission() != null) {
return new String[] {command.getPermission()};
} else {
Skript.error("Command does not have a permission!");
return null;
}
}
Skript.error("Command not found!");
return null;
}
示例7: getCommandTimingsByPlugin
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) {
Map<String, MonitorRecord> record = new HashMap<>();
if (plg == null) {
return record;
}
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);
CommandExecutor executor = commandField.get(pluginCommand);
if (executor instanceof CommandInjector) {
CommandInjector commandInjector = (CommandInjector) executor;
record = mergeRecordMap(record, commandInjector.getMonitorRecordMap());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return record;
}
示例8: 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();
}
}
示例9: register
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
private void register() {
for (EllyCommand command : commands) {
try {
Constructor constructor = Class.forName(PluginCommand.class.getName()).getDeclaredConstructor(String.class, Plugin.class);
constructor.setAccessible(true);
Plugin plugin = registry.getPlugin();
PluginCommand pluginCommand = (PluginCommand) constructor.newInstance(command.getName(), plugin);
pluginCommand.setAliases(command.getAliases());
pluginCommand.setDescription(command.getDescription());
pluginCommand.setExecutor(plugin);
pluginCommand.setTabCompleter(command.getTabCompleter());
pluginCommand.setUsage(command.getUsage(false));
Commands.getCommandMap().register(plugin.getName(), pluginCommand);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException
| NoSuchMethodException | ClassNotFoundException e) {
Logger.getLogger("EllyCommand").severe("Could not register command \"" + command.getName() + "\"");
}
}
}
示例10: 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);
}
}
示例11: getBukkitPluginCommand
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
/**
* Gets a command of a Bukkit plugin.
* <p>
* Multple invocations of this method with the same name will return the
* same command instance.
*
* @param name
* The command name.
* @return The command.
*/
public PluginCommand getBukkitPluginCommand(String name) {
cn.nukkit.command.PluginCommand<?> nukkitCommand = (cn.nukkit.command.PluginCommand<?>) nukkitCommandMap
.apply(name);
if (nukkitCommand == null) {
// No command exists with that name
return null;
}
if (!(nukkitCommand.getPlugin() instanceof PokkitPlugin)) {
// Command not provided by a Bukkit plugin
return null;
}
PluginCommand bukkitCommand = toBukkitCommand.get(nukkitCommand);
if (bukkitCommand == null) {
bukkitCommand = createNewBukkitCommand(nukkitCommand);
toBukkitCommand.put(nukkitCommand, bukkitCommand);
}
return bukkitCommand;
}
示例12: 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);
}
示例13: createInstance
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
private PluginCommand createInstance() {
if (pluginInstance == null) {
throw new IllegalArgumentException("instance is null.");
}
if (commandName == null || commandName.isEmpty()) {
throw new IllegalArgumentException("command is null.");
}
PluginCommand commandInstance = null;
try {
Constructor<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
constructor.setAccessible(true);
commandInstance = constructor.newInstance(commandName, pluginInstance);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return commandInstance;
}
示例14: onEnable
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
@Override
public void onEnable() {
Config.setup(this);
PluginCommand mainCommand = getCommand(MainCommandExecutor.NAME);
mainCommand.setExecutor(new MainCommandExecutor(this));
mainCommand.setTabCompleter(new MainCommandTabCompleter());
PluginCommand confCommand = getCommand(ConfCommandExecutor.NAME);
confCommand.setExecutor(new ConfCommandExecutor(this));
confCommand.setTabCompleter(new ConfCommandTabCompleter());
getServer().getPluginManager().registerEvents(new CustomListener(this), this);
eventBus.register(new MainListener(this));
}
示例15: PlayerCommand
import org.bukkit.command.PluginCommand; //导入依赖的package包/类
@EventHandler
public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
final String message = event.getMessage().toLowerCase().replaceAll("/", "");
String[] split = message.split(" ");
PluginCommand cmd = Bukkit.getServer().getPluginCommand(split[0]);
if (cmd != null) {
return;
}
if (split[0].equals("plotme") || split[0].equals("ap")) {
final Player player = event.getPlayer();
if (Settings.USE_PLOTME_ALIAS) {
player.performCommand("plots " + StringUtils.join(Arrays.copyOfRange(split, 1, split.length), " "));
} else {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
}
event.setCancelled(true);
}
}