org.bukkit.command.CommandExecutor Java Examples

The following examples show how to use org.bukkit.command.CommandExecutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StupidLogin.java    From BukkitDevelopmentNote with Apache License 2.0 6 votes vote down vote up
public void onEnable() {
	instance = this;
	
	//Configuration
	this.saveDefaultConfig();  //���Ĭ������
	//Listener
	Bukkit.getPluginManager().registerEvents(new PlayerLimitListener(), this);  //ע�������
	Bukkit.getPluginManager().registerEvents(new PlayerLoginCommand(), this);
	Bukkit.getPluginManager().registerEvents(new PlayerTipListener(), this);
	//Commands
	CommandExecutor ce = new PlayerLoginCommand();  //ע��ָ���������ָ���ͬһ��Executor
	Bukkit.getPluginCommand("login").setExecutor(ce);
	Bukkit.getPluginCommand("register").setExecutor(ce);
	
	getLogger().info("StupidLogin���������");
}
 
Example #2
Source File: HologramCommands.java    From Holograms with MIT License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length == 0) {
        sendMenu(sender);
    } else {
        String subCommand = args[0].toLowerCase();
        CommandExecutor subCommandExec = commands.get(subCommand);

        if (subCommandExec == null) {
            sendMenu(sender);
        } else if (!sender.hasPermission("holograms." + subCommand)) {
            sender.sendMessage(ChatColor.RED + command.getPermissionMessage());
        } else {
            return subCommandExec.onCommand(sender, command, label, args);
        }
    }

    return false;
}
 
Example #3
Source File: CombatLogX.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void registerCommand(String commandName, CommandExecutor executor, String description, String usage, String... aliases) {
    PluginCommand command = getCommand(commandName);
    if(command == null) {
        forceRegisterCommand(commandName, executor, description, usage, aliases);
        return;
    }
    command.setExecutor(executor);

    if(executor instanceof TabCompleter) {
        TabCompleter completer = (TabCompleter) executor;
        command.setTabCompleter(completer);
    }

    if(executor instanceof Listener) {
        Listener listener = (Listener) executor;
        PluginManager manager = Bukkit.getPluginManager();
        manager.registerEvents(listener, this);
    }
}
 
Example #4
Source File: CommandMapUtil.java    From helper with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: GameManager.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private void registerCommand(String commandName, CommandExecutor executor){
	PluginCommand command = UhcCore.getPlugin().getCommand(commandName);
	if (command == null){
		Bukkit.getLogger().warning("[UhcCore] Failed to register " + commandName + " command!");
		return;
	}

	command.setExecutor(executor);
}
 
Example #6
Source File: CombatLogX.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private void forceRegisterCommand(String commandName, CommandExecutor executor, String description, String usage, String... aliases) {
    if(commandName == null || executor == null || description == null || usage == null || aliases == null) return;

    PluginManager manager = Bukkit.getPluginManager();

    CustomCommand command = new CustomCommand(commandName, executor, description, usage, aliases);
    manager.registerEvents(command, this);

    if(executor instanceof Listener) {
        Listener listener = (Listener) executor;
        manager.registerEvents(listener, this);
    }
}
 
Example #7
Source File: BukkitCommand.java    From intake with GNU Lesser General Public License v3.0 5 votes vote down vote up
public BukkitCommand(
    Plugin plugin, CommandExecutor executor, TabCompleter completer, CommandMapping command) {
  super(
      command.getPrimaryAlias(),
      command.getDescription().getShortDescription(),
      "/" + command.getPrimaryAlias() + " " + command.getDescription().getUsage(),
      Lists.newArrayList(command.getAllAliases()));
  this.plugin = plugin;
  this.executor = executor;
  this.completer = completer;
  this.permissions = command.getDescription().getPermissions();
  super.setPermission(Joiner.on(';').join(permissions));
}
 
Example #8
Source File: CommandMapUtil.java    From helper with MIT License 5 votes vote down vote up
/**
 * Registers a CommandExecutor with the server
 *
 * @param plugin the plugin instance
 * @param command the command instance
 * @param permission the command permission
 * @param permissionMessage the message sent when the sender doesn't the required permission
 * @param description the command description
 * @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, String permission, String permissionMessage, String description, @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());
            if (permission != null) {
               cmd.setPermission(permission);
               if (permissionMessage != null) {
                   cmd.setPermissionMessage(permissionMessage);
               }
            }
            if (description != null) {
                cmd.setDescription(description);
            }

            cmd.setExecutor(command);
            if (command instanceof TabCompleter) {
                cmd.setTabCompleter((TabCompleter) command);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return command;
}
 
Example #9
Source File: CombatLogX.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
private void registerCommand(String commandName, CommandExecutor executor) {
    registerCommand(commandName, executor, null, null);
}
 
Example #10
Source File: CustomCommand.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public CustomCommand(String command, CommandExecutor executor, String description, String usage, String... aliases) {
    super(command, description, usage, Util.newList(aliases));
    this.executor = executor;
}
 
Example #11
Source File: ExtendedJavaPlugin.java    From helper with MIT License 4 votes vote down vote up
@Nonnull
@Override
public <T extends CommandExecutor> T registerCommand(@Nonnull T command, String permission, String permissionMessage, String description, @Nonnull String... aliases) {
    return CommandMapUtil.registerCommand(this, command, permission, permissionMessage, description, aliases);
}
 
Example #12
Source File: UHC.java    From UHC with MIT License 4 votes vote down vote up
protected void setupCommand(CommandExecutor executor, String... commands) {
    for (final String command : commands) {
        getCommand(command).setExecutor(executor);
    }
}
 
Example #13
Source File: ShopSubCommand.java    From ShopChest with MIT License 4 votes vote down vote up
public ShopSubCommand(String name, boolean playerCommand, CommandExecutor executor, TabCompleter tabCompleter) {
    this.name = name;
    this.playerCommand = playerCommand;
    this.executor = executor;
    this.tabCompleter = tabCompleter;
}
 
Example #14
Source File: CommandMapUtil.java    From helper with MIT License 2 votes vote down vote up
/**
 * 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) {
    return registerCommand(plugin, command, null, null, null, aliases);
}
 
Example #15
Source File: HelperPlugin.java    From helper with MIT License 2 votes vote down vote up
/**
 * Registers a CommandExecutor with the server
 *
 * @param command the command instance
 * @param permission the command permission
 * @param permissionMessage the message sent when the sender doesn't the required permission
 * @param description the command description
 * @param aliases the command aliases
 * @param <T> the command executor class type
 * @return the command executor
 */
@Nonnull
<T extends CommandExecutor> T registerCommand(@Nonnull T command, String permission, String permissionMessage, String description, @Nonnull String... aliases);
 
Example #16
Source File: HelperPlugin.java    From helper with MIT License 2 votes vote down vote up
/**
 * Registers a CommandExecutor with the server
 *
 * @param command the command instance
 * @param aliases the command aliases
 * @param <T> the command executor class type
 * @return the command executor
 */
@Nonnull
default <T extends CommandExecutor> T registerCommand(@Nonnull T command, @Nonnull String... aliases) {
    return registerCommand(command, null, null, null, aliases);
}
 
Example #17
Source File: ICombatLogX.java    From CombatLogX with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Register a command to CombatLogX
 * @param commandName The name of the command
 * @param executor The executor class of the command
 * @param description The description of the command
 * @param usage The usage of the command
 * @param aliases The alias list of the command
 * @see CommandExecutor
 */
void registerCommand(String commandName, CommandExecutor executor, String description, String usage, String... aliases);