Пример #1
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onEntityExplode(EntityExplodeEvent event) {
   if (plugin.isInArena(event.getLocation())) {
     // Prevent block damage in arenas
     event.blockList().clear();
   }
 }
Пример #2
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityDamageByEntityHighest(EntityDamageByEntityEvent event) {
    Player attacker = getPlayer(event.getDamager());
    if (attacker == null) return;

    Player defender = getPlayer(event.getEntity());
    if (defender == null) return;

    ArenaPlayer ap = plugin.getArenaPlayer(attacker);
    if (ap != null) {
      ArenaPlayer dp = plugin.getArenaPlayer(defender);
      if (dp != null) {
        Arena arena = ap.getArena();
        if (arena.isInLobby()) {
          // Prevent lobby PvP
          ap.sendMessage("&cYou cannot PvP in the lobby!");
          event.setCancelled(true);
          return;
        }

        // Prevent team killing
        if (!arena.isAllowTeamKilling()) {
          if (dp.getTeam() == ap.getTeam()) {
            ap.sendMessage("&cYou cannot hurt your team mate!");
            event.setCancelled(true);
            return;
          }
        }
      } else {
        ap.sendMessage("&cYou cannot hurt players not in the arena!");
        event.setCancelled(true);
        return;
      }
    } else {
      if (plugin.isInArena(defender)) {
        attacker.sendMessage(
            plugin.getPrefix()
                + FormatUtil.format("&cYou cannot hurt players while they are in an arena!"));
        event.setCancelled(true);
        return;
      }
    }
  }
