Exemplo n.º 1
0
 @Override
 public void onPlayerDeath(ArenaPlayer pl) {
   if (pl.getTeam() == Team.RED) {
     pl.sendMessage(getMessage("joinedInfected"));
     pl.setTeam(Team.BLUE);
   }
 }
Exemplo n.º 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;
      }
    }
  }
Exemplo n.º 3
0
 private final void chooseInfected(int tries) {
   if (tries < 16) {
     ArenaPlayer ap = active.get(Util.random(active.size()));
     if (ap != null && ap.isOnline()) {
       ap.setTeam(Team.BLUE);
       ap.sendMessage(getMessage("patientZero"));
       onSpawn(ap);
       tellPlayers(getMessage("zombie"), ap.getName());
     } else {
       chooseInfected(tries++);
     }
   } else {
     // Shouldn't happen...
     tellPlayers(getMessage("couldntFindZombie"));
     stop();
   }
 }
Exemplo n.º 4
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamageByEntityMonitor(EntityDamageByEntityEvent event) {
    Player player = getPlayer(event.getDamager());
    if (player == null) return;

    ArenaPlayer ap = plugin.getArenaPlayer(player);
    if (ap != null) {
      // Repair in-hand item
      ItemStack inHand = player.getItemInHand();
      if (inHand != null && inHand.getType() != Material.AIR) {
        if (inHand.getType().getMaxDurability() != 0) {
          inHand.setDurability((short) 0);
        }
      }

      // Repair armor
      for (ItemStack armor : player.getInventory().getArmorContents()) {
        if (armor != null && armor.getType() != Material.AIR) {
          armor.setDurability((short) 0);
        }
      }

      // Healer class
      if (inHand != null && inHand.getType() == Material.GOLD_AXE) {
        Player damaged = getPlayer(event.getEntity());
        if (damaged != null) {
          ArenaPlayer dp = plugin.getArenaPlayer(damaged);
          if (dp != null) {
            if (ap.getTeam() == dp.getTeam()) {
              ArenaClass ac = ap.getArenaClass();
              if (ac != null && ac.getName().equalsIgnoreCase("healer")) {
                Player heal = dp.getPlayer();
                double health = heal.getHealth();
                double maxHealth = heal.getMaxHealth();
                if (health > 0.0D && health < maxHealth) {
                  heal.setHealth(Math.min(health + 2.0D, maxHealth));
                  ap.sendMessage("&3You have healed &e{0} &3for &e1 &3heart!", dp.getName());
                }
              }
            }
          }
        }
      }
    }
  }
Exemplo n.º 5
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();
            }
          }
        }
      }
    }
  }