Exemplo n.º 1
0
  private void commit(final Arena arena, final String sTeam) {
    arena.getDebugger().i("[BD] checking end: " + sTeam);
    arena.getDebugger().i("win: " + false);

    for (final ArenaTeam team : arena.getTeams()) {
      if (!team.getName().equals(sTeam)) {
        /*
        team is sTeam and win
        team is not sTeam and not win
        */
        continue;
      }
      for (final ArenaPlayer ap : team.getTeamMembers()) {
        if (ap.getStatus() == Status.FIGHT || ap.getStatus() == Status.DEAD) {
          ap.addLosses();
          /*
          arena.removePlayer(ap.get(), CFG.TP_LOSE.toString(),
          		true, false);*/

          ap.setStatus(Status.LOST);

          // ap.setTelePass(false);
        }
      }
    }
    /*
    if (!win && getLifeMap().size() > 1) {
    	return; // if not a win trigger AND more than one team left. out!
    }

    for (ArenaTeam team : arena.getTeams()) {
    	for (ArenaPlayer ap : team.getTeamMembers()) {
    		if (!ap.getStatus().equals(Status.FIGHT)) {
    			continue;
    		}
    		winteam = team.getName();
    		break;
    	}
    }

    if (arena.getTeam(winteam) != null) {

    	ArenaModuleManager
    			.announce(
    					arena,
    					Language.parse(arena, MSG.TEAM_HAS_WON,
    							arena.getTeam(winteam).getColor()
    									+ winteam + ChatColor.YELLOW),
    					"WINNER");
    	arena.broadcast(Language.parse(arena, MSG.TEAM_HAS_WON,
    			arena.getTeam(winteam).getColor() + winteam
    					+ ChatColor.YELLOW));
    }

    getLifeMap().clear();
    new EndRunnable(arena, arena.getArenaConfig().getInt(
    		CFG.TIME_ENDCOUNTDOWN));
    		*/
    PACheck.handleEnd(arena, false);
  }
Exemplo n.º 2
0
  @Override
  public PACheck checkJoin(final CommandSender sender, final PACheck res, final String[] args) {
    if (res.getPriority() >= PRIORITY) {
      return res;
    }

    final int maxPlayers = arena.getArenaConfig().getInt(CFG.READY_MAXPLAYERS);
    final int maxTeamPlayers = arena.getArenaConfig().getInt(CFG.READY_MAXTEAMPLAYERS);

    if (maxPlayers > 0 && arena.getFighters().size() >= maxPlayers) {
      res.setError(this, Language.parse(arena, MSG.ERROR_JOIN_ARENA_FULL));
      return res;
    }

    if (args == null || args.length < 1) {
      return res;
    }

    if (!arena.isFreeForAll()) {
      final ArenaTeam team = arena.getTeam(args[0]);

      if (team != null && maxTeamPlayers > 0 && team.getTeamMembers().size() >= maxTeamPlayers) {
        res.setError(this, Language.parse(arena, MSG.ERROR_JOIN_TEAM_FULL));
        return res;
      }
    }

    res.setPriority(this, PRIORITY);
    return res;
  }
Exemplo n.º 3
0
  @Override
  public void parseStart() {
    getLifeMap().clear();
    for (final ArenaTeam team : arena.getTeams()) {
      if (!team.getTeamMembers().isEmpty()) {
        arena.getDebugger().i("adding team " + team.getName());
        // team is active
        getLifeMap()
            .put(team.getName(), arena.getArenaConfig().getInt(CFG.GOAL_BLOCKDESTROY_LIVES, 1));
      }
      final Set<PABlockLocation> blocks = SpawnManager.getBlocksContaining(arena, "block");

      for (final PABlockLocation block : blocks) {
        takeBlock(team.getColor().name(), block);
      }
    }
  }
