Ejemplo n.º 1
0
  private void formatSubcmds(CommandManager mgr, StringBuffer buff) throws CLIException {
    ResourceBundle rb = mgr.getResourceBundle();
    buff.append(rb.getString("USAGE_SUBCOMMAND_TITLE"));
    buff.append("\n");

    List defObjects = mgr.getDefinitionObjects();
    Map mapCmds = new HashMap();
    Set orderCmds = new TreeSet();

    for (Iterator i = defObjects.iterator(); i.hasNext(); ) {
      IDefinition def = (IDefinition) i.next();
      for (Iterator j = def.getSubCommands().iterator(); j.hasNext(); ) {
        SubCommand cmd = (SubCommand) j.next();

        if ((cmd != null) && (!mgr.webEnabled() || cmd.webEnabled())) {
          String name = cmd.getName();
          orderCmds.add(name);
          mapCmds.put(name, cmd.getDescription());
        }
      }
    }

    StringBuilder buffCmd = new StringBuilder();
    boolean started = false;
    String webEnabledURL = mgr.getWebEnabledURL();
    for (Iterator i = orderCmds.iterator(); i.hasNext(); ) {
      String cmdName = (String) i.next();
      buffCmd.append(formAbstractCmdUsage(webEnabledURL, cmdName, (String) mapCmds.get(cmdName)));
    }

    buff.append(buffCmd.toString());
  }
Ejemplo n.º 2
0
  private synchronized MinnBot initCommands()
      throws UnknownHostException, UnsupportedDataTypeException {
    try {
      EvalUtil.init();
    } catch (ScriptException e) {
      logger.logThrowable(e);
    }
    // User commands
    tmp = new PublicManager(prefix, logger, this);
    AtomicReference<CmdManager> manager = new AtomicReference<>(tmp);
    handler.registerManager(manager.get());

    // Voice
    if (audio) {
      manager.set(new AudioCommandManager(prefix, logger));
      handler.registerManager(manager.get());
    }

    manager.set(new RoleCommandManager(prefix, logger));
    handler.registerManager(manager.get());

    manager.set(new GoofyManager(prefix, logger, giphy, this));
    handler.registerManager(manager.get());

    manager.set(new CustomManager(prefix, logger));
    handler.registerManager(manager.get());
    return this;
  }
Ejemplo n.º 3
0
  @Test
  public void testCommand() throws CommandException {
    CommandManager cm = new CommandManager();
    CommandSource testSource = new TestCommandSource(cm);
    Command cmd =
        cm.getCommand("test1")
            .addAlias("t1")
            .setPermission("test.1")
            .setExecutor(
                new Executor() {
                  @Override
                  public void execute(CommandSource source, Command command, CommandArguments args)
                      throws CommandException {
                    args.popString("testArg1");
                    args.popString("testArg2", "Not specified");
                    args.assertCompletelyParsed();
                  }
                });

    // execute with success
    cmd.process(testSource, "foo");
    cmd.process(testSource, "foo", "bar");

    // execute with failure
    thrown.expect(CommandException.class);
    cmd.process(testSource, "foo", "bar", "baz");
    cmd.process(testSource);
  }
