/** * When a creeper explodes, reinforcements are launched from him with random velocities by this * method. * * <p>Reinforcements are always launched at a 45 degree angle, a configurable range from the * exploding creeper. * * @param creeper the exploding creeper. */ protected void launchReinforcements(Entity creeper) { final int numReinforcements = random(CONFIG.MIN_REINFORCEMENTS, CONFIG.MAX_REINFORCEMENTS); for (int i = 0; i < numReinforcements; ++i) { // Compute unit velocity vector components, given 45 degree pitch. double yaw = 2.0 * Math.PI * Math.random(); double y = INV_ROOT_2; double x = INV_ROOT_2 * Math.cos(yaw); double z = INV_ROOT_2 * Math.sin(yaw); // Spawn one reinforcement. Location origin = creeper.getLocation(); World world = origin.getWorld(); Location loc = origin.clone().add(CONFIG.REINFORCEMENT_RANGE * x, 0.5, CONFIG.REINFORCEMENT_RANGE * z); Creeper reinforcement = (Creeper) world.spawnEntity(loc, EntityType.CREEPER); if (reinforcement != null) { reinforcement.setMetadata(SPECIAL_KEY, SPECIAL_META); double speed = random(CONFIG.MIN_REINFORCEMENT_SPEED, CONFIG.MAX_REINFORCEMENT_SPEED); Vector velocity = new Vector(speed * x, speed * y, speed * z); reinforcement.setVelocity(velocity); // Randomly charge a fraction of creepers. if (Math.random() < CONFIG.CHARGED_CHANCE) { reinforcement.setPowered(true); } } } } // launchReinforcements
private void changeMobData(String type, Entity spawned, String data, User user) throws Exception { if ("Slime".equalsIgnoreCase(type)) { try { ((Slime) spawned).setSize(Integer.parseInt(data)); } catch (Exception e) { throw new Exception(Util.i18n("slimeMalformedSize"), e); } } if ("Sheep".equalsIgnoreCase(type)) { try { if (data.equalsIgnoreCase("random")) { Random rand = new Random(); ((Sheep) spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]); } else { ((Sheep) spawned).setColor(DyeColor.valueOf(data.toUpperCase())); } } catch (Exception e) { throw new Exception(Util.i18n("sheepMalformedColor"), e); } } if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("tamed")) { Wolf wolf = ((Wolf) spawned); wolf.setTamed(true); wolf.setOwner(user); wolf.setSitting(true); } if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("angry")) { ((Wolf) spawned).setAngry(true); } if ("Creeper".equalsIgnoreCase(type) && data.equalsIgnoreCase("powered")) { ((Creeper) spawned).setPowered(true); } }
private void forMelee(Creeper creeper) { Location lcreeper = creeper.getLocation(); LivingEntity player = creeper.getTarget(); Location lplayer = player.getLocation(); Vector vcreeper = new Vector(lcreeper.getX(), lcreeper.getY(), lcreeper.getZ()); Vector vplayer = new Vector(lplayer.getX(), lplayer.getY(), lplayer.getZ()); if (vplayer.isInSphere(vcreeper, 3d)) { switch (lplayer.getWorld().getDifficulty()) { case EASY: player.damage(3, creeper); case NORMAL: player.damage(4, creeper); case HARD: player.damage(6, creeper); } } }
@EventHandler public void onInteract(PlayerInteractEvent event) { if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { // (2) final Player player = event.getPlayer(); if (player.getItemInHand().getType() == Material.LEATHER) { Location loc = player.getLocation(); Vector vec = calculateVector(loc); final Creeper creeper = player.getWorld().spawn(loc, Creeper.class); // (3) creeper.setVelocity(vec); creeper.setFireTicks(20); BukkitRunnable runnable = new CowTask(player.getWorld(), creeper); runnable.runTaskTimer(this, 0L, 0L); } } }
/** Checks the creeper is there and spawns in a new one if not. */ private void checkCreepers() { ResultSetTardis rs = new ResultSetTardis(plugin, null, "", true); if (rs.resultSet()) { ArrayList<HashMap<String, String>> data = rs.getData(); for (HashMap<String, String> map : data) { // only if there is a saved creeper location if (!map.get("creeper").isEmpty()) { // only if the TARDIS has been initialised if (map.get("tardis_init").equals("1")) { String[] creeperData = map.get("creeper").split(":"); World w = plugin.getServer().getWorld(creeperData[0]); if (w != null) { float cx = 0, cy = 0, cz = 0; try { cx = plugin.utils.parseFloat(creeperData[1]); cy = plugin.utils.parseFloat(creeperData[2]) + 1; cz = plugin.utils.parseFloat(creeperData[3]); } catch (NumberFormatException nfe) { plugin.debug("Couldn't convert to a float! " + nfe.getMessage()); } Location l = new Location(w, cx, cy, cz); plugin.myspawn = true; Entity e = w.spawnEntity(l, EntityType.CREEPER); // if there is a creeper there already get rid of it! for (Entity k : e.getNearbyEntities(1d, 1d, 1d)) { if (k.getType().equals(EntityType.CREEPER)) { e.remove(); break; } } Creeper c = (Creeper) e; c.setPowered(true); } } } } } }
/** 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
/** Replace naturally spawned monsters in the affected world with creepers. */ @EventHandler(ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { if (!CONFIG.isAffectedWorld(event) || event.getSpawnReason() != SpawnReason.NATURAL || !isEligibleHostileMob(event.getEntityType())) { return; } Entity originalMob = event.getEntity(); Creeper creeper; if (event.getEntityType() == EntityType.CREEPER) { creeper = (Creeper) originalMob; } else { Location loc = originalMob.getLocation(); creeper = (Creeper) loc.getWorld().spawnEntity(loc, EntityType.CREEPER); originalMob.remove(); } creeper.setMetadata(SPECIAL_KEY, SPECIAL_META); if (Math.random() < CONFIG.CHARGED_CHANCE) { creeper.setPowered(true); } } // onCreatureSpawn
public static void setEntityTypeData(final Entity entity, final String data) { if (data == "") return; final String parts[] = data.split(","); if (entity instanceof LivingEntity) { ((LivingEntity) entity).setMaxHealth(Double.parseDouble(parts[1])); ((LivingEntity) entity).setHealth(Double.parseDouble(parts[0])); if (!parts[2].equals("null")) ((LivingEntity) entity).setCustomName(parts[2]); if (entity instanceof Animals) { ((Animals) entity).setAge(Integer.parseInt(parts[3])); if (entity instanceof Sheep) { ((Sheep) entity).setSheared(Boolean.parseBoolean(parts[4])); ((Sheep) entity).setColor(sheepColors.get(parts[5])); } else if (entity instanceof Wolf) { if (Boolean.parseBoolean(parts[4])) { ((Wolf) entity).setAngry(Boolean.parseBoolean(parts[4])); } else if (parts.length > 5) { ((Tameable) entity).setTamed(true); ((Tameable) entity).setOwner(getPlayer(parts[5])); ((Wolf) entity).setCollarColor(DyeColor.valueOf(parts[6])); } } else if (entity instanceof Ocelot) { if (parts.length > 4) { ((Tameable) entity).setTamed(true); ((Tameable) entity).setOwner(getPlayer(parts[4])); ((Ocelot) entity).setCatType(catTypes.get(parts[5])); } } else if (entity instanceof Pig) { ((Pig) entity).setSaddle(Boolean.parseBoolean(parts[4])); } else if (entity instanceof Horse) { ((Horse) entity).setVariant(horseVariants.get(parts[4])); ((Horse) entity).setStyle(horseStyles.get(parts[5])); ((Horse) entity).setColor(horseColors.get(parts[6])); ((Horse) entity).setDomestication(Integer.parseInt(parts[7])); ((Horse) entity).setMaxDomestication(Integer.parseInt(parts[8])); ((Horse) entity).setJumpStrength(Double.parseDouble(parts[9])); if (parts.length > 10) { ((Tameable) entity).setTamed(true); if (!parts[10].equals("null")) ((Tameable) entity).setOwner(getPlayer(parts[10])); ((Horse) entity) .getInventory() .setSaddle(ItemStackUtil.stringToItemStack(parts[11])[0]); ((Horse) entity).getInventory().setArmor(ItemStackUtil.stringToItemStack(parts[12])[0]); if (parts.length > 13) { ((Horse) entity).setCarryingChest(true); ((Horse) entity) .getInventory() .setContents(ItemStackUtil.stringToItemStack(parts[13])); } } } } else if (entity instanceof Villager) { ((Villager) entity).setProfession(villagerProfessions.get(parts[3])); ((Villager) entity).setAge(Integer.parseInt(parts[4])); } else if (entity instanceof Creeper) { ((Creeper) entity).setPowered(Boolean.parseBoolean(parts[3])); } else if (entity instanceof Slime) { ((Slime) entity).setSize(Integer.parseInt(parts[3])); } else if (entity instanceof Skeleton) { ((Skeleton) entity).setSkeletonType(skeletonTypes.get(parts[3])); if (parts[3].equals("0")) { ((Skeleton) entity).getEquipment().setItemInHand(new ItemStack(Material.BOW)); } else { ((Skeleton) entity).getEquipment().setItemInHand(new ItemStack(Material.BOW)); } } else if (entity instanceof PigZombie) { ((LivingEntity) entity).getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD)); } } }
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 ""; }
@SuppressWarnings("deprecation") public void assignMobProps(Entity baseEntity, ISpawnableEntity data) { // This needs to be before everything else! if (data.getRider() != null) { addRider(baseEntity, data.getRider()); } Vector v1 = data.getVelocity(baseEntity); Vector v2 = data.getVelocity2(baseEntity); if (v2.getX() == 0 && v2.getY() == 0 && v2.getZ() == 0) { baseEntity.setVelocity(data.getVelocity(baseEntity).clone()); } else { Vector v3 = randomVector(v1, v2); baseEntity.setVelocity(v3.clone()); } baseEntity.setFireTicks(data.getFireTicks(baseEntity)); if (baseEntity instanceof LivingEntity) { LivingEntity entity = (LivingEntity) baseEntity; setBasicProps(entity, data); if (data.showCustomName()) { setCustomName(entity, data); } if (entity instanceof Ageable) { Ageable a = (Ageable) entity; setAgeProps(a, data); } if (entity instanceof Animals) { Animals animal = (Animals) entity; // Setting animal specific properties if (animal instanceof Pig) { Pig p = (Pig) animal; p.setSaddle(data.isSaddled()); } else if (animal instanceof Sheep) { Sheep s = (Sheep) animal; DyeColor color = DyeColor.valueOf(data.getColor()); s.setColor(color); } else if (animal instanceof Wolf) { Wolf w = (Wolf) animal; w.setAngry(data.isAngry()); w.setTamed(data.isTamed()); if (data.isTamed()) { ArrayList<Player> nearPlayers = getNearbyPlayers(w.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { w.setOwner(nearPlayers.get(index)); } w.setSitting(data.isSitting()); } } else if (animal instanceof Ocelot) { Ocelot o = (Ocelot) animal; o.setTamed(data.isTamed()); if (data.isTamed()) { Ocelot.Type catType = Ocelot.Type.valueOf(data.getCatType()); o.setCatType(catType); ArrayList<Player> nearPlayers = getNearbyPlayers(o.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { o.setOwner(nearPlayers.get(index)); } o.setSitting(data.isSitting()); } } } else if (entity instanceof Villager) { Villager v = (Villager) entity; v.setAge(data.getAge(baseEntity)); v.setProfession(data.getProfession()); } else if (entity instanceof Monster) { Monster monster = (Monster) entity; // Setting monster specific properties. if (monster instanceof Enderman) { Enderman e = (Enderman) monster; e.setCarriedMaterial(data.getEndermanBlock()); } else if (monster instanceof Creeper) { Creeper c = (Creeper) monster; c.setPowered(data.isCharged()); } else if (monster instanceof PigZombie) { PigZombie p = (PigZombie) monster; if (data.isAngry()) { p.setAngry(true); } p.setBaby((data.getAge(baseEntity) < -1) ? true : false); } else if (monster instanceof Spider) { Spider s = (Spider) monster; if (data.isJockey()) { makeJockey(s, data); } } else if (monster instanceof Zombie) { Zombie z = (Zombie) monster; boolean isVillager = false; if (data.hasProp("zombie")) { isVillager = (Boolean) (data.getProp("zombie")); } z.setBaby((data.getAge(baseEntity) < -1) ? true : false); z.setVillager(isVillager); } else if (monster instanceof Skeleton) { Skeleton sk = (Skeleton) monster; SkeletonType skType = SkeletonType.NORMAL; if (data.hasProp("wither")) { skType = ((Boolean) (data.getProp("wither")) == true) ? SkeletonType.WITHER : SkeletonType.NORMAL; } sk.setSkeletonType(skType); } } else if (entity instanceof Golem) { Golem golem = (Golem) entity; if (golem instanceof IronGolem) { IronGolem i = (IronGolem) golem; if (data.isAngry()) { ArrayList<Player> nearPlayers = getNearbyPlayers(i.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { i.setPlayerCreated(false); i.damage(0, nearPlayers.get(index)); i.setTarget(nearPlayers.get(index)); } } } // Some are not classified as animals or monsters } else if (entity instanceof Slime) { Slime s = (Slime) entity; s.setSize(data.getSlimeSize()); } else if (entity instanceof MagmaCube) { MagmaCube m = (MagmaCube) entity; m.setSize(data.getSlimeSize()); } } else if (baseEntity instanceof Projectile) { Projectile pro = (Projectile) baseEntity; // Eventually add explosive arrows and such :D if (pro instanceof Fireball) { Fireball f = (Fireball) pro; setExplosiveProps(f, data); f.setVelocity(new Vector(0, 0, 0)); f.setDirection(data.getVelocity(baseEntity)); } else if (pro instanceof SmallFireball) { SmallFireball f = (SmallFireball) pro; setExplosiveProps(f, data); f.setVelocity(new Vector(0, 0, 0)); f.setDirection(data.getVelocity(baseEntity)); } } else if (baseEntity instanceof Explosive) { Explosive ex = (Explosive) baseEntity; if (ex instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) ex; setExplosiveProps(tnt, data); tnt.setFuseTicks(data.getFuseTicks(baseEntity)); } } else if (baseEntity instanceof Firework) { Firework f = (Firework) baseEntity; ItemMeta meta = data.getItemType().getItemMeta(); if (meta != null) { if (meta instanceof FireworkMeta) { FireworkMeta fMeta = (FireworkMeta) meta; if (fMeta != null) { f.setFireworkMeta(fMeta); } } } } else if (baseEntity instanceof Minecart) { Minecart m = (Minecart) baseEntity; if (data.hasProp("minecartSpeed")) { m.setMaxSpeed((Double) data.getProp("minecartSpeed")); } } else if (baseEntity instanceof ExperienceOrb) { ExperienceOrb o = (ExperienceOrb) baseEntity; o.setExperience(data.getDroppedExp(baseEntity)); } setNBT(baseEntity, data); }
public List<LivingEntity> spawn(Location location, Player player) { List<LivingEntity> entities = new ArrayList<LivingEntity>(this.num); World world = location.getWorld(); for (int num = 0; num < this.num; num++) { if (spread > 0) { int minX = location.getBlockX() - spread / 2; int minY = location.getBlockY() - spread / 2; int minZ = location.getBlockZ() - spread / 2; int maxX = location.getBlockX() + spread / 2; int maxY = location.getBlockY() + spread / 2; int maxZ = location.getBlockZ() + spread / 2; int tries = spread * 10; boolean found = false; while (tries-- > 0) { int x = minX + RecipeManager.random.nextInt(maxX - minX); int z = minZ + RecipeManager.random.nextInt(maxZ - minZ); int y = 0; for (y = maxY; y >= minY; y--) { if (!Material.getMaterial(world.getBlockTypeIdAt(x, y, z)).isSolid()) { found = true; break; } } if (found) { location.setX(x); location.setY(y); location.setZ(z); break; } } if (!found) { Messages.debug( "Couldn't find suitable location after " + (spread * 10) + " tries, using center."); } location.add(0.5, 0, 0.5); } LivingEntity ent = (LivingEntity) world.spawnEntity(location, type); entities.add(ent); if (!noEffect) { world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 20); } if (name != null) { ent.setCustomName(name); ent.setCustomNameVisible(noHideName); } if (onFire > 0.0f) { ent.setFireTicks((int) Math.ceil(onFire * 20.0)); } if (pickup != null) { ent.setCanPickupItems(pickup); } if (pet && ent instanceof Tameable) { Tameable npc = (Tameable) ent; npc.setOwner(player); npc.setTamed(true); } if (ent instanceof Wolf) { Wolf npc = (Wolf) ent; if (pet) { if (noSit) { npc.setSitting(false); } if (color != null) { npc.setCollarColor(color); } } else if (angry) { npc.setAngry(true); } } if (ent instanceof Ocelot) { Ocelot npc = (Ocelot) ent; if (pet && noSit) { npc.setSitting(false); } if (cat != null) { npc.setCatType(cat); } } if (hp > 0) { ent.setHealth(hp); if (maxHp > 0) { ent.setMaxHealth(maxHp); } } if (ent instanceof Ageable) { Ageable npc = (Ageable) ent; if (baby) { npc.setBaby(); } if (ageLock) { npc.setAgeLock(true); } if (noBreed) { npc.setBreed(false); } } if (saddle && ent instanceof Pig) { Pig npc = (Pig) ent; npc.setSaddle(true); if (mount) { npc.setPassenger(player); } } if (ent instanceof Zombie) { Zombie npc = (Zombie) ent; if (baby) { npc.setBaby(true); } if (zombieVillager) { npc.setVillager(true); } } if (villager != null && ent instanceof Villager) { Villager npc = (Villager) ent; npc.setProfession(villager); } if (poweredCreeper && ent instanceof Creeper) { Creeper npc = (Creeper) ent; npc.setPowered(true); } if (playerIronGolem && ent instanceof IronGolem) { IronGolem npc = (IronGolem) ent; npc.setPlayerCreated(true); // TODO what exacly does this do ? } if (shearedSheep && ent instanceof Sheep) { Sheep npc = (Sheep) ent; npc.setSheared(true); } if (color != null && ent instanceof Colorable) { Colorable npc = (Colorable) ent; npc.setColor(color); } if (skeleton != null && ent instanceof Skeleton) { Skeleton npc = (Skeleton) ent; npc.setSkeletonType(skeleton); } if (target && ent instanceof Creature) { Creature npc = (Creature) ent; npc.setTarget(player); } if (pigAnger > 0 && ent instanceof PigZombie) { PigZombie npc = (PigZombie) ent; npc.setAnger(pigAnger); } if (hit) { ent.damage(0, player); ent.setVelocity(new Vector()); } if (!potions.isEmpty()) { for (PotionEffect effect : potions) { ent.addPotionEffect(effect, true); } } ent.setRemoveWhenFarAway(!noRemove); EntityEquipment eq = ent.getEquipment(); for (int i = 0; i < equip.length; i++) { ItemStack item = equip[i]; if (item == null) { continue; } switch (i) { case 0: eq.setHelmet(item); eq.setHelmetDropChance(drop[i]); break; case 1: eq.setChestplate(item); eq.setChestplateDropChance(drop[i]); break; case 2: eq.setLeggings(item); eq.setLeggingsDropChance(drop[i]); break; case 3: eq.setBoots(item); eq.setBootsDropChance(drop[i]); break; case 4: { if (ent instanceof Enderman) { Enderman npc = (Enderman) ent; npc.setCarriedMaterial(item.getData()); } else { eq.setItemInHand(item); eq.setItemInHandDropChance(drop[i]); } break; } } } } return entities; }
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); } }
@Override public LivingEntity modify(LivingEntity e) { Creeper c = (Creeper) e; c.setPowered(false); return e; }