@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onEntityDeath(EntityDeathEvent event) {
    // TODO: use get getLastDamageCause rather than checking on each
    // getdamage?
    Log.logInfo(
        "*** OnEntityDeath, before checks (victim: " + event.getEntity().toString() + ")", HIGHEST);
    Entity entity = event.getEntity();

    // If there's no damage record, ignore
    if (entity.getLastDamageCause() == null) {
      Log.logWarning(
          "OnEntityDeath: entity " + entity.toString() + " has no 'lastDamageCause'.", HIGH);
      return;
    }

    OccurredEvent drop = new OccurredEvent(event);
    Log.logInfo("EntityDeath drop occurance created. (" + drop.toString() + ")", HIGHEST);
    parent.sectionManager.performDrop(drop);
  }
예제 #2
0
  public static boolean isSortApplicable(String line, Minecart minecart) {
    if (line.equalsIgnoreCase("All")) {
      return true;
    }
    Entity test = minecart.getPassenger();
    Player player = null;
    if (test instanceof Player) player = (Player) test;

    if ((line.equalsIgnoreCase("Unoccupied") || line.equalsIgnoreCase("Empty"))
        && minecart.getPassenger() == null) {
      return true;
    }

    if (line.equalsIgnoreCase("Storage") && minecart instanceof StorageMinecart) {
      return true;
    } else if (line.equalsIgnoreCase("Powered") && minecart instanceof PoweredMinecart) {
      return true;
    } else if (line.equalsIgnoreCase("Minecart") && minecart instanceof Minecart) {
      return true;
    }

    if ((line.equalsIgnoreCase("Occupied") || line.equalsIgnoreCase("Full"))
        && minecart.getPassenger() != null) {
      return true;
    }

    if (line.equalsIgnoreCase("Animal") && test instanceof Animals) {
      return true;
    }

    if (line.equalsIgnoreCase("Mob") && test instanceof Monster) {
      return true;
    }

    if ((line.equalsIgnoreCase("Player") || line.equalsIgnoreCase("Ply")) && player != null) {
      return true;
    }

    String[] parts = line.split(":");

    if (parts.length >= 2) {
      if (player != null && parts[0].equalsIgnoreCase("Held")) {
        try {
          int item = Integer.parseInt(parts[1]);
          if (player.getItemInHand().getTypeId() == item) {
            return true;
          }
        } catch (NumberFormatException e) {
        }
      } else if (player != null && parts[0].equalsIgnoreCase("Ply")) {
        if (parts[1].equalsIgnoreCase(player.getName())) {
          return true;
        }
      } else if (parts[0].equalsIgnoreCase("Mob")) {
        String testMob = parts[1];
        test.toString().toLowerCase().equalsIgnoreCase(testMob);
      } else if (minecart instanceof StorageMinecart && parts[0].equalsIgnoreCase("Ctns")) {
        StorageMinecart storageCart = (StorageMinecart) minecart;
        Inventory storageInventory = storageCart.getInventory();

        if (parts.length == 3) {
          try {
            int item = Integer.parseInt(parts[1]);
            short durability = Short.parseShort(parts[2]);
            if (storageInventory.contains(new ItemStack(item, 1, durability))) {
              return true;
            }
          } catch (NumberFormatException e) {
          }
        } else {
          try {
            int item = Integer.parseInt(parts[1]);
            if (storageInventory.contains(item)) {
              return true;
            }
          } catch (NumberFormatException e) {
          }
        }
      }
    }

    return false;
  }
예제 #3
0
  // -1, false, false are defaults, attackmob and attack player are only processed when damage = -1.
  public void entityAttack(EntityDamageByEntityEvent ed, double customDamage) {
    double damage = 0;

    event = ed;

    // Reset all globals.
    setGlobalDefaults();

    // Set event damage to 0.
    ed.setDamage(0);

    LivingEntity entity;
    Entity eEntity = ed.getEntity();

    if (eEntity instanceof Arrow) {
      Arrow ca = (Arrow) eEntity;
      entity = ca.getShooter();
    } else if (eEntity instanceof LargeFireball) {
      LargeFireball cf = (LargeFireball) eEntity;
      entity = cf.getShooter();
    } else if (eEntity instanceof ExperienceOrb) {
      return;
    } else if (eEntity instanceof Item) {
      return;
    } else {
      // Set entity equal to the entity that got hit.
      try {
        entity = (LivingEntity) ed.getEntity();
      } catch (ClassCastException e) {
        FC_Rpg.plugin
            .getLogger()
            .info(
                "Failed to cast an entity to living entity, damage cancelled -> "
                    + eEntity.toString()
                    + " <- report to a FC_Rpg developer via a ticket please.");
        return;
      }
    }

    // Prepare the defender and attacker variables.
    prepareDefender(entity);

    // If a damage was passed in, then we don't want to set damage. Else, store new damage
    damage = prepareAttacker(ed);

    // When two players are fighting, then...
    boolean isPvp = false;

    // set whether in pvp or not.
    if (playerAttacker != null && playerDefender != null) isPvp = true;

    if (isPvp == true && cancelRpgDamage == true) {
      MessageLib msgLib = new MessageLib(playerAttacker);
      msgLib.standardMessage("This player can't be attacked currently.");
      return;
    }

    // Check player tiers.
    if (isPvp == true) {
      int attackerTier = getTier(rpgAttacker.playerConfig.getClassLevel());
      int defenderTier = getTier(rpgDefender.playerConfig.getClassLevel());

      if (attackerTier != defenderTier) {
        MessageLib msgLib = new MessageLib(playerAttacker);
        msgLib.infiniteMessage(
            "You can't fight this target because they are in tier ",
            defenderTier + "",
            " and you are in tier ",
            attackerTier + "",
            "!");
        return;
      }
    }

    // If we are cancelling rpg damage, then return.
    if (cancelRpgDamage == true) return;

    if (customDamage > -1) damage = customDamage;

    /**
     * *********************************************************
     *
     * <p>SET THE BASE DAMAGE BASED ON IF A PLAYER, MOB, OR ENVIROMENT CAUSED DAMAGE
     *
     * <p>*********************************************************
     */

    // We do a sword check for atttackers.
    if (rpgAttacker != null) {
      // Check the attackers sword.
      rpgAttacker.swordAttackRequirementCheck();

      // We handle spells on non-fireball player attacks.
      if (damageType != 2) {
        if (rpgAttacker.playerConfig.getAutoCast() == true) rpgAttacker.prepareSpell(false);

        double spellDamage = -1;

        // Attempt to cast a spell.
        if (rpgMobDefender != null)
          spellDamage = rpgAttacker.castSpell(rpgMobDefender.getEntity(), damage, damageType);
        else spellDamage = rpgAttacker.castSpell(rpgDefender.getPlayer(), damage, damageType);

        // If the spell failed to cast, then we want to do spells/enchantment stuff.
        if (spellDamage == -1) {
          // Cast auto spells/enchantment stuff.
          if (rpgMobDefender != null)
            spellDamage = rpgAttacker.autocastOffense(rpgMobDefender.getEntity(), damage);
          else spellDamage = rpgAttacker.autocastOffense(rpgDefender.getPlayer(), damage);
        }

        // If the spell damage isn't -1, then we want to store the spell damage.
        if (spellDamage != -1) damage = spellDamage;
      }
    }

    // Apply randomization to damage.
    damage = getRandomDamageModifier(damage);

    // We do a armor check for defenders.
    if (rpgDefender != null) {
      rpgDefender.fullArmorCheck();

      // Cast armor enchantment stuff.
      rpgDefender.autocastDefense();
    }

    if (rpgMobDefender != null) {
      // Prevent mobs from damaging friendly mobs.
      if (rpgMobAttacker != null) return;

      // If no player attacked, then we want to nuke the mob (enviromental damage).
      if (rpgAttacker == null) {
        edm.nukeMob(rpgMobDefender.getEntity());
        return;
      }

      // Attack the mob defender
      if (edm.attackMobDefender(rpgMobDefender, rpgAttacker, damage, damageType) == false) {
        MessageLib msgLib = new MessageLib(playerAttacker);
        msgLib.standardMessage("Attack Missed.");
      }

      // Make creatures forcibly attack attacker.
      if (playerAttacker != null && mobDefender != null) {
        // Set wolves to angry.
        if (mobDefender instanceof Wolf) ((Wolf) mobDefender).setAngry(true);

        if (mobDefender instanceof Creature) {
          // Change aggro
          ((Creature) mobDefender).setTarget(playerAttacker);
        }
      }
    } else if (rpgDefender != null) {
      // Attack the player Defender.
      if (rpgAttacker != null) {
        if (edm.attackPlayerDefender(
                rpgDefender,
                rpgAttacker,
                null,
                damage,
                damageType,
                rpgAttacker.getPlayer().getName().substring(0, nameTrimEnd))
            == false) {
          MessageLib msgLib = new MessageLib(playerAttacker);
          msgLib.standardMessage("Attack Missed.");
        }
      } else if (rpgMobAttacker != null)
        edm.attackPlayerDefender(
            rpgDefender,
            null,
            rpgMobAttacker,
            damage,
            damageType,
            rpgMobAttacker.getEntity().getType().toString());
    }
  }