Ejemplo n.º 4
0
  /**
   * Perform the 'alias' command.
   *
   * @param session JSwat session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    CommandManager cmdman = (CommandManager) session.getManager(CommandManager.class);
    if (args.hasMoreTokens()) {
      String aliasName = args.nextToken();
      if (args.hasMoreTokens()) {
        // Grab rest of string as alias value.
        // Be sure to preserve the quotes and escapes.
        args.returnAsIs(true);
        String alias = args.rest().trim();
        if (alias.charAt(0) == '"' && alias.charAt(alias.length() - 1) == '"') {
          // Must remove the enclosing quotes because the
          // command parser doesn't handle that.
          alias = alias.substring(1, alias.length() - 1);
        }

        // Add the command alias to the list.
        cmdman.createAlias(aliasName, alias);
        out.writeln(Bundle.getString("alias.defined") + ' ' + aliasName);
      } else {
        // One argument, show the alias definition.
        String alias = cmdman.getAlias(aliasName);
        if (alias == null) {
          throw new CommandException(Bundle.getString("alias.undefined") + ' ' + aliasName);
        } else {
          out.writeln("alias " + aliasName + ' ' + alias);
        }
      }
    } else {
      // No arguments, show the defined aliases.
      cmdman.listAliases();
    }
  } // perform
Ejemplo n.º 5
0
 private static void dumpToOutput(CommandManager mgr, String msg, Throwable t) {
   if (mgr.isDebugOn()) {
     IOutput writer = mgr.getOutputWriter();
     writer.printlnMessage(msg);
     if (t != null) {
       writer.printlnMessage(getStackTrace(t));
     }
   }
 }
Ejemplo n.º 6
0
  /**
   * Handle widget events.
   *
   * @param e action event
   */
  public void actionPerformed(final ActionEvent e) {
    if (e.getSource() == tableClose) {
      propertySupport.firePropertyChange(ModuleFrame.WINDOW_CLOSE_PROPERTY, 0, 1);
    } else if (e.getSource() == applyExpressions) {
      applyExpressions(model);
    } else if (e.getSource() == applyFilter) {
      applyFilter();
    } else if (e.getSource() == sortByMostActive) {
      setColumnSortStatus(EODQuoteModel.ACTIVITY_COLUMN, SORT_UP);
      resort();
      validate();
      repaint();
    }

    // Find symbol
    else if (e.getSource() == findSymbol) findSymbol();

    // Graph symbols, either by the popup menu or the main menu
    else if ((popupGraphSymbols != null && e.getSource() == popupGraphSymbols)
        || e.getSource() == graphSymbols) {

      int[] selectedRows = getSelectedRows();
      List symbols = new ArrayList();

      for (int i = 0; i < selectedRows.length; i++) {
        Symbol symbol = (Symbol) model.getValueAt(selectedRows[i], EODQuoteModel.SYMBOL_COLUMN);

        symbols.add(symbol);
      }

      // Graph the highlighted symbols
      CommandManager.getInstance().graphStockBySymbol(symbols);
    }

    // Table symbols, either by the popup menu or the main menu
    else if ((popupTableSymbols != null && e.getSource() == popupTableSymbols)
        || e.getSource() == tableSymbols) {

      int[] selectedRows = getSelectedRows();
      List symbols = new ArrayList();

      for (int i = 0; i < selectedRows.length; i++) {
        Symbol symbol = (Symbol) model.getValueAt(selectedRows[i], EODQuoteModel.SYMBOL_COLUMN);

        symbols.add(symbol);
      }

      // Table the highlighted symbols
      CommandManager.getInstance().tableStocks(symbols);
    } else if (e.getSource() == alertSymbols) {
      int[] selectedRows = getSelectedRows();
      Symbol symbol = (Symbol) model.getValueAt(selectedRows[0], EODQuoteModel.SYMBOL_COLUMN);

      CommandManager.getInstance().newAlert(symbol);
    } else assert false;
  }
Ejemplo n.º 7
0
 /**
  * Load an extension into this meterpreter. Called from {@link core_loadlib}.
  *
  * @param data The extension jar's content as a byte array
  */
 public String[] loadExtension(byte[] data) throws Exception {
   ClassLoader classLoader = getClass().getClassLoader();
   if (loadExtensions) {
     URL url = MemoryBufferURLConnection.createURL(data, "application/jar");
     classLoader = new URLClassLoader(new URL[] {url}, classLoader);
   }
   JarInputStream jis = new JarInputStream(new ByteArrayInputStream(data));
   String loaderName = (String) jis.getManifest().getMainAttributes().getValue("Extension-Loader");
   ExtensionLoader loader = (ExtensionLoader) classLoader.loadClass(loaderName).newInstance();
   commandManager.resetNewCommands();
   loader.load(commandManager);
   return commandManager.getNewCommands();
 }
Ejemplo n.º 8
0
  private void formatUsage(CommandManager mgr, StringBuffer buff, SubCommand cmd)
      throws CLIException {
    ResourceBundle rb = mgr.getResourceBundle();
    buff.append(rb.getString("USAGE"));
    buff.append("\n");

    buff.append(mgr.getCommandName()).append(" ").append(cmd.getName());

    formatOptionNames(cmd.getMandatoryOptions(), cmd, buff, CLIConstants.USAGE_OPTION_NAME_FORMAT);
    formatOptionNames(
        cmd.getOptionalOptions(), cmd, buff, CLIConstants.USAGE_OPTIONAL_OPTION_NAME_FORMAT);

    buff.append("\n").append("\n");
  }
