當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。