예제 #4
0
  public DeathDetail(EntityDeathEvent event) {
    player = (Player) event.getEntity();
    entityDeathEvent = event;
    // Support for setHealth(0) which is used by essentials to do a suicide
    try {
      EntityDamageEvent damageEvent = event.getEntity().getLastDamageCause();
      if (damageEvent instanceof EntityDamageByEntityEvent) {
        Entity damager = ((EntityDamageByEntityEvent) damageEvent).getDamager();
        log.debug("damager", damager.toString());
        if (damager instanceof Player) {
          log.debug("Killed by an other player");
          if (((Player) damager).getItemInHand().getType().equals(Material.AIR)) {
            causeOfDeath = DeathEventType.PVP_FISTS;
          } else {
            causeOfDeath = DeathEventType.PVP;
          }
          murderWeapon = ((Player) damager).getItemInHand().getType().toString();
          killer = (Player) damager;
        } else if (damager instanceof Creature || damager instanceof Slime) {
          log.debug("We have a creature or slime");
          if (damager instanceof Tameable && ((Tameable) damager).isTamed()) {
            causeOfDeath = DeathEventType.PVP_TAMED;
            murderWeapon = damager.getType().toString();
            killer = (Player) ((Tameable) damager).getOwner();
          } else {
            try {
              causeOfDeath = DeathEventType.valueOf(damager.getType().toString());
              if (damager instanceof Skeleton) {
                Skeleton skeleton = (Skeleton) damager;
                causeOfDeath =
                    skeleton.getSkeletonType() == SkeletonType.WITHER
                        ? DeathEventType.WITHER_SKELETON
                        : DeathEventType.SKELETON;
              } else if (damager instanceof Zombie) {
                Zombie zombie = (Zombie) damager;
                causeOfDeath =
                    zombie.isVillager() ? DeathEventType.ZOMBIE_VILLAGER : DeathEventType.ZOMBIE;
              }
            } catch (IllegalArgumentException iae) {
              log.severe("Please notify the developer of the following Error:");
              log.severe(
                  "The following damager is not correctly implemented: "
                      + damager.getType().toString());
              causeOfDeath = DeathEventType.UNKNOWN;
            }
            log.debug("and it is: " + causeOfDeath);
          }
        } else if (damager instanceof Projectile) {
          log.debug("this is a projectile");
          log.debug("shooter", ((Projectile) damager).getShooter());
          if (((Projectile) damager).getShooter() instanceof Player) {
            causeOfDeath = DeathEventType.PVP;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
            killer = (Player) ((Projectile) damager).getShooter();
          }
          if (((Projectile) damager).getShooter() == null) {
            // let's assume that null will only be caused by a dispenser!
            causeOfDeath = DeathEventType.DISPENSER;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
          }
          if (((Projectile) damager).getShooter().toString().equalsIgnoreCase("CraftSkeleton")) {
            causeOfDeath = DeathEventType.SKELETON;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
          }

        } else if (damager instanceof TNTPrimed) {
          causeOfDeath = DeathEventType.BLOCK_EXPLOSION;
        } else {
          log.info("unknown enitity damager" + damager);
        }
      } else if (damageEvent != null) {
        log.debug("DamageEvent is not by Entity");
        try {
          causeOfDeath = DeathEventType.valueOf(damageEvent.getCause().toString());
        } catch (IllegalArgumentException e) {
          causeOfDeath = DeathEventType.UNKNOWN;
        }
      }
    } catch (NullPointerException npe) {
      log.debug("normal detection of damageevent failed", npe);
      log.debug("assuming you did use essentials or similar");
      log.debug("which uses setHealth(0) to kill people");
      log.info("Deathcause is being set to SUICIDE!");
      causeOfDeath = DeathEventType.SUICIDE;
      murderWeapon = "Essentials";
    }

    if (causeOfDeath == null) {
      causeOfDeath = DeathEventType.UNKNOWN;
      murderWeapon = "unknown";
    }
    log.debug("causeOfDeath", causeOfDeath);
    log.debug("murderWeapon", murderWeapon);
    log.debug("killer", killer);
  }