Exemplo n.º 4
0
  @Override
  public void commitEnd(final boolean force) {
    if (arena.realEndRunner != null) {
      arena.getDebugger().i("[BD] already ending");
      return;
    }
    arena.getDebugger().i("[BD]");

    final PAGoalEvent gEvent = new PAGoalEvent(arena, this, "");
    Bukkit.getPluginManager().callEvent(gEvent);
    ArenaTeam aTeam = null;

    for (final ArenaTeam team : arena.getTeams()) {
      for (final ArenaPlayer ap : team.getTeamMembers()) {
        if (ap.getStatus() == Status.FIGHT) {
          aTeam = team;
          break;
        }
      }
    }

    if (aTeam != null && !force) {
      ArenaModuleManager.announce(
          arena,
          Language.parse(
              arena, MSG.TEAM_HAS_WON, aTeam.getColor() + aTeam.getName() + ChatColor.YELLOW),
          "END");

      ArenaModuleManager.announce(
          arena,
          Language.parse(
              arena, MSG.TEAM_HAS_WON, aTeam.getColor() + aTeam.getName() + ChatColor.YELLOW),
          "WINNER");
      arena.broadcast(
          Language.parse(
              arena, MSG.TEAM_HAS_WON, aTeam.getColor() + aTeam.getName() + ChatColor.YELLOW));
    }

    if (ArenaModuleManager.commitEnd(arena, aTeam)) {
      return;
    }
    new EndRunnable(arena, arena.getArenaConfig().getInt(CFG.TIME_ENDCOUNTDOWN));
  }
Exemplo n.º 5
0
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
  public void onBlockBreak(final BlockBreakEvent event) {
    final Player player = event.getPlayer();
    if (!arena.hasPlayer(event.getPlayer())
        || !event
            .getBlock()
            .getType()
            .name()
            .equals(arena.getArenaConfig().getString(CFG.GOAL_BLOCKDESTROY_BLOCKTYPE))) {

      arena.getDebugger().i("block destroy, ignoring", player);
      arena.getDebugger().i(String.valueOf(arena.hasPlayer(event.getPlayer())), player);
      arena.getDebugger().i(event.getBlock().getType().name(), player);
      return;
    }

    if (!arena.isFightInProgress()) {
      event.setCancelled(true);
      return;
    }

    final Block block = event.getBlock();

    arena.getDebugger().i("block destroy!", player);

    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());

    final ArenaTeam pTeam = aPlayer.getArenaTeam();
    if (pTeam == null) {
      return;
    }

    Vector vBlock = null;
    for (final ArenaTeam team : arena.getTeams()) {
      final String blockTeam = team.getName();

      if (team.getTeamMembers().size() < 1 && !"touchdown".equals(team.getName())) {
        arena.getDebugger().i("size!OUT! ", player);
        continue; // dont check for inactive teams
      }

      arena.getDebugger().i("checking for block of team " + blockTeam, player);
      Vector vLoc = block.getLocation().toVector();
      arena.getDebugger().i("block: " + vLoc, player);
      if (!SpawnManager.getBlocksStartingWith(arena, blockTeam + "block").isEmpty()) {
        vBlock =
            SpawnManager.getBlockNearest(
                    SpawnManager.getBlocksStartingWith(arena, blockTeam + "block"),
                    new PABlockLocation(player.getLocation()))
                .toLocation()
                .toVector();
      }
      if (vBlock != null && vLoc.distance(vBlock) < 2) {

        // ///////

        if (blockTeam.equals(pTeam.getName())) {
          arena.getDebugger().i("is own team! cancel and OUT! ", player);
          event.setCancelled(true);
          continue;
        }
        PAGoalEvent gEvent = new PAGoalEvent(arena, this, "trigger:" + player.getName());
        Bukkit.getPluginManager().callEvent(gEvent);
        final String sTeam = pTeam.getName();

        try {
          arena.broadcast(
              Language.parse(
                  arena,
                  MSG.GOAL_BLOCKDESTROY_SCORE,
                  arena.getTeam(sTeam).colorizePlayer(player) + ChatColor.YELLOW,
                  arena.getTeam(blockTeam).getColoredName() + ChatColor.YELLOW,
                  String.valueOf(getLifeMap().get(blockTeam) - 1)));
        } catch (final Exception e) {
          Bukkit.getLogger().severe("[PVP Arena] team unknown/no lives: " + blockTeam);
          e.printStackTrace();
        }

        gEvent =
            new PAGoalEvent(
                arena,
                this,
                "score:" + player.getName() + ':' + aPlayer.getArenaTeam().getName() + ":1");
        Bukkit.getPluginManager().callEvent(gEvent);
        class RunLater implements Runnable {
          String localColor;
          PABlockLocation localLoc;

          RunLater(final String color, final PABlockLocation loc) {
            localColor = color;
            localLoc = loc;
          }

          @Override
          public void run() {
            takeBlock(localColor, localLoc);
          }
        }

        if (getLifeMap().containsKey(blockTeam)
            && getLifeMap().get(blockTeam)
                > SpawnManager.getBlocksStartingWith(arena, blockTeam + "block").size()) {

          Bukkit.getScheduler()
              .runTaskLater(
                  PVPArena.instance,
                  new RunLater(
                      arena.getTeam(blockTeam).getColor().name(),
                      new PABlockLocation(event.getBlock().getLocation())),
                  5L);
        }
        reduceLivesCheckEndAndCommit(arena, blockTeam);

        return;
      }
    }
  }
