Пример #1
0
  @Override
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

    String name = args.<String>getOne("name").get();
    if (src instanceof Player && EzpzPvpKit.getInstance().isQueueExisting(name)) {
      Player player = (Player) src;
      PvPPlayer pvpPlayer = EzpzPvpKit.getInstance().getPlayer(player.getIdentifier());
      Team team = EzpzPvpKit.getInstance().getTeam(pvpPlayer.getTeam());
      DuelQueue queue = EzpzPvpKit.getInstance().getQueue(name);
      // Size ?
      if (team.getSize() != queue.getSize())
        Utils.sendKitMessage(
            player, Text.of(TextColors.RED, "Party size doesn't match queue size"));
      // Is in duel ?
      else if (team.getInMatch())
        Utils.sendKitMessage(player, Text.of(TextColors.RED, "Cannot join queue in duel"));
      else {
        // is in other queue ?
        if (team.getQueue() != null) EzpzPvpKit.getInstance().getQueue(team.getQueue()).leave(team);
        queue.join(team);
        for (String it : team.getPlayers())
          Utils.sendKitMessage(
              EzpzPvpKit.getInstance().getPlayer(it).getPlayer(),
              Text.of("You joined queue : " + name));
      }

    } else if (src instanceof Player && !EzpzPvpKit.getInstance().isQueueExisting(name))
      Utils.sendKitMessage((Player) src, Text.of(TextColors.RED, "this queue doesn't exist"));
    else if (src instanceof ConsoleSource) Utils.sendMessageC(src);
    else if (src instanceof CommandBlockSource) Utils.sendMessageCB(src);

    return CommandResult.success();
  }
Пример #2
0
  /**
   * @param msg
   * @return
   * @throws TextMessageException
   */
  public Text formatMessage(Object sender, Text msg) throws TextMessageException {
    Hashtable<String, String> tokens = new Hashtable<String, String>();
    tokens.put("color", color);
    tokens.put("command", command);

    if (sender instanceof Player) {
      Player player = (Player) sender;

      Subject subject = player.getContainingCollection().get(player.getIdentifier());
      String prefix = "";
      String suffix = "";

      if (subject instanceof OptionSubject) {
        Optional<String> optionalPrefix = ((OptionSubject) subject).getOption("prefix");
        if (optionalPrefix.isPresent()) {
          prefix = optionalPrefix.get();
        }

        Optional<String> optionalSuffix = ((OptionSubject) subject).getOption("suffix");
        if (optionalSuffix.isPresent()) {
          suffix = optionalSuffix.get();
        }
      }

      tokens.put("msg", "");
      tokens.put("sender", player.getName());
      tokens.put("prefix", prefix);
      tokens.put("suffix", suffix);
    } else {
      tokens.put("msg", "");
      tokens.put(
          "sender", sender != null ? sender.getClass().getSimpleName().toString() : "unknown");
      tokens.put("prefix", "");
      tokens.put("suffix", "");
    }

    Text replaced = TextSerializers.FORMATTING_CODE.deserialize(getString(format, tokens));
    return Text.of(replaced, msg);
  }