Ejemplo n.º 9
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(command.getName().equalsIgnoreCase("stats"))) return false;
    CommandManager.setSender(sender);

    if (args.length == 0) {
      CommandManager.Help.run();
      CommandManager.resetSender();
      return true;
    }

    for (CommandManager cmd : CommandManager.values()) {
      if (cmd.isCommand(args[0])) {
        if (LocalConfiguration.Debug.asBoolean()) {
          String argString = "/stats";
          for (String arg : args) {
            argString = argString + " " + arg;
          }
          Message.log(sender.getName() + ": " + argString);
        }

        boolean result = cmd.run(args);
        CommandManager.resetSender();
        return result;
      }
    }

    Message.sendFormattedError(sender, "Unknown command");
    CommandManager.resetSender();
    return false;
  }
Ejemplo n.º 10
0
  /** applies the transformation to the source MelodyPart */
  public void execute() {
    Trace.log(2, "executing SideSlipCommand");

    int start = original.getSize();

    if (direction.equals("up")) { // slide up
      cm.execute(new ShiftPitchesCommand(distance, dest, 0, start, 0, 128, keySig));
    } else if (direction.equals("down")) { // slide down
      cm.execute(new ShiftPitchesCommand(-1 * distance, dest, 0, start, 0, 128, keySig));
    }

    // add two of the same melodies with one transposed
    source.setSize(dest.getSize() * 2);
    source.pasteOver(dest, start);
  }
Ejemplo n.º 11
0
  private void formatUsage(CommandManager mgr, StringBuffer buff) throws CLIException {
    ResourceBundle rb = mgr.getResourceBundle();
    String commandName = mgr.getCommandName();
    buff.append(rb.getString("USAGE"));
    buff.append("\n");

    for (Iterator i = globalArgs.iterator(); i.hasNext(); ) {
      try {
        String option = (String) i.next();
        Field fldLong = CLIConstants.class.getField(CLIConstants.PREFIX_ARGUMENT + option);
        Field fldShort = CLIConstants.class.getField(CLIConstants.PREFIX_SHORT_ARGUMENT + option);
        Object[] params = {
          commandName,
          fldLong.get(null),
          fldShort.get(null),
          rb.getString(CLIConstants.PREFIX_ARGUMENT + option)
        };
        buff.append(MessageFormat.format(CLIConstants.USAGE_FORMAT, params));
        buff.append("\n");
      } catch (Exception e) {
        throw new CLIException(e.getMessage(), ExitCodes.USAGE_FORMAT_ERROR);
      }
    }

    {
      Object[] params = {
        commandName,
        rb.getString("USAGE_SUBCOMMAND"),
        rb.getString("USAGE_GLOBAL_OPTIONS"),
        rb.getString("USAGE_OPTIONS"),
        rb.getString("ARGUMENT_SUBCOMMAND")
      };
      buff.append(MessageFormat.format(CLIConstants.USAGE_SUBCMD_FORMAT, params));
      buff.append("\n");
    }

    {
      Object[] params = {
        commandName,
        rb.getString("USAGE_SUBCOMMAND"),
        CLIConstants.ARGUMENT_HELP,
        CLIConstants.SHORT_ARGUMENT_HELP,
        rb.getString("ARGUMENT_SUBCOMMAND_HELP")
      };
      buff.append(MessageFormat.format(CLIConstants.USAGE_SUBCMD_HELP_FORMAT, params));
      buff.append("\n");
    }
  }
Ejemplo n.º 12
0
  // If the user double clicks on a stock with the LMB, graph the stock.
  // If the user right clicks over the table, open up a popup menu.
  private void handleMouseClicked(MouseEvent event) {

    Point point = event.getPoint();

    // Right click on the table - raise menu
    if (event.getButton() == MouseEvent.BUTTON3) {
      JPopupMenu menu = new JPopupMenu();

      popupGraphSymbols = MenuHelper.addMenuItem(this, menu, Locale.getString("GRAPH"));
      popupGraphSymbols.setEnabled(getSelectedRowCount() > 0);

      popupTableSymbols = MenuHelper.addMenuItem(this, menu, Locale.getString("TABLE"));
      popupTableSymbols.setEnabled(getSelectedRowCount() > 0);

      menu.show(this, point.x, point.y);
    }

    // Left double click on the table - graph stock
    else if (event.getButton() == MouseEvent.BUTTON1 && event.getClickCount() == 2) {
      int[] selectedRows = getSelectedRows();
      List symbols = new ArrayList();
      for (int i = 0; i < selectedRows.length; i++) {
        Symbol symbol = (Symbol) model.getValueAt(selectedRows[i], EODQuoteModel.SYMBOL_COLUMN);

        symbols.add(symbol);
      }

      // Graph the highlighted symbols
      CommandManager.getInstance().graphStockBySymbol(symbols);
    }
  }
