Exemplo n.º 1
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityRegainHealth(EntityRegainHealthEvent event) {

    if (event.isCancelled()) {
      return; // respect other plugins
    }

    Entity p1 = event.getEntity();

    if ((p1 == null) || (!(p1 instanceof Player))) return; // no player

    Arena arena = Arenas.getArenaByPlayer((Player) p1);
    if (arena == null) return;

    db.i("onEntityRegainHealth => fighing player");
    if (!arena.fightInProgress) {
      return;
    }

    Player player = (Player) p1;

    ArenaPlayer ap = ArenaPlayer.parsePlayer(player);
    ArenaTeam team = Teams.getTeam(arena, ap);

    if (team == null) {
      return;
    }

    PVPArena.instance.getAmm().onEntityRegainHealth(arena, event);
  }
Exemplo n.º 2
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamage(EntityDamageEvent event) {

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

    Entity p2 = event.getEntity();

    db.i(
        "onEntityDamage: cause: " + event.getCause().name() + " : " + event.getEntity().toString());

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

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

    Player defender = (Player) p2;

    ArenaPlayer apDefender = ArenaPlayer.parsePlayer(defender);

    if (arena.REALEND_ID != -1
        || (!apDefender.getStatus().equals(Status.EMPTY)
            && !apDefender.getStatus().equals(Status.FIGHT))) {
      event.setCancelled(true);
      return;
    }
  }
  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);
    }
  }
Exemplo n.º 4
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());
  }