@ArenaEventHandler(suppressCastWarnings = true, priority = EventPriority.LOW)
  public void onEntityDamageEvent(EntityDamageEvent event) {
    if (!(event.getEntity() instanceof Player)) return;
    final TransitionOptions to = transitionOptions.getOptions(match.getMatchState());
    if (to == null) return;
    final PVPState pvp = to.getPVP();
    if (pvp == null) return;
    final ArenaPlayer target = BattleArena.toArenaPlayer((Player) event.getEntity());
    if (pvp == PVPState.INVINCIBLE) {
      /// all damage is cancelled
      target.setFireTicks(0);
      handler.setDamage(event, 0);
      event.setCancelled(true);
      return;
    }
    if (!(event instanceof EntityDamageByEntityEvent)) {
      return;
    }

    final Entity damagerEntity = ((EntityDamageByEntityEvent) event).getDamager();
    ArenaPlayer damager;
    switch (pvp) {
      case ON:
        ArenaTeam targetTeam = match.getTeam(target);
        if (targetTeam == null
            || !targetTeam.hasAliveMember(target)) // / We dont care about dead players
        return;
        damager = DmgDeathUtil.getPlayerCause(damagerEntity);
        if (damager == null) { // / damage from some source, its not pvp though. so we dont care
          return;
        }
        ArenaTeam t = match.getTeam(damager);
        if (t != null && t.hasMember(target)) { // / attacker is on the same team
          event.setCancelled(true);
        } else { /// different teams... lets make sure they can actually hit
          event.setCancelled(false);
        }
        break;
      case OFF:
        damager = DmgDeathUtil.getPlayerCause(damagerEntity);
        if (damager != null) { // / damage done from a player
          handler.setDamage(event, 0);
          event.setCancelled(true);
        }
        break;
      default:
        break;
    }
  }
示例#2
0
  @ArenaEventHandler(
      suppressCastWarnings = true,
      bukkitPriority = org.bukkit.event.EventPriority.MONITOR)
  public void onPlayerDeath(PlayerDeathEvent event, final ArenaPlayer target) {
    if (Defaults.DEBUG_TRACE)
      MessageUtil.sendMessage(target, " -onPlayerDeath  t=" + target.getTeam());
    if (state == MatchState.ONCANCEL || state == MatchState.ONCOMPLETE) {
      return;
    }
    final ArenaTeam t = getTeam(target);
    if (t == null) return;

    ArenaPlayerDeathEvent apde = new ArenaPlayerDeathEvent(target, t);
    apde.setPlayerDeathEvent(event);
    callEvent(apde);
    ArenaPlayer killer = DmgDeathUtil.getPlayerCause(event);
    if (killer != null) {
      ArenaTeam killT = getTeam(killer);
      if (killT != null) { // / they must be in the same match for this to count
        killT.addKill(killer);
        callEvent(new ArenaPlayerKillEvent(killer, killT, target));
      }
    }
  }