Ejemplo n.º 13
0
 public static CLIException createIncorrectFormatException(CommandManager mgr, String line) {
   ResourceBundle rb = mgr.getResourceBundle();
   String[] param = {line};
   String msg =
       MessageFormat.format(rb.getString("exception-incorrect-data-format"), (Object[]) param);
   return new CLIException(msg, ExitCodes.INCORRECT_DATA_FORMAT);
 }
Ejemplo n.º 14
0
  @Test
  public void testFilter() {
    CommandManager cm = new CommandManager();
    CommandSource source = new TestCommandSource(cm);
    cm.getCommand("test3")
        .addFilter(new PlayerFilter())
        .setExecutor(
            new Executor() {
              @Override
              public void execute(CommandSource source, Command command, CommandArguments args)
                  throws CommandException {}
            });

    thrown.expectCause(isA(CommandException.class));
    thrown.expectMessage("You must be a Player to execute this command");
    source.processCommand("test3");
  }
Ejemplo n.º 15
0
 public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
   if (command.getName().equalsIgnoreCase("mineresetlite")) {
     if (args.length == 0) {
       String[] helpArgs = new String[0];
       commandManager.callCommand("help", sender, helpArgs);
       return true;
     }
     // Spoof args array to account for the initial subcommand specification
     String[] spoofedArgs = new String[args.length - 1];
     for (int i = 1; i < args.length; i++) {
       spoofedArgs[i - 1] = args[i];
     }
     commandManager.callCommand(args[0], sender, spoofedArgs);
     return true;
   }
   return false; // Fallthrough
 }
Ejemplo n.º 16
0
 /**
  * Prints the usage of CLI.
  *
  * @param mgr Command Manager object.
  * @throws CLIException if usage text cannot be presented.
  */
 public void format(CommandManager mgr) throws CLIException {
   StringBuffer buff = new StringBuffer();
   buff.append("\n\n");
   formatUsage(mgr, buff);
   formatGlobalOptions(mgr, buff);
   formatSubcmds(mgr, buff);
   mgr.getOutputWriter().printlnMessage(buff.toString());
 }
Ejemplo n.º 17
0
 private void formatOptions(CommandManager mgr, StringBuffer buff, SubCommand cmd)
     throws CLIException {
   ResourceBundle rb = mgr.getResourceBundle();
   buff.append(rb.getString("USAGE_OPTIONS_TITLE"));
   buff.append("\n");
   formatOption(cmd.getMandatoryOptions(), cmd, buff);
   formatOption(cmd.getOptionalOptions(), cmd, buff);
   buff.append("\n");
 }
  public void onEnable() {
    Bukkit.getServer().getPluginManager().registerEvents(new SignManager(), this);

    ArenaManager.getInstance().setupArenas();

    CommandManager cm = new CommandManager();
    cm.setup();
    getCommand("supersmashcraft").setExecutor(cm);

    PluginManager pm = Bukkit.getServer().getPluginManager();
    pm.registerEvents(new BlockBreak(), this);
    pm.registerEvents(new PlayerDeath(), this);
    pm.registerEvents(new PlayerLeave(), this);
    pm.registerEvents(new PlayerLoseHunger(), this);
    pm.registerEvents(new PlayerFireball(), this);
    pm.registerEvents(new PlayerCake(), this);
    pm.registerEvents(new PlayerBow(), this);
  }
Ejemplo n.º 19
0
  public synchronized MinnBot initCommands(JDA api)
      throws UnknownHostException, UnsupportedDataTypeException {
    PlayingFieldManager.init(api, logger);

    // Add logger to the listeners
    api.addEventListener(logger);

    AtomicReference<CmdManager> manager =
        new AtomicReference<>(new OperatorManager(prefix, logger, this));
    handler.registerManager(manager.get());

    // Moderation commands

    manager.set(new ModerationCommandManager(prefix, logger, api));
    handler.registerManager(manager.get());

    return this;
  }
