示例#1
0
  /**
   * Imports the teams from the configuration.
   *
   * @return The number of teams imported.
   */
  public int importTeamsFromConfig() {
    if (p.getConfig().getList("teams") != null) {
      int teamsCount = 0;
      for (Object teamRaw : p.getConfig().getList("teams")) {
        if (teamRaw instanceof String && teamRaw != null) {
          String[] teamRawSeparated = ((String) teamRaw).split(",");
          TeamColor color = TeamColor.fromString(teamRawSeparated[0]);
          if (color == null) {
            p.getLogger().warning(i.t("load.invalidTeam", (String) teamRaw));
          } else {
            if (teamRawSeparated.length == 2) { // "color,name"
              UHTeam newTeam = addTeam(color, teamRawSeparated[1]);
              p.getLogger()
                  .info(
                      i.t("load.namedTeamAdded", newTeam.getName(), newTeam.getColor().toString()));
              teamsCount++;
            } else if (teamRawSeparated.length == 1) { // "color"
              UHTeam newTeam = addTeam(color, teamRawSeparated[0]);
              p.getLogger().info(i.t("load.teamAdded", newTeam.getColor().toString()));
              teamsCount++;
            } else {
              p.getLogger().warning(i.t("load.invalidTeam", (String) teamRaw));
            }
          }
        }
      }

      return teamsCount;
    }

    return 0;
  }
示例#2
0
  public UHBorderManager(UHPlugin plugin) {
    this.p = plugin;
    this.i = p.getI18n();

    this.warningTimerName = i.t("borders.warning.nameTimer");

    this.currentBorderDiameter = p.getConfig().getInt("map.size");
    this.isCircularBorder = p.getConfig().getBoolean("map.circular");
  }
示例#3
0
  /**
   * Sends a list of the players outside the given border to the specified sender.
   *
   * @param to The player/console to send the check.
   * @param diameter The diameter of the border to be checked.
   */
  public void sendCheckMessage(CommandSender to, int diameter) {
    HashSet<Player> playersOutside = getPlayersOutside(diameter);

    if (playersOutside.size() == 0) {
      to.sendMessage(i.t("borders.check.allPlayersInside"));
    } else {
      to.sendMessage(
          i.t("borders.check.countPlayersOutside", String.valueOf(playersOutside.size())));
      for (Player player : getPlayersOutside(diameter)) {
        int distance = getDistanceToBorder(player.getLocation(), diameter);
        if (distance > 150) {
          to.sendMessage(i.t("borders.check.itemPlayerFar", player.getName()));
        } else if (distance > 25) {
          to.sendMessage(i.t("borders.check.itemPlayerClose", player.getName()));
        } else {
          to.sendMessage(i.t("borders.check.itemPlayerVeryClose", player.getName()));
        }
      }
    }
  }
示例#4
0
  /**
   * Displays a chat-based GUI (using tellraw formatting) to player to select a team.
   *
   * <p>Nothing is displayed if the player cannot use the /join command.
   *
   * @param player The receiver of the chat-GUI.
   */
  public void displayTeamChooserChatGUI(Player player) {
    if (!player.hasPermission("uh.player.join.self")) return;

    if (p.getGameManager().isGameRunning()) {
      if (!p.getGameManager().isGameWithTeams()) {
        return;
      }
    }

    player.sendMessage(
        ChatColor.GRAY
            + "⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅");

    if (p.getTeamManager().getTeams().size() != 0) {
      player.sendMessage(i.t("team.gui.choose"));

      boolean displayPlayers = p.getConfig().getBoolean("teams-options.gui.displayPlayersInTeams");

      for (UHTeam team : p.getTeamManager().getTeams()) {

        String text = "{\"text\":\"\",\"extra\":[";

        // Team count (something like "[2/5]”)
        text += "{";
        if (maxPlayersPerTeam != 0) {
          text +=
              "\"text\": \""
                  + i.t(
                      "team.gui.playersCount",
                      String.valueOf(team.getSize()),
                      String.valueOf(maxPlayersPerTeam))
                  + "\", ";
        } else {
          text +=
              "\"text\": \""
                  + i.t("team.gui.playersCountUnlimited", String.valueOf(team.getSize()))
                  + "\", ";
        }

        String players = "";
        if (displayPlayers) {
          String bullet = "\n - ";
          for (OfflinePlayer opl : team.getPlayers()) {
            if (!p.getGameManager().isGameRunning()) {
              players += bullet + i.t("team.list.itemPlayer", opl.getName());
            } else {
              if (p.getGameManager().isPlayerDead(opl.getUniqueId())) {
                players += bullet + i.t("team.list.itemPlayerDead", opl.getName());
              } else {
                players += bullet + i.t("team.list.itemPlayerAlive", opl.getName());
              }
            }
          }
        }
        text +=
            "\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""
                + i.t("team.gui.tooltipCount", String.valueOf(team.getPlayers().size()))
                + players
                + "\"}";
        text += "},";

        text += "{\"text\":\" \"},{";

        // Team name (click event is here)
        text += "\"text\":\"" + team.getName() + "\",";
        text += "\"color\":\"" + team.getColor().toString().toLowerCase() + "\",";
        text +=
            "\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/join "
                + team.getName()
                + "\"},";
        if (team.containsPlayer(player)) {
          text += "\"bold\":\"true\",";
          text +=
              "\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""
                  + i.t("team.gui.tooltipJoinInside", team.getDisplayName())
                  + "\"}";
        } else {
          text +=
              "\"hoverEvent\":{\"action\":\"show_text\",\"value\":\""
                  + i.t("team.gui.tooltipJoin", team.getDisplayName())
                  + "\"}";
        }
        text += "}";

        text += "]}";

        UHUtils.sendJSONMessage(player, text);
      }

      if (p.getTeamManager().getTeamForPlayer(player) != null
          && player.hasPermission("uh.player.leave.self")) {
        String text = "{";
        text += "\"text\":\"" + i.t("team.gui.leaveTeam") + "\",";
        text += "\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/leave\"}";
        text += "}";

        UHUtils.sendJSONMessage(player, text);
      } else {
        player.sendMessage(i.t("team.gui.howToDisplayAgain"));
      }
    } else {
      // No teams.
      player.sendMessage(i.t("team.gui.noTeams"));
    }

    player.sendMessage(
        ChatColor.GRAY
            + "⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅");
  }