Exemplo n.º 1
0
 private void sendPlayer(CommandSender warper, Warpable warped, Warp warp) {
   if (warped.teleport(warp.getLocation().toLocation(), TeleportCause.COMMAND)) {
     String rawMsg = warp.getRawWelcomeMessage();
     if (rawMsg == null) {
       rawMsg = this.properties.getDefaultMessage().replace("{NAME}", warp.getName());
     }
     if (MinecraftUtil.isSet(rawMsg)) {
       warped.sendMessage(ChatColor.AQUA + rawMsg);
     }
     this.down.addPlayer(warp, warper);
     this.players.remove(warper);
     if (!warped.equals(warper)) {
       warper.sendMessage(
           "Sucessfully warped '"
               + ChatColor.GREEN
               + MinecraftUtil.getName(warped)
               + ChatColor.WHITE
               + "'");
     }
   } else {
     warper.sendMessage(ChatColor.RED + "Unable to warp.");
   }
 }
Exemplo n.º 2
0
  public boolean execute(CommandSender sender, String[] parameters) {
    if (parameters.length == 2) {
      Integer id = MinecraftUtil.tryAndGetInteger(parameters[1]);
      if (id != null) {
        Vote vote = this.manager.getVote(id);
        if (vote != null) {
          sender.sendMessage("Vote #" + id + " by " + vote.getCreator());
          sender.sendMessage(vote.getQuestion());
          StringBuilder result = new StringBuilder("Result: ");
          for (VoteResult voteResult : VoteResult.values()) {
            result.append(voteResult.getNames()[0]);
            result.append(": ");
            result.append(vote.getVoteCount(voteResult));
            result.append(", ");
          }
          result.append("Total: ");
          int total = vote.getVoteCount();
          result.append(total);
          sender.sendMessage(result.toString());

          // @formatter:off
          sender.sendMessage(
              BarCommand.getBar(vote, VoteResult.PRO, total, 100)
                  + BarCommand.getBar(vote, VoteResult.CONTRA, total, 100)
                  + BarCommand.getBar(vote, VoteResult.ABSTENTION, total, 100));
          // @formatter:on

          Date finalDate = vote.getFinalDate();
          if (finalDate != null) {
            String expirationString = "This vote runs until: " + this.formatter.format(finalDate);
            if (vote.expired()) {
              expirationString += " " + ChatColor.RED + "(expired)";
            }
            sender.sendMessage(expirationString);
          } else {
            sender.sendMessage("This vote has no expiration date.");
          }
        } else {
          sender.sendMessage(ChatColor.RED + "The id is not a valid vote.");
        }
      } else {
        sender.sendMessage(ChatColor.RED + "The id has to be an integer.");
      }

      return true;
    } else {
      return false;
    }
  }
Exemplo n.º 3
0
  @Override
  public boolean execute(CommandSender sender, String[] parameters) {
    if (!XWarp.permissions.permission(sender, PermissionTypes.CMD_LIST)) {
      sender.sendMessage(ChatColor.RED + "You have no permission to list warps.");
      return true;
    }

    // Special case
    if (parameters.length == 2 && parameters[1].equalsIgnoreCase("legend")) {
      if (!(sender instanceof Player)) {
        sender.sendMessage("Maybe no colors here, so this command could be useless here!");
      }
      for (String line : GenericLister.getLegend()) {
        sender.sendMessage(line);
      }
    } else {
      // Parse values here
      /*
       * c:<creator>
       * oc:<offline creator (won't be expanded)>
       * w:<world>
       * o:<owner>
       * oo:<offline owner (won't be expanded)>
       * v:<visibility>
       */

      // Whitelist
      Set<String> creators = new HashSet<String>();
      Set<String> owners = new HashSet<String>();
      Set<String> worlds = new HashSet<String>();
      Set<Visibility> visibilites = new HashSet<Visibility>();

      // Blacklist
      /* not implemented yet */

      // Column blacklist
      EnumSet<Column> blackColumns = EnumSet.noneOf(Column.class);

      Integer page = null; // Default page = 1
      // 0 = list/ls
      for (int i = 1; i < parameters.length; i++) {
        if (parameters[i].startsWith("c:")) {
          add(
              sender,
              creators,
              MinecraftUtil.expandName(parameters[i].substring(2), this.server).toLowerCase());
        } else if (parameters[i].startsWith("oc:")) {
          add(sender, creators, parameters[i].substring(2).toLowerCase());
        } else if (parameters[i].startsWith("w:")) {
          add(sender, worlds, parameters[i].substring(2).toLowerCase());
        } else if (parameters[i].startsWith("o:")) {
          add(
              sender,
              owners,
              MinecraftUtil.expandName(parameters[i].substring(2), this.server).toLowerCase());
        } else if (parameters[i].startsWith("oo:")) {
          add(sender, owners, parameters[i].substring(2).toLowerCase());
        } else if (parameters[i].startsWith("v:")) {
          Visibility v = Visibility.parseString(parameters[i].substring(2));
          if (v != null) {
            add(sender, visibilites, v);
          } else {
            sender.sendMessage(
                ChatColor.RED
                    + "Inputed an invalid visibility value: "
                    + parameters[i].substring(2));
          }
        } else if (parameters[i].startsWith("-col:")) {
          if (parameters[i].equalsIgnoreCase("-col:owner")) {
            add(sender, blackColumns, Column.OWNER);
          } else if (parameters[i].equalsIgnoreCase("-col:world")) {
            add(sender, blackColumns, Column.WORLD);
          } else if (parameters[i].equalsIgnoreCase("-col:loc")) {
            add(sender, blackColumns, Column.LOCATION);
          } else {
            sender.sendMessage(ChatColor.RED + "Unknown column: " + parameters[i].substring(5));
          }
        } else {
          Integer buffer = MinecraftUtil.tryAndGetInteger(parameters[i]);
          if (buffer != null) {
            if (page == null) {
              page = buffer;
            } else {
              sender.sendMessage(
                  ChatColor.RED
                      + "Found more than one page definition. Selecting first: "
                      + buffer);
            }
          } else {
            sender.sendMessage(ChatColor.RED + "Unknown parameter prefix: " + parameters[i]);
          }
        }
      }

      if (page == null) {
        page = 1;
      }

      final List<Warp> warps = this.manager.getWarps(sender, creators, owners, worlds, visibilites);

      final int maxPages = getNumberOfPages(warps.size(), sender);
      final int numLines = MinecraftUtil.getMaximumLines(sender) - 1;

      final ListSection section = new ListSection("", numLines);

      if (maxPages < 1) {
        sender.sendMessage(ChatColor.RED + "There are no warps to list");
      } else if (page < 1) {
        sender.sendMessage(ChatColor.RED + "Page number can't be below 1.");
      } else if (page > maxPages) {
        sender.sendMessage(ChatColor.RED + "There are only " + maxPages + " pages of warps");
      } else {
        // Get only those warps one the page
        final int offset = (page - 1) * numLines;
        final int lines = Math.min(warps.size() - offset, numLines);
        List<Warp> pageWarps = warps.subList(offset, offset + lines);

        section.addWarps(pageWarps);

        GenericLister.listPage(page, maxPages, sender, EnumSet.complementOf(blackColumns), section);
      }
    }
    return true;
  }
Exemplo n.º 4
0
 private static int getNumberOfPages(int elements, CommandSender sender) {
   return (int) Math.ceil(elements / (double) (MinecraftUtil.getMaximumLines(sender) - 1));
 }