Ejemplo n.º 20
0
  /**
   * Perform the 'history' command.
   *
   * @param session JSwat session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    CommandManager cmdman = (CommandManager) session.getManager(CommandManager.class);

    if (args.hasMoreTokens()) {
      String arg = args.nextToken();
      try {
        int size = Integer.parseInt(arg);
        cmdman.setHistorySize(size);
        out.writeln(Bundle.getString("history.sizeSet"));
      } catch (NumberFormatException nfe) {
        throw new CommandException(Bundle.getString("history.invalidSize"));
      } catch (IllegalArgumentException iae) {
        throw new CommandException(Bundle.getString("history.invalidRange"));
      }
    } else {
      cmdman.displayHistory();
    }
  } // perform
Ejemplo n.º 21
0
    public void actionPerformed(ActionEvent event) {
      String action = event.getActionCommand();
      if (action.equals(colorString)) {
        Color newColor = ColorChooser.getColor(colorTitleString, getColor());

        if (newColor != null) {
          setColor(newColor);
          currentColor = newColor;
        }

        CommandManager.getInstance().execute("RepaintWorkspace");
      } else if (action.equals(dashedString)) {
        dashed = !dashed;
        currentIsDashed = dashed;

        CommandManager.getInstance().execute("RepaintWorkspace");
      }
    }
Ejemplo n.º 22
0
  @Test
  public void testChildren() {
    CommandManager cm = new CommandManager();
    CommandSource testSource = new TestCommandSource(cm);
    cm.getCommand("test2")
        .getChild("foo")
        .getChild("bar")
        .getChild("baz")
        .setExecutor(
            new Executor() {
              @Override
              public void execute(CommandSource source, Command command, CommandArguments args)
                  throws CommandException {
                assertEquals("baz", command.getName());
                assertEquals("hello", args.popString("testStr"));
              }
            });

    testSource.processCommand("test2", "foo", "bar", "baz", "hello");
  }
Ejemplo n.º 23
0
  /**
   * Prints the usage of sub command.
   *
   * @param mgr Command Manager object.
   * @param cmd Sub command object.
   * @throws CLIException if usage text cannot be presented.
   */
  public void format(CommandManager mgr, SubCommand cmd) throws CLIException {
    StringBuffer buff = new StringBuffer();
    buff.append("\n\n");

    ResourceBundle rb = mgr.getResourceBundle();
    String commandName = mgr.getCommandName();
    Object[] params = {
      commandName,
      cmd.getName(),
      rb.getString("USAGE_OPTIONS"),
      rb.getString("USAGE_GLOBAL_OPTIONS"),
      cmd.getDescription()
    };
    buff.append(MessageFormat.format(CLIConstants.USAGE_SUBCMD_LONG_FORMAT, params));
    buff.append("\n");
    formatUsage(mgr, buff, cmd);
    formatGlobalOptions(mgr, buff);
    formatOptions(mgr, buff, cmd);
    mgr.getOutputWriter().printlnMessage(buff.toString());
  }
  private void sendCommandQueue(String eventType, CommandManager c, OrderDTO order)
      throws PluggableTaskException {
    LOG.debug("Publishing command queue to JMS");

    try {
      CommandsQueueSender cmdSender = new CommandsQueueSender(order);
      cmdSender.postCommandsQueue(c.getCommands(), eventType);

    } catch (JMSException e) {
      throw new PluggableTaskException(e);
    }
  }
Ejemplo n.º 25
0
  /** Shutdown all the various servers. */
  public void shutdown() {
    try {
      if (http != null) {
        try {
          http.stop();
        } catch (Exception e) {
          LOG.error("Error stopping FlumeMaster", e);
        }
        http = null;
      }

      cmdman.stop();

      ackman.stop();

      if (configServer != null) {
        configServer.stop();
        configServer = null;
      }

      if (controlServer != null) {
        controlServer.stop();
        controlServer = null;
      }
      /*
       * Close the reportserver which started.
       */
      if (cfg.getReportServerRPC() == cfg.RPC_TYPE_AVRO) {
        if (avroReportServer != null) {
          avroReportServer.stop();
          avroReportServer = null;
        }
      } else {
        if (thriftReportServer != null) {
          thriftReportServer.stop();
          thriftReportServer = null;
        }
      }
      specman.stop();

      reaper.interrupt();

      FlumeConfiguration cfg = FlumeConfiguration.get();
      if (cfg.getMasterStore().equals(ZK_CFG_STORE)) {
        ZooKeeperService.get().shutdown();
      }

    } catch (IOException e) {
      LOG.error("Exception when shutting down master!", e);
    } catch (Exception e) {
      LOG.error("Exception when shutting down master!", e);
    }
  }