Exemplo n.º 6
0
  /**
   * parsing of damage: Entity vs Entity
   *
   * @param event the triggering event
   */
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {

    if (event.isCancelled()) {
      return;
    }

    Entity p1 = event.getDamager();
    Entity p2 = event.getEntity();

    db.i(
        "onEntityDamageByEntity: cause: "
            + event.getCause().name()
            + " : "
            + event.getDamager().toString()
            + " => "
            + event.getEntity().toString());

    if (p1 instanceof Projectile) {
      db.i("parsing projectile");
      p1 = ((Projectile) p1).getShooter();
      db.i("=> " + String.valueOf(p1));
    }

    if (event.getEntity() instanceof Wolf) {
      Wolf wolf = (Wolf) event.getEntity();
      if (wolf.getOwner() != null) {
        try {
          p1 = (Entity) wolf.getOwner();
        } catch (Exception e) {
          // wolf belongs to dead player or whatnot
        }
      }
    }

    if ((p1 != null && p2 != null) && p1 instanceof Player && p2 instanceof Player) {
      if (PVPArena.instance.getConfig().getBoolean("onlyPVPinArena")) {
        event.setCancelled(true); // cancel events for regular no PVP
        // servers
      }
    }

    if ((p2 == null) || (!(p2 instanceof Player))) {
      return;
    }

    Arena arena = Arenas.getArenaByPlayer((Player) p2);
    if (arena == null) {
      // defender no arena player => out
      return;
    }

    db.i("onEntityDamageByEntity: fighting player");

    if ((p1 == null) || (!(p1 instanceof Player))) {
      // attacker no player => out!
      return;
    }

    db.i("both entities are players");
    Player attacker = (Player) p1;
    Player defender = (Player) p2;

    if (attacker.equals(defender)) {
      // player attacking himself. ignore!
      return;
    }

    boolean defTeam = false;
    boolean attTeam = false;
    ArenaPlayer apDefender = ArenaPlayer.parsePlayer(defender);
    ArenaPlayer apAttacker = ArenaPlayer.parsePlayer(attacker);

    for (ArenaTeam team : arena.getTeams()) {
      defTeam = defTeam ? true : team.getTeamMembers().contains(apDefender);
      attTeam = attTeam ? true : team.getTeamMembers().contains(apAttacker);
    }

    if (!defTeam || !attTeam || arena.REALEND_ID != -1) {
      event.setCancelled(true);
      return;
    }

    db.i("both players part of the arena");

    if (PVPArena.instance.getConfig().getBoolean("onlyPVPinArena")) {
      event.setCancelled(false); // uncancel events for regular no PVP
      // servers
    }

    if ((!arena.cfg.getBoolean("game.teamKill", false))
        && (Teams.getTeam(arena, apAttacker)).equals(Teams.getTeam(arena, apDefender))) {
      // no team fights!
      db.i("team hit, cancel!");
      event.setCancelled(true);
      return;
    }

    if (!arena.fightInProgress) {
      // fight not started, cancel!
      event.setCancelled(true);
      return;
    }

    if (arena.cfg.getBoolean("game.weaponDamage")) {
      if (Inventories.receivesDamage(attacker.getItemInHand())) {
        attacker.getItemInHand().setDurability((short) 0);
      }
    }

    // TODO NOT LAGGING

    if (arena.cfg.getInt("protection.spawn") > 0) {
      if (Spawns.isNearSpawn(arena, defender, arena.cfg.getInt("protection.spawn"))) {
        // spawn protection!
        db.i("spawn protection! damage cancelled!");
        event.setCancelled(true);
        return;
      }
    }

    // here it comes, process the damage!

    db.i("processing damage!");

    PVPArena.instance.getAmm().onEntityDamageByEntity(arena, attacker, defender, event);

    Statistics.damage(arena, attacker, defender, event.getDamage());
  }