Example #1
0
File: Cmd.java Project: Rojoss/Boxx
  public void showSubCmds(CommandSender sender, String label, int page) {
    SubCmd[] subCmds = getBaseCmd().getSubCmds();
    if (subCmds == null) {
      Msg.get("command.no-subcmd").send(sender);
      return;
    }

    int commandsPerPage = 8;
    int pages = subCmds.length / commandsPerPage + 1;

    if (page > pages) {
      Msg.get("command.page-number-high", Param.P("pages", pages)).send(sender);
      return;
    }

    List<String> lines = new ArrayList<>();
    int start = (page - 1) * commandsPerPage;
    for (int i = start; i < start + commandsPerPage && i < subCmds.length; i++) {
      String usage =
          new CmdUsageParser(
                  subCmds[i],
                  sender,
                  label,
                  new String[0],
                  Msg.getString("command.list-argument-name-color"))
              .getJSON();
      lines.add(
          Msg.getString(
              "command.list-entry",
              Param.P("cmd", label),
              Param.P("subcmd", subCmds[i].getSubName()),
              Param.P("usage", usage)));
    }

    String prev;
    if (page == 1) {
      prev = Msg.getString("command.list-no-prev");
    } else {
      prev =
          Msg.getString("command.list-prev", Param.P("cmd", label), Param.P("prevpage", page - 1));
    }
    String next;
    if (page == pages) {
      next = Msg.getString("command.list-no-next");
    } else {
      next =
          Msg.getString("command.list-next", Param.P("cmd", label), Param.P("nextpage", page + 1));
    }

    String msg =
        Msg.getString(
            "command.list",
            Param.P("cmd", label),
            Param.P("page", page),
            Param.P("pages", pages),
            Param.P("prev", prev),
            Param.P("next", next),
            Param.P("commands", Str.implode(lines, "\n")));
    Msg.fromString(msg).send(sender);
  }
Example #2
0
File: Cmd.java Project: Rojoss/Boxx
 /**
  * Get a list with all the registered links.
  *
  * <p>If this command is a sub command this will include all the links from the parent.
  *
  * @return List with registered links.
  */
 public List<Link> getAllLinks() {
   if (isBase()) {
     return new ArrayList<>(links);
   }
   List<Link> links = new ArrayList<>(getBaseCmd().getLinks());
   links.addAll(this.links);
   return links;
 }
Example #3
0
File: Cmd.java Project: Rojoss/Boxx
  /**
   * Display a detailed help message to the specified {@link CommandSender}
   *
   * <p>If the sender is a player or console it will display 'all' details. If it's not it will only
   * display the usage string.
   *
   * @param sender The {@link CommandSender} to send the message to.
   */
  public void showHelp(CommandSender sender, String label, String[] args) {
    if ((!(sender instanceof Player) && sender instanceof Entity)
        || sender instanceof BlockCommandSender) {
      Msg.fromString(getUsage(sender, label, args)).send(sender);
      return;
    }
    String none = Msg.getString("command.none");
    String noDesc = Msg.getString("command.no-description");

    List<String> blacklisted = new ArrayList<>();
    for (SenderType type : getSenderBlacklist()) {
      blacklisted.add(Str.camelCase(type.toString()));
    }

    String perm = "";
    if (perm().isEmpty() && getBaseCmd().perm().isEmpty()) {
      perm = none;
    } else {
      if (!perm().isEmpty()) {
        perm = perm();
      }
      if (isSub() && !getBaseCmd().perm().isEmpty()) {
        if (!perm.isEmpty()) {
          perm += " ";
        }
        perm +=
            Msg.getString("command.permission-inherit", Param.P("permission", getBaseCmd().perm()));
      }
    }

    List<String> flagFormats = new ArrayList<>();
    for (Flag flag : getAllFlags().values()) {
      boolean inherit =
          !flags.containsKey(flag.name().toLowerCase())
              || flag.name().equals("?")
              || flag.name().equals("l");
      if (sender instanceof Player) {
        flagFormats.add(
            Msg.getString(
                inherit ? "command.flag-entry-inherit" : "command.flag-entry",
                Param.P("name", flag.name()),
                Param.P("description", flag.desc().isEmpty() ? noDesc : flag.desc()),
                Param.P("permission", flag.perm().isEmpty() ? none : flag.perm())));
      } else {
        flagFormats.add((inherit ? "&a&l-" : "&7&l-") + flag.name());
      }
    }

    List<String> modifierFormats = new ArrayList<>();
    for (Modifier mod : getAllModifiers().values()) {
      boolean inherit =
          !modifiers.containsKey(mod.name().toLowerCase()) || mod.name().equals("page");
      if (sender instanceof Player) {
        modifierFormats.add(
            Msg.getString(
                inherit ? "command.modifier-entry-inherit" : "command.modifier-entry",
                Param.P("name", mod.name()),
                Param.P("description", mod.desc().isEmpty() ? noDesc : mod.desc()),
                Param.P("permission", mod.perm().isEmpty() ? none : mod.perm()),
                Param.P("type", mod.option().getTypeName())));
      } else {
        modifierFormats.add(
            inherit
                ? "&a" + mod.name() + ":&8[&a" + mod.option().getTypeName() + "&8]"
                : "&7" + mod.name() + ":&8[&7" + mod.option().getTypeName() + "&8]");
      }
    }

    String argClr = Msg.getString("command.argument-name-color");
    String msg =
        Msg.getString(
            "command.help",
            Param.P("label", label),
            Param.P("cmd", getBaseCmd().getName()),
            Param.P(
                "usage",
                sender instanceof ConsoleCommandSender
                    ? new CmdUsageParser(this, sender, label, args, argClr).getString()
                    : new CmdUsageParser(this, sender, label, args, argClr).getJSON()),
            Param.P("description", desc().isEmpty() ? noDesc : desc()),
            Param.P("permission", perm),
            Param.P(
                "aliases",
                isSub()
                    ? (((SubCmd) this).getSubAliases().isEmpty()
                        ? none
                        : Str.implode(((SubCmd) this).getSubAliases()))
                    : (getAliases().isEmpty() ? none : Str.implode(getAliases()))),
            Param.P("flags", flagFormats.isEmpty() ? none : Str.implode(flagFormats, " ")),
            Param.P("modifiers", modifierFormats.isEmpty() ? none : Str.implode(modifierFormats)));

    Msg.fromString(msg).send(sender);
  }
Example #4
0
File: Cmd.java Project: Rojoss/Boxx
 /**
  * Register a {@link} for this command.
  *
  * @see Link
  * @see #addRemoveLink(String, String...)
  * @see #addRequirementLink(String, ArgRequirement, String...)
  * @param link The link instance to add.
  * @return The added {@link Link}
  */
 public Link addLink(Link link) {
   links.add(link);
   return link;
 }
Example #5
0
File: Cmd.java Project: Rojoss/Boxx
 /**
  * Add one or more {@link SenderType}s on the sender blacklist.
  *
  * <p>The added sender types won't be able to execute the command.
  *
  * @param type One or more {@link SenderType}s to be blacklisted.
  */
 public void blacklistSenders(SenderType... type) {
   senderBlacklist.addAll(Arrays.asList(type));
 }
Example #6
0
File: Cmd.java Project: Rojoss/Boxx
 /** Clear the list with blacklisted {@link SenderType}s. */
 public void clearSenderBlacklist() {
   senderBlacklist.clear();
 }