private void init() {
    PluginCommand mobeffects = plugin.getCommand("mobeffects");
    CommandExecutor exe;

    exe =
        new CommandExecutor() {
          @Override
          public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
            if (args.length < 1) {
              s.sendMessage("§eMobEffects Commands");
              s.sendMessage("§3/mobeffects reload:§f - Reloads the config.");
              s.sendMessage("§3/mobeffects version:§f - Checks your version of MobEffects");
              s.sendMessage("§3/mobeffects update:§f - Checks if there is a new version available");
              return true;
            } else if (args[0].equalsIgnoreCase("reload") && s.hasPermission("mobeffects.reload")) {
              plugin.ConfigReload();
              s.sendMessage("§aConfig reloaded");
              return true;
            } else if (args[0].equalsIgnoreCase("version")) {
              if (s.hasPermission("mobeffects.version")) {
                s.sendMessage(
                    "§eThis server is running MobEffects §4v"
                        + plugin.getDescription().getVersion());
                return true;
              } else {
                s.sendMessage("§cYou don't have permission to do that!");
              }
            }
            return true;
          }
        };
    mobeffects.setExecutor(exe);
  }
  public void registerCommands(Class<?> clazz, CommandContainer base) {
    Validate.notNull(clazz);

    Set<CommandContainer> commands =
        CommandContainer.create(clazz, base, instantiator, execution, logger);
    Iterator<CommandContainer> iterator = commands.iterator();

    while (iterator.hasNext()) {
      CommandContainer command = iterator.next();

      if (base == null) {
        if (commandMap.containsKey(command.getName())) {
          logger.warning("duplicate command " + command.getName() + "!");
          continue;
        }

        commandMap.put(command.getName(), command);

        PluginCommand bukkitCommand = plugin.getCommand(command.getName());
        if (bukkitCommand != null) {
          bukkitCommand.setExecutor(this);
        } else {
          logger.warning(
              "Command "
                  + command.getName()
                  + " registered but could not find a matching command for plugin "
                  + plugin.getName()
                  + ". Did you forget to add the command to your plugin.yml?");
        }
      } else {
        // Just add it as a child
        base.addChild(command);
      }
    }
  }
Esempio n. 3
0
 public void setAsExecutor(Command cmd) {
   cmd.setDescription(annot.desc());
   cmd.setUsage(annot.usage());
   cmd.setPermission(annot.permission());
   cmd.setAliases(new ArrayList<String>(Arrays.asList(annot.alias())));
   if (cmd instanceof PluginCommand) {
     PluginCommand pcmd = ((PluginCommand) cmd);
     pcmd.setExecutor(this);
     pcmd.setTabCompleter(this);
   }
 }
  @Override
  public void onEnable() {
    instance = this;
    if (!is1_9OrNewer) {
      System.out.println("[ForceResourcePack] The plugin work only on a 1.8 or newer version.");
      getServer().getPluginManager().disablePlugin(instance);
      return;
    }
    /*Configurations*/
    saveDefaultConfig();
    configUtils = new ConfigUtils(getConfig());
    /*Events*/
    new EventsManager(this).registerEvents();

    /*Commands*/
    final PluginCommand command = getCommand("forceresourcepack");
    command.setAliases(Collections.singletonList("frp"));
    command.setExecutor(new FrpCommand());

    /*If server was reloaded*/
    for (Player player : Bukkit.getOnlinePlayers()) new ForcePlayer(player);
  }
  public void registerCommand(JavaPlugin plugin, Class<? extends CommandExecutor> commandClass) {
    try {
      String[] commandNames = (String[]) commandClass.getField("commandNames").get(null);
      PluginCommand command = plugin.getCommand(commandNames[0]);

      if (command != null) {
        command.setExecutor(this);

        mappedCommandClasses.put(commandNames, commandClass);
        registeredExecutors.add(commandClass.newInstance());
      } else {
        Util.noticeableConsoleMessage(
            "The command: " + commandNames[0] + ", is not registered in the plugin.yml");
      }

      // Get command class from the string array
    } catch (IllegalArgumentException
        | IllegalAccessException
        | NoSuchFieldException
        | SecurityException
        | InstantiationException e) {
      // Could not instantiate command class
    }
  }
