Пример #1
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamage(EntityDamageEvent event) {

    if (event.isCancelled() == false && !worlds.contains(event.getEntity().getWorld().getName())) {

      Entity attacker = null;
      Projectile projectile = null;
      if (event instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent ed = (EntityDamageByEntityEvent) event;
        attacker = ed.getDamager();

        // handle arrow attacks
        if (ed.getDamager() instanceof Projectile) {
          projectile = ((Projectile) attacker);
          attacker = projectile.getShooter();
        }
      }

      Entity entity = event.getEntity();
      if (entity instanceof ComplexEntityPart) {
        entity = ((ComplexEntityPart) entity).getParent();
      }
      int damage = event.getDamage();
      DamageCause cause = event.getCause();
      // if the player gets attacked
      if (entity instanceof Player) {
        // global damage count
        playerStatManager
            .getPlayerBlob(((Player) entity).getName())
            .getStat("damagetaken", "total")
            .incrementStat(damage);
        // handle projectiles
        if (projectile != null) {
          playerStatManager
              .getPlayerBlob(((Player) entity).getName())
              .getStat(
                  "damagetaken", projectile.getType().toString().toLowerCase().replace("_", ""))
              .incrementStat(damage);
        }

        playerStatManager
            .getPlayerBlob(((Player) entity).getName())
            .getStat("damagetaken", cause.toString().toLowerCase().replace("_", ""))
            .incrementStat(damage);

        // pvp damage
        if (attacker instanceof Player) {
          playerStatManager
              .getPlayerBlob(((Player) entity).getName())
              .getStat("damagetaken", "player")
              .incrementStat(damage);
          playerStatManager
              .getPlayerBlob(((Player) attacker).getName())
              .getStat("damagedealt", "player")
              .incrementStat(damage);
          // mob damage
        } else if (attacker != null) {
          playerStatManager
              .getPlayerBlob(((Player) entity).getName())
              .getStat("damagetaken", attacker.getType().toString().toLowerCase().replace("_", ""))
              .incrementStat(damage);
        }

      } else {
        if (attacker instanceof Player) {
          // global damage dealt
          playerStatManager
              .getPlayerBlob(((Player) attacker).getName())
              .getStat("damagedealt", "total")
              .incrementStat(damage);
          playerStatManager
              .getPlayerBlob(((Player) attacker).getName())
              .getStat("damagedealt", cause.toString().toLowerCase().replace("_", ""))
              .incrementStat(damage);
          playerStatManager
              .getPlayerBlob(((Player) attacker).getName())
              .getStat("damagedealt", entity.getType().toString().toLowerCase().replace("_", ""))
              .incrementStat(damage);
        }
      }
    }
  }
