@Override
  public void tpPlayerToCoordName(Arena arena, Player player, String place) {
    if (arena.cfg.getBoolean("messages.colorNick", true)) {
      if (spoutHandler != null) {
        colorizePlayer(arena, player);
      } else {
        ArenaTeam team = Teams.getTeam(arena, ArenaPlayer.parsePlayer(player));
        String n;
        if (team == null) {
          db.i("> team is null");
          n = player.getName();
        } else {
          n = team.getColorString() + player.getName();
        }
        n = n.replaceAll("(&([a-f0-9]))", "§$2");

        player.setDisplayName(n);

        if (team != null && arena.cfg.getBoolean("game.hideName")) {
          n = " ";
        }

        updateName(player, n);
      }
    }
  }
Example #2
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);
  }
Example #3
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;
  }
Example #4
0
 @Override
 public List<String> getMain() {
   final List<String> result = Collections.singletonList("blocktype");
   if (arena != null) {
     for (final ArenaTeam team : arena.getTeams()) {
       final String sTeam = team.getName();
       result.add(sTeam + "block");
     }
   }
   return result;
 }
Example #5
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);
      }
    }
  }
Example #6
0
  @Override
  public void initate(final Player player) {
    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());
    final ArenaTeam team = aPlayer.getArenaTeam();
    if (!getLifeMap().containsKey(team.getName())) {
      getLifeMap()
          .put(
              aPlayer.getArenaTeam().getName(),
              arena.getArenaConfig().getInt(CFG.GOAL_BLOCKDESTROY_LIVES));

      final Set<PABlockLocation> blocks = SpawnManager.getBlocksContaining(arena, "block");

      for (final PABlockLocation block : blocks) {
        takeBlock(team.getColor().name(), block);
      }
    }
  }
Example #7
0
  @Override
  public void commitCommand(final CommandSender sender, final String[] args) {
    if ("blocktype".equalsIgnoreCase(args[0])) {
      if (args.length < 2) {
        arena.msg(
            sender,
            Language.parse(
                arena, MSG.ERROR_INVALID_ARGUMENT_COUNT, String.valueOf(args.length), "2"));
        return;
      }

      try {
        final int value = Integer.parseInt(args[1]);
        arena
            .getArenaConfig()
            .set(CFG.GOAL_BLOCKDESTROY_BLOCKTYPE, Material.getMaterial(value).name());
      } catch (final Exception e) {
        final Material mat = Material.getMaterial(args[1].toUpperCase());

        if (mat == null) {
          arena.msg(sender, Language.parse(arena, MSG.ERROR_MAT_NOT_FOUND, args[1]));
          return;
        }

        arena.getArenaConfig().set(CFG.GOAL_BLOCKDESTROY_BLOCKTYPE, mat.name());
      }
      arena.getArenaConfig().save();
      arena.msg(
          sender,
          Language.parse(
              arena, MSG.GOAL_BLOCKDESTROY_TYPESET, CFG.GOAL_BLOCKDESTROY_BLOCKTYPE.toString()));

    } else if (args[0].contains("block")) {
      for (final ArenaTeam team : arena.getTeams()) {
        final String sTeam = team.getName();
        if (args[0].contains(sTeam + "block")) {
          blockTeamName = args[0];
          PAA_Region.activeSelections.put(sender.getName(), arena);

          arena.msg(sender, Language.parse(arena, MSG.GOAL_BLOCKDESTROY_TOSET, blockTeamName));
        }
      }
    }
  }
Example #8
0
  @Override
  public PACheck checkCommand(final PACheck res, final String string) {
    if (res.getPriority() > PRIORITY) {
      return res;
    }

    if ("blocktype".equalsIgnoreCase(string)) {
      res.setPriority(this, PRIORITY);
    }

    for (final ArenaTeam team : arena.getTeams()) {
      final String sTeam = team.getName();
      if (string.contains(sTeam + "block")) {
        res.setPriority(this, PRIORITY);
      }
    }

    return res;
  }
  private void colorizePlayer(Arena a, Player player) {
    db.i("colorizing player " + player.getName() + ";");

    Arena arena = Arenas.getArenaByPlayer(player);
    if (arena == null) {
      db.i("> arena is null");
      if (spoutHandler != null) {
        SpoutManager.getPlayer(player).setTitle(player.getName());
      } else if (!a.cfg.getBoolean("colors.requireSpout")) {
        disguise(player, player.getName());
      }
      return;
    }

    ArenaTeam team = Teams.getTeam(arena, ArenaPlayer.parsePlayer(player));
    String n;
    if (team == null) {
      db.i("> team is null");
      if (spoutHandler != null) {
        SpoutManager.getPlayer(player).setTitle(player.getName());
      } else if (!a.cfg.getBoolean("colors.requireSpout")) {
        disguise(player, player.getName());
      }
      return;
    } else {
      n = team.getColorString() + player.getName();
    }
    n = n.replaceAll("(&([a-f0-9]))", "§$2");

    player.setDisplayName(n);

    if (arena.cfg.getBoolean("game.hideName")) {
      n = " ";
    }
    if (spoutHandler != null) {
      SpoutManager.getPlayer(player).setTitle(n);
    } else if (!a.cfg.getBoolean("colors.requireSpout")) {
      disguise(player, n);
    }
  }
Example #10
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));
  }
Example #11
0
  @Override
  public Map<String, Double> timedEnd(final Map<String, Double> scores) {

    for (final ArenaTeam team : arena.getTeams()) {
      double score =
          getLifeMap().containsKey(team.getName()) ? getLifeMap().get(team.getName()) : 0;
      if (scores.containsKey(team.getName())) {
        scores.put(team.getName(), scores.get(team.getName()) + score);
      } else {
        scores.put(team.getName(), score);
      }
    }

    return scores;
  }
Example #12
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;
      }
    }
  }
Example #13
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());
  }