Beispiel #1
0
  public void clearSpecs() {

    for (int a = 0; a < spectators.size(); a = 0) {
      removeSpectator(Bukkit.getPlayerExact(spectators.get(0)));
    }
    spectators.clear();
    nextspec.clear();
  }
Beispiel #2
0
  @SuppressWarnings("deprecation")
  public boolean addPlayer(final Player p) {
    if (SettingsManager.getInstance().getLobbySpawn() == null) {
      msgmgr.sendFMessage(PrefixType.WARNING, "error.nolobbyspawn", p);
      return false;
    }
    if (!p.hasPermission("sg.arena.join." + gameID)) {
      debug("permission needed to join arena: " + "sg.arena.join." + gameID);
      msgmgr.sendFMessage(PrefixType.WARNING, "game.nopermission", p, "arena-" + gameID);
      return false;
    }
    HookManager.getInstance()
        .runHook(
            "GAME_PRE_ADDPLAYER",
            "arena-" + gameID,
            "player-" + p.getName(),
            "maxplayers-" + spawns.size(),
            "players-" + activePlayers.size());

    GameManager.getInstance().removeFromOtherQueues(p, gameID);

    if (GameManager.getInstance().getPlayerGameId(p) != -1) {
      if (GameManager.getInstance().isPlayerActive(p)) {
        msgmgr.sendMessage(PrefixType.ERROR, "Cannot join multiple games!", p);
        return false;
      }
    }
    if (p.isInsideVehicle()) {
      p.leaveVehicle();
    }
    if (spectators.contains(p)) removeSpectator(p);
    if (mode == GameMode.WAITING || mode == GameMode.STARTING) {
      if (activePlayers.size() < SettingsManager.getInstance().getSpawnCount(gameID)) {
        msgmgr.sendMessage(PrefixType.INFO, "Joining Arena '" + name + "'", p);
        PlayerJoinArenaEvent joinarena =
            new PlayerJoinArenaEvent(p, GameManager.getInstance().getGame(gameID));
        Bukkit.getServer().getPluginManager().callEvent(joinarena);
        if (joinarena.isCancelled()) return false;
        boolean placed = false;
        int spawnCount = SettingsManager.getInstance().getSpawnCount(gameID);

        for (int a = 1; a <= spawnCount; a++) {
          if (spawns.get(a) == null) {
            placed = true;
            spawns.put(a, p);
            p.setGameMode(org.bukkit.GameMode.SURVIVAL);

            // p.teleport(SettingsManager.getInstance().getLobbySpawn());
            p.teleport(SettingsManager.getInstance().getSpawnPoint(gameID, a));

            p.setHealth(p.getMaxHealth());
            p.setFoodLevel(20);
            p.getInventory().clear();
            p.getEquipment().setArmorContents(null);
            p.updateInventory();

            p.setFlying(false);
            p.setAllowFlight(false);
            p.setWalkSpeed(0.2F);
            p.setFireTicks(0);

            activePlayers.add(p);
            sm.addPlayer(p, gameID);

            scoreBoard.addPlayer(p);

            hookvars.put("activeplayers", activePlayers.size() + "");
            LobbyManager.getInstance().updateWall(gameID);
            HookManager.getInstance()
                .runHook("GAME_POST_ADDPLAYER", "activePlayers-" + activePlayers.size());

            if (spawnCount == activePlayers.size()) {
              countdown(5);
            }

            Bukkit.getServer()
                .getScheduler()
                .scheduleSyncDelayedTask(
                    GameManager.getInstance().getPlugin(),
                    new Runnable() {
                      public void run() {
                        p.setFlying(false);
                        p.setAllowFlight(false);
                        p.setWalkSpeed(0.2F);
                        p.setFireTicks(0);

                        p.getInventory().clear();
                        p.getEquipment().setArmorContents(null);
                        p.updateInventory();
                        showMenu(p);

                        for (PotionEffect effect : p.getActivePotionEffects()) {
                          p.removePotionEffect(effect.getType());
                        }
                      }
                    },
                    1L);

            break;
          }
        }
        if (!placed) {
          msgmgr.sendFMessage(PrefixType.ERROR, "error.gamefull", p, "arena-" + gameID);
          return false;
        }

      } else if (SettingsManager.getInstance().getSpawnCount(gameID) == 0) {
        msgmgr.sendMessage(PrefixType.WARNING, "No spawns set for Arena " + gameID + "!", p);
        return false;
      } else {
        msgmgr.sendFMessage(PrefixType.WARNING, "error.gamefull", p, "arena-" + gameID);
        return false;
      }
      msgFall(
          PrefixType.INFO,
          "game.playerjoingame",
          "player-" + p.getName(),
          "activeplayers-" + getActivePlayers(),
          "maxplayers-" + SettingsManager.getInstance().getSpawnCount(gameID));
      if (activePlayers.size() >= config.getInt("auto-start-players") && !countdownRunning)
        countdown(config.getInt("auto-start-time"));
      return true;
    } else {
      if (config.getBoolean("enable-player-queue")) {
        if (!queue.contains(p)) {
          queue.add(p);
          msgmgr.sendFMessage(
              PrefixType.INFO, "game.playerjoinqueue", p, "queuesize-" + queue.size());
        }
        int a = 1;
        for (Player qp : queue) {
          if (qp == p) {
            msgmgr.sendFMessage(PrefixType.INFO, "game.playercheckqueue", p, "queuepos-" + a);
            break;
          }
          a++;
        }
      }
    }
    if (mode == GameMode.INGAME) msgmgr.sendFMessage(PrefixType.WARNING, "error.alreadyingame", p);
    else if (mode == GameMode.DISABLED)
      msgmgr.sendFMessage(PrefixType.WARNING, "error.gamedisabled", p, "arena-" + gameID);
    else if (mode == GameMode.RESETING)
      msgmgr.sendFMessage(PrefixType.WARNING, "error.gamereseting", p);
    else msgmgr.sendMessage(PrefixType.INFO, "Cannot join game!", p);
    LobbyManager.getInstance().updateWall(gameID);
    return false;
  }