Esempio n. 6
0
  @Override
  public void registerCommands() {
    new MainCommand();
    MainCommand.subCommands.add(new Template());
    MainCommand.subCommands.add(new Setup());
    MainCommand.subCommands.add(new DebugUUID());
    MainCommand.subCommands.add(new DebugFill());
    MainCommand.subCommands.add(new DebugSaveTest());
    MainCommand.subCommands.add(new DebugLoadTest());
    MainCommand.subCommands.add(new CreateRoadSchematic());
    MainCommand.subCommands.add(new RegenAllRoads());
    MainCommand.subCommands.add(new DebugClear());
    MainCommand.subCommands.add(new Claim());
    MainCommand.subCommands.add(new Auto());
    MainCommand.subCommands.add(new Home());
    MainCommand.subCommands.add(new Visit());
    MainCommand.subCommands.add(new TP());
    MainCommand.subCommands.add(new Set());
    MainCommand.subCommands.add(new Toggle());
    MainCommand.subCommands.add(new Clear());
    MainCommand.subCommands.add(new Delete());
    MainCommand.subCommands.add(new SetOwner());
    if (Settings.ENABLE_CLUSTERS) {
      MainCommand.subCommands.add(new Cluster());
    }

    MainCommand.subCommands.add(new Trust());
    MainCommand.subCommands.add(new Add());
    MainCommand.subCommands.add(new Deny());
    MainCommand.subCommands.add(new Untrust());
    MainCommand.subCommands.add(new Remove());
    MainCommand.subCommands.add(new Undeny());

    MainCommand.subCommands.add(new Info());
    MainCommand.subCommands.add(new list());
    MainCommand.subCommands.add(new Help());
    MainCommand.subCommands.add(new Debug());
    MainCommand.subCommands.add(new SchematicCmd());
    MainCommand.subCommands.add(new plugin());
    MainCommand.subCommands.add(new Inventory());
    MainCommand.subCommands.add(new Purge());
    MainCommand.subCommands.add(new Reload());
    MainCommand.subCommands.add(new Merge());
    MainCommand.subCommands.add(new Unlink());
    MainCommand.subCommands.add(new Kick());
    MainCommand.subCommands.add(new Rate());
    MainCommand.subCommands.add(new DebugClaimTest());
    MainCommand.subCommands.add(new Inbox());
    MainCommand.subCommands.add(new Comment());
    MainCommand.subCommands.add(new Database());
    MainCommand.subCommands.add(new Unclaim());
    MainCommand.subCommands.add(new Swap());
    MainCommand.subCommands.add(new MusicSubcommand());
    MainCommand.subCommands.add(new DebugRoadRegen());
    MainCommand.subCommands.add(new Trim());
    MainCommand.subCommands.add(new DebugExec());
    MainCommand.subCommands.add(new FlagCmd());
    MainCommand.subCommands.add(new Target());
    MainCommand.subCommands.add(new DebugFixFlags());
    MainCommand.subCommands.add(new Move());
    MainCommand.subCommands.add(new Condense());
    MainCommand.subCommands.add(new Confirm());
    MainCommand.subCommands.add(new Copy());
    MainCommand.subCommands.add(new Chat());
    final BukkitCommand bcmd = new BukkitCommand();
    final PluginCommand plotCommand = getCommand("plots");
    plotCommand.setExecutor(bcmd);
    plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
    plotCommand.setTabCompleter(bcmd);
  }
  @SuppressWarnings("unchecked")
  public void register(Command command, Map<String, Object> cmdParams) {
    String cmdName = command.getCommandName();

    log.devDebug("register() command=", command, ",cmdParams=", cmdParams);
    command.setPlugin(plugin);
    command.setCommandParameters(cmdParams);

    if (cmdParams.containsKey("name")) cmdName = (String) cmdParams.get("name");

    // we never load the same command twice
    if (loadedCommands.contains(cmdName)) return;

    CraftServer cs = (CraftServer) Bukkit.getServer();
    SimpleCommandMap commandMap = cs.getCommandMap();

    try {
      Constructor<PluginCommand> constructor =
          PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
      constructor.setAccessible(true);

      // construct a new PluginCommand object
      PluginCommand pc = constructor.newInstance(cmdName, plugin);
      pc.setExecutor(command);
      pc.setLabel(cmdName);
      if (command.getUsage() != null) pc.setUsage(command.getUsage());

      // don't set Permission node, not all permission plugins behave
      // with superperms command permissions nicely.
      //			pc.setPermission(command.getCommandPermissionNode());

      // check for aliases defined in the configuration
      Object o = cmdParams.get("aliases");
      if (o != null) {
        List<String> aliases = null;
        if (o instanceof List) {
          aliases = (List<String>) o;
        } else if (o instanceof String) {
          aliases = new ArrayList<String>(2);
          aliases.add((String) o);
        } else log.warn("invalid aliases defined for command ", cmdName, ": ", o);

        if (aliases == null) aliases = new ArrayList<String>(1);

        aliases.add("hsp" + command.getCommandName()); // all commands have "hsp" prefix alias
        pc.setAliases(aliases);
      }
      // otherwise set whatever the command has defined
      else {
        List<String> aliases = new ArrayList<String>(5);
        String[] strAliases = command.getCommandAliases();
        if (strAliases != null) {
          for (String alias : strAliases) {
            aliases.add(alias);
          }
        }
        aliases.add("hsp" + command.getCommandName()); // all commands have "hsp" prefix alias
        pc.setAliases(aliases);
      }

      // register it
      commandMap.register("hsp", pc);
      loadedCommands.add(cmdName);

      Debug.getInstance().devDebug("register() command ", command, " registered");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }