Exemplo n.º 1
0
  /** On creeper death, drop fireworks and heads with a configurable chance. */
  @EventHandler(ignoreCancelled = true)
  public void onCreeperDeath(EntityDeathEvent event) {
    if (!CONFIG.isAffectedWorld(event)) {
      return;
    }

    Entity entity = event.getEntity();
    if (entity.getType() == EntityType.CREEPER && entity.hasMetadata(SPECIAL_KEY)) {
      Creeper creeper = (Creeper) entity;

      // Require recent player damage on the creeper for special drops.
      Long damageTime = getPlayerDamageTime(entity);
      if (damageTime != null) {
        Location loc = creeper.getLocation();
        if (loc.getWorld().getFullTime() - damageTime < PLAYER_DAMAGE_TICKS) {
          if (Math.random() < CONFIG.FIREWORK_DROP_CHANCE) {
            // Replace the default drops.
            event.getDrops().clear();
            final int amount = random(CONFIG.MIN_FIREWORK_DROPS, CONFIG.MAX_FIREWORK_DROPS);
            for (int i = 0; i < amount; ++i) {
              ItemStack firework = new ItemStack(Material.FIREWORK);
              FireworkMeta meta = (FireworkMeta) firework.getItemMeta();
              meta.setPower(random(0, 3));
              meta.addEffect(randomFireworkFffect(false));
              firework.setItemMeta(meta);
              event.getDrops().add(firework);
            }
          }

          // Powered creepers may drop a creeper skull in addition to
          // fireworks.
          if (creeper.isPowered() && Math.random() < CONFIG.CHARGED_CREEPER_SKULL_CHANCE) {
            event.getDrops().add(new ItemStack(Material.SKULL_ITEM, 1, (short) 4));
          }
        }
      }
    }
  } // onCreeperDeath
Exemplo n.º 2
0
  public static String entityName(Entity entity, Player player) {

    if (entity instanceof Bat) {
      return "bat";
    }

    if (entity instanceof Blaze) {
      return "blaze";
    }

    if (entity instanceof Player) {
      return "player";
    }

    if (entity instanceof Chicken) {
      return "chicken";
    }

    if (entity instanceof CaveSpider) {
      return "cavespider";
    }

    if (entity instanceof Cow) {
      if (entity.getType().equals(EntityType.MUSHROOM_COW)) return "mooshroom_cow";
      return "cow";
    }

    if (entity instanceof Creeper) {
      Creeper creeper = (Creeper) entity;
      if (creeper.isPowered()) return "electrifiedcreeper";
      return "creeper";
    }

    if (entity instanceof EnderDragon) {
      return "enderdragon";
    }

    if (entity instanceof Enderman) {
      return "enderman";
    }

    if (entity instanceof Ghast) {
      return "ghast";
    }

    if (entity instanceof Giant) {
      return "giant";
    }

    if (entity instanceof IronGolem) {
      return "irongolem";
    }

    if (entity instanceof MagmaCube) {
      return "magmacube";
    }

    if (entity instanceof Zombie) {
      Zombie zombie = (Zombie) entity;
      if (entity.getType().equals(EntityType.PIG_ZOMBIE)) return "pigzombie";
      if (zombie.isVillager()) return "villagerzombie";
      if (zombie.isBaby()) return "babyzombie";
      return "zombie";
    }

    if (entity instanceof Skeleton) {
      Skeleton skeleton = (Skeleton) entity;
      if ((skeleton.getSkeletonType().equals(Skeleton.SkeletonType.WITHER))
          || (skeleton.getSkeletonType().getId() == 1)) {
        return "witherskeleton";
      }
      return "skeleton";
    }

    if (entity instanceof Silverfish) {
      return "silverfish";
    }

    if (entity instanceof Spider) {
      return "spider";
    }

    if (entity instanceof Witch) {
      return "witch";
    }

    if (entity instanceof Wither) {
      return "wither";
    }

    if (entity instanceof Monster) {
      return "monster";
    }

    if (entity instanceof Ocelot) {
      Ocelot ocelot = (Ocelot) entity;
      if (ocelot.isTamed()) {
        if ((ocelot.getOwner() instanceof Player)
            && ((Player) ocelot.getOwner()).getName().equalsIgnoreCase(player.getName())) {
          return "ocelot_tamed_self";
        } else {
          return "ocelot_tamed";
        }
      }
      return "ocelot_neutral";
    }

    if (entity instanceof Pig) {
      return "pig";
    }

    if (entity instanceof Sheep) {
      return "sheep";
    }

    if (entity instanceof Slime) {
      return "slime";
    }

    if (entity instanceof Snowman) {
      return "snowgolem";
    }

    if (entity instanceof Squid) {
      return "squid";
    }

    if (entity instanceof Villager) {
      return "villager";
    }

    if (entity instanceof Wolf) {
      Wolf wolf = (Wolf) entity;
      if (wolf.isTamed()) {
        if ((wolf.getOwner() instanceof Player)
            && ((Player) wolf.getOwner()).getName().equalsIgnoreCase(player.getName())) {
          return "wolf_self_tamed";
        } else {
          return "wolf_tamed";
        }
      }
      return "wolf_neutral";
    }

    return "";
  }
