Пример #1
0
 private void register() {
   try {
     Field f =
         Class.forName("org.bukkit.craftbukkit." + VERSION + ".CraftServer")
             .getDeclaredField("commandMap");
     f.setAccessible(true);
     CommandMap map = (CommandMap) f.get(Bukkit.getServer());
     map.register(this.plugin.getName(), this);
   } catch (Exception exc) {
     exc.printStackTrace();
   }
 }
Пример #2
0
  /**
   * Used by the {@link CmdRegistration} to register the command.
   *
   * <p><b>Do not call this to register a command!</b>
   *
   * <p>You'll have to use {@link CmdRegistration#register(Plugin, BaseCmd)} to register a command
   * properly! Also don't forget to call {@link CmdRegistration#unregister(Plugin)} in onDisable()
   *
   * @param plugin The plugin that registered the command.
   * @throws CmdAlreadyRegisteredException When the command is already registered.
   */
  public void register(Plugin plugin) throws CmdAlreadyRegisteredException {
    setUsage(getUsage(plugin.getServer().getConsoleSender(), getBaseCmd().getName()));

    if (this.plugin != null) {
      throw new CmdAlreadyRegisteredException(plugin, this);
    }
    this.plugin = plugin;

    try {
      Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
      f.setAccessible(true);
      CommandMap commandMap = (CommandMap) f.get(Bukkit.getServer());

      commandMap.register(plugin.getName(), this);
    } catch (NoSuchFieldException | IllegalAccessException e) {
      e.printStackTrace();
    }
  }
Пример #3
0
 public boolean register(List<CommandInfo> registered) {
   CommandMap commandMap = getCommandMap();
   if (registered == null || commandMap == null) {
     return false;
   }
   for (CommandInfo command : registered) {
     DynamicPluginCommand cmd =
         new DynamicPluginCommand(
             command.getAliases(),
             command.getDesc(),
             "/" + command.getAliases()[0] + " " + command.getUsage(),
             executor,
             command.getRegisteredWith(),
             plugin);
     cmd.setPermissions(command.getPermissions());
     commandMap.register(plugin.getDescription().getName(), cmd);
   }
   return true;
 }
  public static void scan() {
    CommandMap commandMap = getCommandMap();
    if (commandMap == null) {
      TFM_Log.severe("Error loading commandMap.");
      return;
    }
    COMMAND_LIST.clear();
    COMMAND_LIST.addAll(getCommands());

    for (TFM_CommandInfo commandInfo : COMMAND_LIST) {
      TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo);

      Command existing = commandMap.getCommand(dynamicCommand.getName());
      if (existing != null) {
        unregisterCommand(existing, commandMap);
      }

      commandMap.register(TotalFreedomMod.plugin.getDescription().getName(), dynamicCommand);
    }

    TFM_Log.info("TFM commands loaded.");
  }
Пример #5
0
 public static void registerCommand(final Command command) {
   CommandMap commandMap = getCommandMap();
   if (commandMap != null) {
     commandMap.register("/", command);
   }
 }