当前位置: 首页>>代码示例>>Java>>正文


Java PluginCommand.setExecutor方法代码示例

本文整理汇总了Java中org.bukkit.command.PluginCommand.setExecutor方法的典型用法代码示例。如果您正苦于以下问题:Java PluginCommand.setExecutor方法的具体用法?Java PluginCommand.setExecutor怎么用?Java PluginCommand.setExecutor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.command.PluginCommand的用法示例。


在下文中一共展示了PluginCommand.setExecutor方法的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;
}
 
开发者ID:lucko,项目名称:helper,代码行数:32,代码来源:CommandMapUtil.java

示例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();
	}
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:19,代码来源:ScriptCommand.java

示例3: 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() + "\"");
    }
  }
}
 
开发者ID:CardinalDevelopment,项目名称:EllyCommand,代码行数:23,代码来源:CommandFactory.java

示例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);
}
 
开发者ID:caoli5288,项目名称:EnderChest,代码行数:19,代码来源:PluginHelper.java

示例5: 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));
}
 
开发者ID:NthPortal,项目名称:uhc-plugin,代码行数:17,代码来源:UHCPlugin.java

示例6: createPluginCommand

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
private PluginCommand createPluginCommand() {
    plugin.debug("Creating plugin command");
    try {
        Constructor<PluginCommand> c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
        c.setAccessible(true);

        PluginCommand cmd = c.newInstance(name, plugin);
        cmd.setDescription("Manage players' shops or this plugin.");
        cmd.setUsage("/" + name);
        cmd.setExecutor(new ShopBaseCommandExecutor());
        cmd.setTabCompleter(new ShopBaseTabCompleter());

        return cmd;
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
        plugin.getLogger().severe("Failed to create command");
        plugin.debug("Failed to create plugin command");
        plugin.debug(e);
    }

    return null;
}
 
开发者ID:EpicEricEE,项目名称:ShopChest,代码行数:22,代码来源:ShopCommand.java

示例7: registerCommand

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
/**
 * Registers a command in the server's CommandMap.
 *
 * @param ce CommandExecutor to be registered
 * @param rc ReflectCommand the command was annotated with
 */
public void registerCommand(@NotNull final BaseCommand<? extends Plugin> ce, @NotNull final ReflectCommand rc) {
    Preconditions.checkNotNull(ce, "ce was null");
    Preconditions.checkNotNull(rc, "rc was null");
    try {
        final Constructor c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
        c.setAccessible(true);
        final PluginCommand pc = (PluginCommand) c.newInstance(rc.name(), this.plugin);
        pc.setExecutor(ce);
        pc.setAliases(Arrays.asList(rc.aliases()));
        pc.setDescription(rc.description());
        pc.setUsage(rc.usage());
        final CommandMap cm = this.getCommandMap();
        if (cm == null) {
            this.plugin.getLogger().warning("CommandMap was null. Command " + rc.name() + " not registered.");
            return;
        }
        cm.register(this.plugin.getDescription().getName(), pc);
        this.commandHandler.addCommand(new CommandCoupling(ce, pc));
    } catch (Exception e) {
        this.plugin.getLogger().warning("Could not register command \"" + rc.name() + "\" - an error occurred: " + e.getMessage() + ".");
    }
}
 
开发者ID:Chatterbox,项目名称:Chatterbox,代码行数:29,代码来源:ReflectiveCommandRegistrar.java

示例8: registerExecutor

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
/**
 * Registers a command executor
 *
 * @param command  command enum
 * @param executor the executor
 */
public void registerExecutor(CommandWrapper command, CommandExecutor executor) {
	if(!executors.containsKey(command)) {
		executors.put(command, executor);

		if(command.hasGenericCommand()) {
			PluginCommand genericCommand = plugin.getCommand(command.getGenericCommand());

			if(executor instanceof org.bukkit.command.CommandExecutor) {
				genericCommand.setExecutor((org.bukkit.command.CommandExecutor) executor);
			}
			else {
				genericCommand.setExecutor(genericExecutor);
			}
		}

		command.setExecutor(executor);
	}
}
 
开发者ID:MarcinWieczorek,项目名称:NovaGuilds,代码行数:25,代码来源:CommandManager.java

示例9: setupCommands

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
private void setupCommands() {
	final String[] cmds = {"report", "rreport", "rep", "respond", "rrespond", "resp"};

	PluginCommand cmd = null;

	boolean error = false;

	for (final String currentCmd : cmds) {
		cmd = getCommand(currentCmd);

		if (cmd != null) {
			cmd.setExecutor(commandManager);
		} else {
			log.error(defaultConsolePrefix + "Unable to set executor for " + currentCmd + " command!");
			error = true;
		}
	}

	if (error) {
		log.warn(defaultConsolePrefix + "plugin.yml may have been altered!");
		log.warn(defaultConsolePrefix + "Please re-download the plugin from BukkitDev.");
	}
}
 
开发者ID:KabOOm356,项目名称:Reporter,代码行数:24,代码来源:Reporter.java

示例10: createPluginCommand

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
/**
 * forces to create a PluginCommand
 * 
 * @author xize
 * @param cmd - the command to be created as instance
 * @return PluginCommand
 */
@SuppressWarnings("unchecked")
public PluginCommand createPluginCommand(String cmd) {
	try {
		//forcibly make a new PluginCommand object
		Class<?> clazz = Class.forName("org.bukkit.command.PluginCommand");
		Constructor<?> constructor = clazz.getDeclaredConstructor(String.class, Plugin.class);
		constructor.setAccessible(true);
		Field mf = Constructor.class.getDeclaredField("modifiers");
		mf.setAccessible(true);
		mf.setInt(constructor, constructor.getModifiers() &~Modifier.PROTECTED);

		PluginCommand command = (PluginCommand) constructor.newInstance(cmd, pl);
		command.setExecutor(new SimpleCommand(pl));
		List<String> aliases = (List<String>) pl.getDescription().getCommands().get(command.getName()).get("aliases");
		command.setAliases(aliases);

		constructor.setAccessible(false);
		mf.setAccessible(false);

		return command;  
	} catch(Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:xEssentials,项目名称:xEssentials-deprecated-bukkit,代码行数:33,代码来源:CommandManager.java

示例11: subscribe

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
/**
 * Subscribes the commands to Bukkit commands list.
 * The commands must be registered in plugin.yml by its name.
 */
public void subscribe() {
    PluginCommand cmd = Bukkit.getPluginCommand(getName());
    if (cmd == null) {
        Uppercore.logger().severe("Command not found in plugin.yml: \"" + getName() + "\"");
        return;
    }
    setDescription(cmd.getDescription());
    cmd.setExecutor(this);
    cmd.setTabCompleter(this);
    registerPermissions(Bukkit.getPluginManager());
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:16,代码来源:Command.java

示例12: register

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
public static void register(String prefix, Plugin plugin, InjectableCommand... commands) {
  for (InjectableCommand command : commands) {
    if (command.getName() == null || command.getExecutor() == null) {
      Bukkit.getServer().getLogger().severe("Could not register command " + command.getName() + " for plugin " + plugin.getName() + ": CommandName or CommandExecutor cannot be null");
      continue;
    }
    if (command.getName().contains(":")) {
      Bukkit.getServer().getLogger().severe("Could not register command " + command.getName() + " for plugin " + plugin.getName() + ": CommandName cannot contain \":\"");
      continue;
    }
    PluginCommand _command = getPluginCommand(command.getName(), plugin);
    _command.setExecutor(command.getExecutor());
    if (command.getDescription() != null) {
      _command.setDescription(command.getDescription());
    }
    if (!(command.getAliases() == null || command.getAliases().isEmpty())) {
      _command.setAliases(command.getAliases());
    }
    if (command.getPermission() != null) {
      _command.setPermission(command.getPermission());
    }
    if (command.getPermissionMessage() != null) {
      _command.setPermissionMessage(command.getPermissionMessage());
    }
    if (command.getTabCompleter() != null) {
      _command.setTabCompleter(command.getTabCompleter());
    }
    getCommandMap().register(prefix, _command);
  }
}
 
开发者ID:Rires-Magica,项目名称:Bukkit-Utilities,代码行数:31,代码来源:CommandManager.java

示例13: registerCommand

import org.bukkit.command.PluginCommand; //导入方法依赖的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);
}
 
开发者ID:2008Choco,项目名称:DragonEggDrop,代码行数:11,代码来源:DragonEggDrop.java

示例14: Create

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
public Create(Main main) {
    this.main = main;

    PluginCommand command = main.getCommand("bpcreate");

    command.setExecutor(this);

    if (!syncConfig) {
        command.setTabCompleter(new CreateCompleter());
    }
}
 
开发者ID:michael1011,项目名称:BackPacks,代码行数:12,代码来源:Create.java

示例15: setHandleCommand

import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
@Override
public CommandManager setHandleCommand(String handle, JavaPlugin plugin) {
    if (this.handleCmd != null) {
        this.handleCmd.setExecutor(plugin);
        this.handleCmdName = null;
    }
    PluginCommand cmd = plugin.getCommand(handle);
    cmd.setExecutor(this);
    this.handleCmd = cmd;
    this.handleCmdName = cmd.getName();
    return this;
}
 
开发者ID:Yun-Shan,项目名称:Yun_Shan-Common-Library,代码行数:13,代码来源:BaseCommandManager.java


注:本文中的org.bukkit.command.PluginCommand.setExecutor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。