Exemplo n.º 1
0
  @SuppressWarnings("deprecation")
  public void leaveGame(Player player, boolean normalLeave) {

    player.setGameMode(GameMode.CREATIVE);
    // player.setAllowFlight(true);

    player.setHealth(20.0);
    player.setFoodLevel(20);
    player.setLevel(0);

    for (PotionEffect effect : player.getActivePotionEffects()) {
      player.removePotionEffect(effect.getType());
    }

    // Session session = HyperPVP.getSession(player);
    // session.setInterruptThread(true);

    if (normalLeave) {
      player.sendMessage(ChatColor.AQUA + "You are now spectating!");
      HyperPVP.setListName(ChatColor.AQUA, player);
      player.getInventory().clear();
      player.updateInventory();
    }

    CycleUtil.addSpectator(player, normalLeave);
    HyperPVP.getGameSessions().remove(player.getName());

    CycleUtil.hidePlayerWhereAppropriate(player, false);
    player.getInventory().setHelmet(null);
    player.getInventory().setBoots(null);
    player.getInventory().setChestplate(null);
    player.getInventory().setLeggings(null);

    try {
      HyperPVP.getStorage()
          .executeQuery(
              "UPDATE servers SET team_one = '"
                  + this.getTeamMembers(this.teams.get(0).getColor()).size()
                  + "' WHERE bungee_name = '"
                  + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase()
                  + "'");

      if (this.type != GameType.FFA) {
        HyperPVP.getStorage()
            .executeQuery(
                "UPDATE servers SET team_two = '"
                    + this.getTeamMembers(this.teams.get(1).getColor()).size()
                    + "' WHERE bungee_name = '"
                    + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase()
                    + "'");
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  @SuppressWarnings("deprecation")
  public void joinGame(Player player, String name) {

    int rank = 1;

    try {
      rank =
          HyperPVP.getStorage()
              .readInt32("SELECT rank FROM users WHERE username = '******'");
    } catch (SQLException e) {
      e.printStackTrace();
    }

    if (this.type == GameType.FFA) {

      List<Session> first = this.getTeamMembers(this.teams.get(0).getColor());

      if (first.size() >= this.maxPlayers && rank == 1) {

        System.out.println(this.maxPlayers);
        player.sendMessage(
            ChatColor.RED
                + "Teams full - "
                + ChatColor.GOLD
                + "hyperpvp.us/shop"
                + ChatColor.GREEN
                + " to join full teams or view other servers at "
                + ChatColor.GREEN
                + "hyperpvp.us/servers");
        return;
      }

    } else {

      List<Session> first = this.getTeamMembers(this.teams.get(0).getColor());
      List<Session> second = this.getTeamMembers(this.teams.get(1).getColor());

      if ((first.size() + second.size()) >= this.maxPlayers && rank == 1) {

        System.out.println(this.maxPlayers);
        player.sendMessage(
            ChatColor.RED
                + "Teams full - "
                + ChatColor.GOLD
                + "hyperpvp.us/shop"
                + ChatColor.GREEN
                + " to join full teams or view other servers at "
                + ChatColor.GREEN
                + "hyperpvp.us/servers");
        return;
      }
    }

    for (PotionEffect effect : player.getActivePotionEffects()) {
      player.removePotionEffect(effect.getType());
    }

    if (HyperPVP.hasMatchBeenAnnounced()) {
      player.setGameMode(GameMode.SURVIVAL);
    } else {
      player.setGameMode(GameMode.CREATIVE);
    }

    player.getInventory().clear();
    player.updateInventory();

    Session session = new Session(player);

    HyperPVP.getSpectators().remove(player.getName());
    CycleUtil.addGameSession(player, session);

    if (this.type == GameType.FFA) {
      session.setTeam(this.teams.get(0));
    } else {

      if (name != null) {

        TeamMap team = this.getTeamByName(name);
        session.setTeam(team);

      } else {

        List<Session> first = this.getTeamMembers(this.teams.get(0).getColor());
        List<Session> second = this.getTeamMembers(this.teams.get(1).getColor());

        if (first.size() == second.size()) {
          session.setTeam(this.teams.get(0));
        } else {

          if (first.size() > second.size()) {
            session.setTeam(this.teams.get(1));

          } else session.setTeam(this.teams.get(0));
        }
      }
    }

    /*if (HyperPVP.hasMatchBeenAnnounced()) {
    	player.sendMessage(this.matchInfoToString(player));
    }*/

    player.sendMessage(
        ChatColor.GRAY
            + "You joined the "
            + session.getTeam().getColor()
            + HyperPVP.capitalize(
                session
                    .getTeam()
                    .getColor()
                    .name()
                    .toLowerCase()
                    .replace("_", " ")
                    .replace("dark ", ""))
            + " Team");

    HyperPVP.setListName(session.getTeam().getColor(), player);

    TagAPI.refreshPlayer(player);

    player.setFallDistance(0F);

    if (HyperPVP.hasMatchBeenAnnounced()) {

      CycleUtil.hidePlayerWhereAppropriate(player, true);
      player.teleport(this.getRandomSpawn(player));
    }

    if (!HyperPVP.hasMatchBeenAnnounced()) {
      player.getInventory().clear();
      player.getInventory().addItem(new ItemStack(Material.COMPASS, 1));
      player.updateInventory();
      player.closeInventory();
    }

    try {
      HyperPVP.getStorage()
          .executeQuery(
              "UPDATE servers SET team_one = '"
                  + this.getTeamMembers(this.teams.get(0).getColor()).size()
                  + "' WHERE bungee_name = '"
                  + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase()
                  + "'");

      if (this.type != GameType.FFA) {
        HyperPVP.getStorage()
            .executeQuery(
                "UPDATE servers SET team_two = '"
                    + this.getTeamMembers(this.teams.get(1).getColor()).size()
                    + "' WHERE bungee_name = '"
                    + HyperPVP.getConfiguration().getConfig().getString("Server").toLowerCase()
                    + "'");
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    System.out.println(session.toValue());
  }