Exemplo n.º 3
0
  private void kill(LivingEntity monster, MonsterHuntWorld world) {
    EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) monster.getLastDamageCause();
    String name;
    Player player = null;

    String cause = "General";
    if (event.getCause() == DamageCause.PROJECTILE && event.getDamager() instanceof Projectile) {
      if (event.getDamager() instanceof Snowball) cause = "Snowball";
      else cause = "Arrow";
      LivingEntity shooter = ((Projectile) event.getDamager()).getShooter();
      if (shooter instanceof Player) player = (Player) shooter;
    } else if (event.getDamager() instanceof Wolf && ((Wolf) event.getDamager()).isTamed()) {
      cause = "Wolf";
      player = (Player) ((Wolf) event.getDamager()).getOwner();
    }

    if (player == null) {
      if (!(event.getDamager() instanceof Player)) return;
      player = (Player) event.getDamager();

      if (cause.equals("General")) {
        if (player.getItemInHand() == null) cause = String.valueOf(0);
        else cause = String.valueOf(player.getItemInHand().getTypeId());
      }
    }

    int points = 0;
    if (monster instanceof Skeleton) {
      points = world.settings.getMonsterValue("Skeleton", cause);
      name = "Skeleton";
    } else if (monster instanceof Spider) {
      points = world.settings.getMonsterValue("Spider", cause);
      name = "Spider";
    } else if (monster instanceof Creeper) {
      Creeper creeper = (Creeper) monster;
      if (creeper.isPowered()) {
        points = world.settings.getMonsterValue("ElectrifiedCreeper", cause);
        name = "Electrified Creeper";
      } else {
        points = world.settings.getMonsterValue("Creeper", cause);
        name = "Creeper";
      }
    } else if (monster instanceof Ghast) {
      points = world.settings.getMonsterValue("Ghast", cause);
      name = "Ghast";
    } else if (monster instanceof Slime) {
      points = world.settings.getMonsterValue("Slime", cause);
      name = "Slime";
    } else if (monster instanceof PigZombie) {
      points = world.settings.getMonsterValue("ZombiePigman", cause);
      name = "Zombie Pigman";
    } else if (monster instanceof Giant) {
      points = world.settings.getMonsterValue("Giant", cause);
      name = "Giant";
    } else if (monster instanceof Zombie) {
      points = world.settings.getMonsterValue("Zombie", cause);
      name = "Zombie";
    } else if (monster instanceof Wolf) {
      Wolf wolf = (Wolf) monster;
      if (wolf.isTamed()) {
        points = world.settings.getMonsterValue("TamedWolf", cause);
        name = "Tamed Wolf";
      } else {
        points = world.settings.getMonsterValue("WildWolf", cause);
        name = "Wild Wolf";
      }

    } else if (monster instanceof Player) {
      points = world.settings.getMonsterValue("Player", cause);
      name = "Player";
    } else if (monster instanceof Enderman) {
      points = world.settings.getMonsterValue("Enderman", cause);
      name = "Enderman";
    } else if (monster instanceof Silverfish) {
      points = world.settings.getMonsterValue("Silverfish", cause);
      name = "Silverfish";
    } else if (monster instanceof CaveSpider) {
      points = world.settings.getMonsterValue("CaveSpider", cause);
      name = "CaveSpider";
    } else if (monster instanceof EnderDragon) {
      points = world.settings.getMonsterValue("EnderDragon", cause);
      name = "Ender Dragon";
    } else if (monster instanceof MagmaCube) {
      points = world.settings.getMonsterValue("MagmaCube", cause);
      name = "Magma Cube";
    } else if (monster instanceof MushroomCow) {
      points = world.settings.getMonsterValue("Mooshroom", cause);
      name = "Mooshroom";
    } else if (monster instanceof Chicken) {
      points = world.settings.getMonsterValue("Chicken", cause);
      name = "Chicken";
    } else if (monster instanceof Cow) {
      points = world.settings.getMonsterValue("Cow", cause);
      name = "Cow";
    } else if (monster instanceof Blaze) {
      points = world.settings.getMonsterValue("Blaze", cause);
      name = "Blaze";
    } else if (monster instanceof Pig) {
      points = world.settings.getMonsterValue("Pig", cause);
      name = "Pig";
    } else if (monster instanceof Sheep) {
      points = world.settings.getMonsterValue("Sheep", cause);
      name = "Sheep";
    } else if (monster instanceof Snowman) {
      points = world.settings.getMonsterValue("SnowGolem", cause);
      name = "Snow Golem";
    } else if (monster instanceof Squid) {
      points = world.settings.getMonsterValue("Squid", cause);
      name = "Squid";
    } else if (monster instanceof Villager) {
      points = world.settings.getMonsterValue("Villager", cause);
      name = "Villager";
    } else {
      return;
    }
    if (points < 1) return;

    if (!world.Score.containsKey(player.getName())
        && !world.settings.getBoolean(Setting.EnableSignup)) world.Score.put(player.getName(), 0);
    if (world.Score.containsKey(player.getName())) {
      if (!(world.settings.getBoolean(Setting.OnlyCountMobsSpawnedOutsideBlackList)
              ^ world.properlyspawned.contains(monster.getEntityId()))
          && world.settings.getBoolean(Setting.OnlyCountMobsSpawnedOutside)) {
        String message = world.settings.getString(Setting.KillMobSpawnedInsideMessage);
        Util.Message(message, player);
        world.blacklist.add(monster.getEntityId());
        return;
      }
      int newscore = world.Score.get(player.getName()) + points;

      if (world.settings.getBoolean(Setting.AnnounceLead)) {
        Entry<String, Integer> leadpoints = null;
        for (Entry<String, Integer> e : world.Score.entrySet()) {
          if (leadpoints == null
              || e.getValue() > leadpoints.getValue()
              || (e.getValue() == leadpoints.getValue()
                  && leadpoints.getKey().equalsIgnoreCase(player.getName()))) {
            leadpoints = e;
          }
        }
        Util.Debug(leadpoints.toString());
        Util.Debug(String.valueOf(newscore));
        Util.Debug(String.valueOf(!leadpoints.getKey().equals(player.getName())));

        if (leadpoints != null
            && newscore > leadpoints.getValue()
            && !leadpoints.getKey().equals(player.getName())) {
          String message = world.settings.getString(Setting.MessageLead);
          message = message.replace("<Player>", player.getName());
          message = message.replace("<Points>", String.valueOf(newscore));
          message = message.replace("<World>", world.name);
          Util.Broadcast(message);
        }
      }

      world.Score.put(player.getName(), newscore);
      world.blacklist.add(monster.getEntityId());

      world.properlyspawned.remove((Object) monster.getEntityId());

      String message = world.settings.getKillMessage(cause);
      message = message.replace("<MobValue>", String.valueOf(points));
      message = message.replace("<MobName>", name);
      message = message.replace("<Points>", String.valueOf(newscore));
      Util.Message(message, player);
    }
  }