Ejemplo n.º 26
0
    @Override
    public void processCommand(String command, String... args) {
      Command cmd = cm.getCommand(command, false);
      if (cmd == null) {
        sendMessage("Unknown command: '" + command + "'.");
        return;
      }

      try {
        cmd.process(this, args);
      } catch (CommandException e) {
        throw new RuntimeException(e);
      }
    }
Ejemplo n.º 27
0
 /**
  * Finds the insert position of the given <code>command</command> within the <code>popupMenu</code>.
  *
  * @param popupMenu The popup menu.
  * @param command The command to insert.
  * @param manager The command manager.
  */
 public static int findMenuInsertPosition(
     final JPopupMenu popupMenu, final Command command, final CommandManager manager) {
   int pbi = popupMenu.getComponentCount();
   String placeBefore = command.getPlaceBefore();
   if (placeBefore != null) {
     pbi = UIUtils.findMenuItemPosition(popupMenu, placeBefore);
   }
   int pai = -1;
   String placeAfter = command.getPlaceAfter();
   if (placeAfter != null) {
     pai = UIUtils.findMenuItemPosition(popupMenu, placeAfter) + 1;
   }
   final int componentCount = popupMenu.getComponentCount();
   for (int i = 0; i < componentCount; i++) {
     final Component component = popupMenu.getComponent(i);
     if (!(component instanceof JMenuItem)) {
       continue;
     }
     final JMenuItem item = (JMenuItem) component;
     final String name = item.getName();
     final Command menuCommand = manager.getCommand(name);
     if (menuCommand == null) {
       continue;
     }
     placeBefore = menuCommand.getPlaceBefore();
     if (command.getCommandID().equals(placeBefore)) {
       if (pbi > i) {
         pbi = i + 1;
       }
     }
     placeAfter = menuCommand.getPlaceAfter();
     if (command.getCommandID().equals(placeAfter)) {
       if (pai < i) {
         pai = i;
       }
     }
   }
   int insertPos = -1;
   if (pbi >= pai) {
     insertPos = pai;
   }
   if (insertPos == -1) {
     insertPos = popupMenu.getComponentCount();
   }
   return insertPos;
 }
Ejemplo n.º 28
0
 private static Command[] getCommands(
     final JPopupMenu popupMenu, final CommandManager manager, final Command command) {
   final List<Command> commands = new ArrayList<Command>();
   final int count = popupMenu.getComponentCount();
   for (int i = 0; i < count; i++) {
     final Component component = popupMenu.getComponent(i);
     if (!(component instanceof JMenuItem)) {
       continue;
     }
     final JMenuItem item = (JMenuItem) component;
     final String name = item.getName();
     final Command menuCommand = manager.getCommand(name);
     if (menuCommand != null) {
       commands.add(menuCommand);
     }
   }
   commands.add(command);
   return commands.toArray(new Command[commands.size()]);
 }
Ejemplo n.º 29
0
  @Override
  public void onEnable() {
    we = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
    try {
      am.load();
    } catch (IOException | InvalidConfigurationException ex) {
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    gm.load();
    cm.register();
    em.register();
    sm.load();
    prefix = ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix"));

    String spawnWorldName = getConfig().getString("spawn.world");
    if (spawnWorldName != null) {
      World spawnWorld = getServer().getWorld(spawnWorldName);
      if (spawnWorld != null) {
        spawn = spawnWorld.getSpawnLocation();
      }
    }
  }
Ejemplo n.º 30
0
  private void formatGlobalOptions(CommandManager mgr, StringBuffer buff) throws CLIException {
    ResourceBundle rb = mgr.getResourceBundle();
    buff.append(rb.getString("USAGE_GLOBAL_OPTIONS_TITLE"));
    buff.append("\n");

    for (Iterator i = globalOptions.iterator(); i.hasNext(); ) {
      try {
        String option = (String) i.next();
        Field fldLong = CLIConstants.class.getField(CLIConstants.PREFIX_ARGUMENT + option);
        Field fldShort = CLIConstants.class.getField(CLIConstants.PREFIX_SHORT_ARGUMENT + option);
        Object[] params = {
          fldLong.get(null), fldShort.get(null), rb.getString(CLIConstants.PREFIX_ARGUMENT + option)
        };
        buff.append(MessageFormat.format(CLIConstants.USAGE_OPTIONAL_OPTION_FORMAT, params));
        buff.append("\n");
      } catch (Exception e) {
        throw new CLIException(e.getMessage(), ExitCodes.USAGE_FORMAT_ERROR);
      }
    }

    buff.append("\n");
  }