Пример #3
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDeath(EntityDeathEvent event) {
    // Handles deaths inside arenas
    Entity died = event.getEntity();
    if (died == null) return;

    // Clear the drops if in an arena
    if (plugin.isInArena(died.getLocation())) {
      event.getDrops().clear();
      event.setDroppedExp(0);
    }

    if (died instanceof Player) {
      Player pdied = (Player) died;
      ArenaPlayer dp = plugin.getArenaPlayer(pdied);
      if (dp != null) {
        // Prevent duplicate deaths
        if (dp.isDead()) return;
        dp.onDeath();

        Arena ar = dp.getArena();

        if (pdied.getKiller() instanceof Player) {
          Player killer = pdied.getKiller();
          if (killer.getName().equals(pdied.getName())) // Suicide
          {
            ar.tellPlayers("&e{0} &3commited &esuicide&3!", pdied.getName());
            dp.displayStats();
          } else {
            // PvP
            ar.tellPlayers(
                "&e{0} &3killed &e{1} &3with {2}",
                killer.getName(), pdied.getName(), getWeapon(killer));
            dp.displayStats();

            // Handle killer
            ArenaPlayer kp = plugin.getArenaPlayer(killer);
            if (kp != null) {
              kp.setKills(kp.getKills() + 1);
              kp.setKillStreak(kp.getKillStreak() + 1);
              kp.getArena().handleKillStreak(kp);
              kp.addXP(100);

              kp.displayStats();
            }
          }
        } else {
          // From this point on, we will return when there is a valid match
          if (pdied.getKiller() instanceof LivingEntity) {
            LivingEntity lentity = pdied.getKiller();
            String name = FormatUtil.getFriendlyName(lentity.getType());

            ar.tellPlayers(
                "&e{0} &3was killed by &3{1} &e{2}",
                pdied.getName(), FormatUtil.getArticle(name), name);
            dp.displayStats();
            return;
          } else if (pdied.getKiller() instanceof Projectile) {
            Projectile proj = (Projectile) pdied.getKiller();
            if (proj.getShooter() instanceof Player) {
              Player killer = (Player) proj.getShooter();
              ar.tellPlayers(
                  "&e{0} &3killed &e{1} &3with &e{2}",
                  killer.getName(), pdied.getName(), getWeapon(killer));
              dp.displayStats();

              // Handle killer
              ArenaPlayer kp = plugin.getArenaPlayer(killer);
              kp.setKills(kp.getKills() + 1);
              kp.setKillStreak(kp.getKillStreak() + 1);
              kp.getArena().handleKillStreak(kp);
              kp.addXP(100);

              kp.displayStats();
              return;
            } else if (proj.getShooter() instanceof LivingEntity) {
              LivingEntity lentity = pdied.getKiller();
              String name = FormatUtil.getFriendlyName(lentity.getType());

              ar.tellPlayers(
                  "&e{0} &3was killed by {1} &e{2}",
                  pdied.getName(), FormatUtil.getArticle(name), name);
              dp.displayStats();
              return;
            }
          }

          // Attempt to grab from their last damage cause
          EntityDamageEvent damageEvent = pdied.getLastDamageCause();
          DamageCause cause = damageEvent != null ? damageEvent.getCause() : null;

          if (cause == DamageCause.ENTITY_ATTACK) {
            if (damageEvent instanceof EntityDamageByEntityEvent) {
              EntityDamageByEntityEvent damageByEntity = (EntityDamageByEntityEvent) damageEvent;
              Entity damager = damageByEntity.getDamager();
              if (damager != null) {
                if (damager instanceof Player) {
                  Player killer = (Player) damager;
                  ar.tellPlayers(
                      "&e{0} &3killed &e{1} &3with {2}",
                      killer.getName(), pdied.getName(), getWeapon(killer));
                  dp.displayStats();

                  // Handle killer
                  ArenaPlayer kp = plugin.getArenaPlayer(killer);
                  if (kp != null) {
                    kp.setKills(kp.getKills() + 1);
                    kp.setKillStreak(kp.getKillStreak() + 1);
                    kp.getArena().handleKillStreak(kp);
                    kp.addXP(100);

                    kp.displayStats();
                  }
                } else {
                  String name = FormatUtil.getFriendlyName(damager.getType());
                  ar.tellPlayers(
                      "&e{0} &3was killed by &3{1} &e{2}",
                      pdied.getName(), FormatUtil.getArticle(name), name);
                  dp.displayStats();
                }

                return;
              }
            }
          } else if (cause == DamageCause.PROJECTILE) {
            if (damageEvent instanceof EntityDamageByEntityEvent) {
              EntityDamageByEntityEvent damageByEntity = (EntityDamageByEntityEvent) damageEvent;
              Entity damager = damageByEntity.getDamager();
              if (damager != null) {
                if (damager instanceof Projectile) {
                  Projectile proj = (Projectile) damager;
                  if (proj.getShooter() != null) {
                    if (proj.getShooter() instanceof Player) {
                      Player killer = (Player) proj.getShooter();

                      ar.tellPlayers(
                          "&e{0} &3killed &e{1} &3with {2}",
                          killer.getName(), pdied.getName(), getWeapon(killer));

                      dp.displayStats();

                      // Handle killer
                      ArenaPlayer kp = plugin.getArenaPlayer(killer);
                      if (kp != null) {
                        kp.setKills(kp.getKills() + 1);
                        kp.setKillStreak(kp.getKillStreak() + 1);
                        kp.getArena().handleKillStreak(kp);
                        kp.addXP(100);

                        kp.displayStats();
                      }
                    } else {
                      String name = "";
                      if (proj.getShooter() instanceof LivingEntity)
                        name =
                            FormatUtil.getFriendlyName(
                                ((LivingEntity) proj.getShooter()).getType());

                      ar.tellPlayers(
                          "&e{0} &3was shot by &3{1} &e{2}",
                          pdied.getName(), FormatUtil.getArticle(name), name);
                      dp.displayStats();
                    }

                    return;
                  }
                }
              }
            }
          } else if (cause != null) {
            // There's probably nothing else we can do here, so just turn it into a string
            ar.tellPlayers(
                "&e{0} &3was killed by &e{1}", pdied.getName(), FormatUtil.getFriendlyName(cause));
            dp.displayStats();
          } else if (ar instanceof SpleefArena) {
            // If they were in spleef, they probably fell through the floor
            ar.tellPlayers("&e{0} &3fell through the floor!", pdied.getName());
            dp.displayStats();
          } else {
            // No idea
            ar.tellPlayers("&e{0} &3died of unknown causes", pdied.getName());
            dp.displayStats();
          }
        }
      }
    } else {
      if (died instanceof LivingEntity) {
        LivingEntity lentity = (LivingEntity) died;
        if (lentity.getKiller() instanceof Player) {
          Player killer = lentity.getKiller();
          if (plugin.isInArena(killer)) {
            ArenaPlayer ak = plugin.getArenaPlayer(killer);

            // Selectively count mob kills
            if (ak.getArena().isCountMobKills()) {
              ak.addXP(25);
              ak.setKills(ak.getKills() + 1);
              ak.setKillStreak(ak.getKillStreak() + 1);
              ak.getArena().handleKillStreak(ak);

              String name = FormatUtil.getFriendlyName(lentity.getType());
              ak.sendMessage(
                  "&e{0} &3killed {1} &e{2}", killer.getName(), FormatUtil.getArticle(name), name);
              ak.displayStats();
            }
          }
        }
      }
    }
  }