Пример #2
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDeath(EntityDeathEvent event) {
    Entity died = event.getEntity();
    if (died instanceof Player) {
      Player pdied = (Player) died;
      if (plugin.isInArena(pdied)) {
        event.getDrops().clear();
        plugin.getArena(pdied).onPlayerDeath(plugin.getArenaPlayer(pdied));
      }
    }

    EntityDamageEvent dev = event.getEntity().getLastDamageCause();
    if (dev != null) {
      if (dev.getEntity() != null) {
        if (dev.getEntity() instanceof Player) {
          Player dead = (Player) event.getEntity();
          if (dev.getCause() != null) {
            DamageCause dc = dev.getCause();
            if (dc.equals(DamageCause.ENTITY_ATTACK)) {
              Entity damager = ((EntityDamageByEntityEvent) dev).getDamager();
              if (plugin.isInArena(dead)) {
                String attackerName = damager.getType().getName();
                if (damager instanceof Player) {
                  attackerName = ((Player) damager).getName();
                }
                event.getDrops().clear();

                ArenaPlayer dp = plugin.getArenaPlayer(dead);
                dp.killstreak = 0;
                dp.deaths++;

                String line1 =
                    ChatColor.GREEN
                        + attackerName
                        + ChatColor.WHITE
                        + " 杀死了 "
                        + ChatColor.RED
                        + dead.getName();
                String line2 = ChatColor.RED + dead.getName() + " 你已被 " + attackerName + " 击杀";
                String line3 = ChatColor.RED + "----------------------------";
                String line4 = ChatColor.RED + "杀敌: " + dp.kills;
                String line5 = ChatColor.RED + "死亡: " + dp.deaths;
                String line6 = ChatColor.RED + "----------------------------";

                dead.sendMessage(line1);
                dead.sendMessage(line2);
                dead.sendMessage(line3);
                dead.sendMessage(line4);
                dead.sendMessage(line5);
                dead.sendMessage(line6);

                if (damager instanceof Player) {
                  Player attacker = (Player) ((EntityDamageByEntityEvent) dev).getDamager();
                  if (plugin.isInArena(attacker)) {
                    ArenaPlayer ap = plugin.getArenaPlayer(attacker);
                    ap.kills++;
                    ap.killstreak++;
                    ap.XP += 100;

                    line2 = ChatColor.RED + "杀死了 " + dead.getName() + " +100 XP";
                    line4 = ChatColor.RED + "杀敌: " + plugin.getArenaPlayer(attacker).kills;
                    line5 = ChatColor.RED + "死亡: " + plugin.getArenaPlayer(attacker).deaths;

                    attacker.sendMessage(line1);
                    attacker.sendMessage(line2);
                    attacker.sendMessage(line3);
                    attacker.sendMessage(line4);
                    attacker.sendMessage(line5);
                    attacker.sendMessage(line6);
                    Arena ar = plugin.getArena(attacker);
                    ar.doKillStreak(plugin.getArenaPlayer(attacker));

                    // Call kill event
                    UltimateArenaKillEvent killEvent = new UltimateArenaKillEvent(dp, ap, ar);
                    plugin.getServer().getPluginManager().callEvent(killEvent);
                  }
                }
              }

              return;
            } else if (dc.equals(DamageCause.PROJECTILE)) {
              if (((EntityDamageByEntityEvent) dev)
                  .getDamager()
                  .getType()
                  .toString()
                  .toLowerCase()
                  .equals("snowball")) {
                Entity bullet = ((EntityDamageByEntityEvent) dev).getDamager();
                if (bullet instanceof Snowball) {
                  if (((Snowball) ((EntityDamageByEntityEvent) dev).getDamager()).getShooter()
                      instanceof Player) {
                    Player gunner =
                        (Player)
                            ((Snowball) ((EntityDamageByEntityEvent) dev).getDamager())
                                .getShooter();
                    if (gunner != null && plugin.isInArena(gunner)) {
                      String gunnerp = gunner.getName();
                      event.getDrops().clear();

                      // Dead player
                      if (dead instanceof Player) {
                        if (plugin.isInArena(dead.getLocation())) {
                          Player deadplayer = (Player) dead;
                          ArenaPlayer dp = plugin.getArenaPlayer(deadplayer);

                          dp.killstreak = 0;
                          dp.deaths++;

                          String line1 =
                              ChatColor.GREEN
                                  + deadplayer.getName()
                                  + ChatColor.WHITE
                                  + " 已被 "
                                  + ChatColor.RED
                                  + gunnerp
                                  + ChatColor.WHITE
                                  + " 杀死";
                          String line2 = ChatColor.RED + "----------------------------";
                          String line3 =
                              ChatColor.RED + "杀敌: " + plugin.getArenaPlayer(deadplayer).kills;
                          String line4 =
                              ChatColor.RED + "死亡: " + plugin.getArenaPlayer(deadplayer).deaths;
                          String line5 = ChatColor.RED + "----------------------------";

                          deadplayer.sendMessage(line1);
                          deadplayer.sendMessage(line2);
                          deadplayer.sendMessage(line3);
                          deadplayer.sendMessage(line4);
                          deadplayer.sendMessage(line5);
                        }
                      }

                      // Killer
                      if (gunner instanceof Player) {
                        if (plugin.isInArena(gunner)) {
                          plugin.getArenaPlayer(gunner).killstreak++;
                          plugin.getArenaPlayer(gunner).kills++;
                          plugin.getArenaPlayer(gunner).XP += 25;

                          String line1 =
                              ChatColor.GREEN
                                  + gunnerp
                                  + ChatColor.WHITE
                                  + " 杀死了 "
                                  + ChatColor.RED
                                  + dead.getType().getName();
                          String line2 = ChatColor.RED + "----------------------------";
                          String line3 =
                              ChatColor.RED + "杀敌: " + plugin.getArenaPlayer(gunner).kills;
                          String line4 =
                              ChatColor.RED + "死亡: " + plugin.getArenaPlayer(gunner).deaths;
                          String line5 = ChatColor.RED + "----------------------------";

                          gunner.sendMessage(line1);
                          gunner.sendMessage(line2);
                          gunner.sendMessage(line3);
                          gunner.sendMessage(line4);
                          gunner.sendMessage(line5);
                        }
                      }
                    }
                  }
                }
              }

              return;
            } else {
              if (plugin.isInArena(dead)) {
                event.getDrops().clear();
                plugin.getArenaPlayer(dead).killstreak = 0;

                plugin.getArenaPlayer(dead).deaths++;
                String line2 = ChatColor.RED + dead.getName() + " 你已被 " + dc.toString() + " 杀死";
                String line3 = ChatColor.RED + "----------------------------";
                String line4 = ChatColor.RED + "杀敌: " + plugin.getArenaPlayer(dead).kills;
                String line5 = ChatColor.RED + "死亡: " + plugin.getArenaPlayer(dead).deaths;
                String line6 = ChatColor.RED + "----------------------------";

                dead.sendMessage(line2);
                dead.sendMessage(line3);
                dead.sendMessage(line4);
                dead.sendMessage(line5);
                dead.sendMessage(line6);
              }

              return;
            }
          }
        } else {
          LivingEntity dead = (LivingEntity) event.getEntity();
          if (dev.getCause() != null) {
            DamageCause dc = dev.getCause();
            if (dc.equals(DamageCause.PROJECTILE)) {
              if (((EntityDamageByEntityEvent) dev)
                  .getDamager()
                  .getType()
                  .toString()
                  .equalsIgnoreCase("snowball")) {
                Entity bullet = ((EntityDamageByEntityEvent) dev).getDamager();
                if (bullet instanceof Snowball) {
                  if (((Snowball) ((EntityDamageByEntityEvent) dev).getDamager()).getShooter()
                      instanceof Player) {
                    Player gunner =
                        (Player)
                            ((Snowball) ((EntityDamageByEntityEvent) dev).getDamager())
                                .getShooter();
                    if (gunner != null) {
                      String gunnerp = gunner.getName();
                      event.getDrops().clear();

                      // Dead player
                      if (dead instanceof Player) {
                        if (plugin.isInArena(dead.getLocation())) {
                          Player deadplayer = (Player) dead;
                          plugin.getArenaPlayer(deadplayer).killstreak = 0;
                          plugin.getArenaPlayer(deadplayer).deaths++;
                          String line1 =
                              ChatColor.GREEN
                                  + deadplayer.getName()
                                  + ChatColor.WHITE
                                  + " 已被 "
                                  + ChatColor.RED
                                  + gunnerp
                                  + ChatColor.WHITE
                                  + " 杀死";
                          String line2 = ChatColor.RED + "----------------------------";
                          String line3 =
                              ChatColor.RED + "杀敌: " + plugin.getArenaPlayer(deadplayer).kills;
                          String line4 =
                              ChatColor.RED + "死亡: " + plugin.getArenaPlayer(deadplayer).deaths;
                          String line5 = ChatColor.RED + "----------------------------";

                          deadplayer.sendMessage(line1);
                          deadplayer.sendMessage(line2);
                          deadplayer.sendMessage(line3);
                          deadplayer.sendMessage(line4);
                          deadplayer.sendMessage(line5);
                        }
                      }

                      // Killer
                      if (gunner instanceof Player) {
                        if (plugin.isInArena(gunner)) {
                          plugin.getArenaPlayer(gunner).killstreak++;
                          plugin.getArenaPlayer(gunner).kills++;
                          plugin.getArenaPlayer(gunner).XP += 25;

                          String line1 =
                              ChatColor.GREEN
                                  + gunnerp
                                  + ChatColor.WHITE
                                  + " 杀死了 "
                                  + ChatColor.RED
                                  + dead.getType().getName();
                          String line2 = ChatColor.RED + "----------------------------";
                          String line3 =
                              ChatColor.RED + "杀敌: " + plugin.getArenaPlayer(gunner).kills;
                          String line4 =
                              ChatColor.RED + "死亡: " + plugin.getArenaPlayer(gunner).deaths;
                          String line5 = ChatColor.RED + "----------------------------";

                          gunner.sendMessage(line1);
                          gunner.sendMessage(line2);
                          gunner.sendMessage(line3);
                          gunner.sendMessage(line4);
                          gunner.sendMessage(line5);
                        }
                      }

                      if ((gunner instanceof Player) && (dead instanceof Player)) {
                        if ((gunner != null) && (dead != null)) {
                          ArenaPlayer ag = plugin.getArenaPlayer(gunner);
                          ArenaPlayer ad = plugin.getArenaPlayer((Player) dead);
                          Arena ar = plugin.getArena(gunner);

                          UltimateArenaKillEvent killEvent = new UltimateArenaKillEvent(ad, ag, ar);
                          plugin.getServer().getPluginManager().callEvent(killEvent);
                        }
                      }
                    }
                  }
                }
              }

              return;
            } else if (dc.equals(DamageCause.ENTITY_ATTACK)) {
              Entity damager = ((EntityDamageByEntityEvent) dev).getDamager();
              if (damager instanceof Player) {
                Player attacker = (Player) ((EntityDamageByEntityEvent) dev).getDamager();
                if (plugin.isInArena(attacker)) {
                  event.getDrops().clear();
                  if (plugin.isInArena(attacker.getLocation())) {
                    plugin.getArenaPlayer(attacker).kills++;
                    plugin.getArenaPlayer(attacker).killstreak++;
                    plugin.getArenaPlayer(attacker).XP += 25;

                    String attstr = dead.getType().getName();

                    String line1 =
                        ChatColor.GREEN
                            + attacker.getName()
                            + ChatColor.WHITE
                            + " 杀死了 "
                            + ChatColor.RED
                            + attstr;
                    String line2 = ChatColor.RED + "杀死了 " + attstr + " +25 XP";
                    String line3 = ChatColor.RED + "----------------------------";
                    String line4 = ChatColor.RED + "杀敌: " + plugin.getArenaPlayer(attacker).kills;
                    String line5 = ChatColor.RED + "死亡: " + plugin.getArenaPlayer(attacker).deaths;
                    String line6 = ChatColor.RED + "----------------------------";

                    attacker.sendMessage(line1);
                    attacker.sendMessage(line2);
                    attacker.sendMessage(line3);
                    attacker.sendMessage(line4);
                    attacker.sendMessage(line5);
                    attacker.sendMessage(line6);

                    Arena ar = plugin.getArena(attacker);
                    ar.doKillStreak(plugin.getArenaPlayer(attacker));
                  }
                }
              }

              return;
            } else if (dc.equals(DamageCause.PROJECTILE)) {
              Entity damager = ((EntityDamageByEntityEvent) dev).getDamager();
              if (damager instanceof Arrow) {
                if (((Arrow) ((EntityDamageByEntityEvent) dev).getDamager()).getShooter()
                    instanceof Player) {
                  Player attacker =
                      (Player)
                          ((Arrow) ((EntityDamageByEntityEvent) dev).getDamager()).getShooter();
                  if (plugin.isInArena(attacker)) {
                    event.getDrops().clear();
                    if (plugin.isInArena(attacker.getLocation())) {
                      plugin.getArenaPlayer(attacker).kills++;
                      plugin.getArenaPlayer(attacker).killstreak++;
                      plugin.getArenaPlayer(attacker).XP += 25;

                      String attstr = dead.getType().getName();

                      String line1 =
                          ChatColor.GREEN
                              + attacker.getName()
                              + ChatColor.WHITE
                              + " 杀死了 "
                              + ChatColor.RED
                              + attstr;
                      String line2 = ChatColor.RED + "杀死了 " + attstr + " +25 XP";
                      String line3 = ChatColor.RED + "----------------------------";
                      String line4 = ChatColor.RED + "杀敌: " + plugin.getArenaPlayer(attacker).kills;
                      String line5 =
                          ChatColor.RED + "死亡: " + plugin.getArenaPlayer(attacker).deaths;
                      String line6 = ChatColor.RED + "----------------------------";

                      attacker.sendMessage(line1);
                      attacker.sendMessage(line2);
                      attacker.sendMessage(line3);
                      attacker.sendMessage(line4);
                      attacker.sendMessage(line5);
                      attacker.sendMessage(line6);

                      Arena ar = plugin.getArena(attacker);
                      ar.doKillStreak(plugin.getArenaPlayer(attacker));
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
Пример #3
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDeath(EntityDeathEvent event) {

    EntityDamageEvent lastCause = event.getEntity().getLastDamageCause();
    DamageCause cause = null;
    if (lastCause != null) {
      cause = lastCause.getCause();
    }

    Entity attacker = null;
    Projectile projectile = null;
    if (lastCause instanceof EntityDamageByEntityEvent) {
      attacker = ((EntityDamageByEntityEvent) lastCause).getDamager();
      BeardStat.printDebugCon("attack ID'd Fired"); // Type.ENTITY_DEATH
      if (attacker instanceof Projectile) {
        projectile = ((Projectile) attacker);
        attacker = projectile.getShooter();
      }
    }
    Entity entity = event.getEntity();

    // set attacker and entity total k/d accordingly
    if (entity instanceof Player) {
      playerStatManager
          .getPlayerBlob(((Player) entity).getName())
          .getStat("deaths", "total")
          .incrementStat(1);
      if (cause != null) {
        playerStatManager
            .getPlayerBlob(((Player) entity).getName())
            .getStat("deaths", cause.toString().toLowerCase().replace("_", ""))
            .incrementStat(1);
      }
      if (projectile != null) {
        playerStatManager
            .getPlayerBlob(((Player) entity).getName())
            .getStat("deaths", projectile.getType().toString().toLowerCase().replace("_", ""))
            .incrementStat(1);
      }
    }

    if (attacker instanceof Player) {
      playerStatManager
          .getPlayerBlob(((Player) attacker).getName())
          .getStat("kills", "total")
          .incrementStat(1);
      if (cause != null) {
        playerStatManager
            .getPlayerBlob(((Player) attacker).getName())
            .getStat("kills", cause.toString().toLowerCase().replace("_", ""))
            .incrementStat(1);
      }
      if (projectile != null) {
        playerStatManager
            .getPlayerBlob(((Player) attacker).getName())
            .getStat("kills", projectile.getType().toString().toLowerCase().replace("_", ""))
            .incrementStat(1);
      }
    }

    // PVP
    if (entity instanceof Player && attacker instanceof Player) {
      playerStatManager
          .getPlayerBlob(((Player) entity).getName())
          .getStat("deaths", "player")
          .incrementStat(1);
      playerStatManager
          .getPlayerBlob(((Player) attacker).getName())
          .getStat("kills", "player")
          .incrementStat(1);
    }
    // global damage count

    // PLAYER KILLS ENTITY

    if ((entity instanceof Player) == false && attacker instanceof Player) {
      // global damage dealt
      // playerStatManager.getPlayerBlob(((Player)attacker).getName()).getStat("kill_by_"+
      // cause.toString().toLowerCase()).incrementStat(1);
      playerStatManager
          .getPlayerBlob(((Player) attacker).getName())
          .getStat("kills", entity.getType().toString().replace("_", "").toLowerCase())
          .incrementStat(1);
    }
    // ENTITY KILLS PLAYER
    if ((entity instanceof Player) && !(attacker instanceof Player) && attacker != null) {
      playerStatManager
          .getPlayerBlob(((Player) entity).getName())
          .getStat("deaths", attacker.getType().toString().replace("_", ""))
          .incrementStat(1);
    }
  }