Exemple #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;
  }
  public UHProtocolLibIntegration(UHPlugin p) {

    // The plugin is available if this is called.

    PacketsListener packetsListener = new PacketsListener(p);

    if (p.getConfig().getBoolean("hardcore-hearts.display")) {
      ProtocolLibrary.getProtocolManager().addPacketListener(packetsListener);
    }
    if (p.getConfig().getBoolean("auto-respawn.do")) {
      p.getServer().getPluginManager().registerEvents(packetsListener, p);
    }

    p.getLogger().info("Successfully hooked into ProtocolLib.");
  }