@EventHandler public void onSpawn(CreatureSpawnEvent event) { if (ConfigOptimize.NoCrowdedEntityenable) { Chunk chunk = event.getEntity().getLocation().getChunk(); Entity[] entities = chunk.getEntities(); for (Entity e : entities) { EntityType type = e.getType(); int count = 0; if (ConfigOptimize.NoCrowdedEntityTypeList.contains("*") || ConfigOptimize.NoCrowdedEntityTypeList.contains(type.name())) { count++; if (count > ConfigOptimize.NoCrowdedEntityPerChunkLimit && e.getType() != EntityType.PLAYER) { e.remove(); } } } } }
/** * Track where the mob was created. This will determine its allowable movement zone. * @param e */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void mobSpawn(CreatureSpawnEvent e) { // Only cover withers in the island world if (!Util.inWorld(e.getEntity())) { return; } if (!e.getEntityType().equals(EntityType.WITHER) && !e.getEntityType().equals(EntityType.BLAZE) && !e.getEntityType().equals(EntityType.GHAST)) { return; } if (DEBUG) { plugin.getLogger().info("Flying mobs " + e.getEventName()); } // Store where this mob originated Island island = plugin.getIslands().getIslandAt(e.getLocation()); if (island != null) { if (DEBUG) { plugin.getLogger().info("DEBUG: Mob spawned on known island - id = " + e.getEntity().getUniqueId()); } mobSpawnInfo.put(e.getEntity(),island); } // Else do nothing - maybe an Op spawned it? If so, on their head be it! }
public NametagEntity(final Player player) { super(((CraftWorld)player.getWorld()).getHandle()); final Location location = player.getLocation(); this.setInvisible(true); this.setPosition(location.getX(), location.getY(), location.getZ()); try { final Field invulnerable = Entity.class.getDeclaredField("invulnerable"); invulnerable.setAccessible(true); invulnerable.setBoolean(this, true); } catch (Exception e) { e.printStackTrace(); } this.world.addEntity(this, CreatureSpawnEvent.SpawnReason.CUSTOM); this.persistent = true; this.hideTag(player); }
Graou(Hub hub, Location catLocation, Location door, Location treasureLocations, Location openingLocations) { super(hub); this.holograms = new HashMap<>(); WorldServer world = ((CraftWorld) catLocation.getWorld()).getHandle(); this.graouEntity = new EntityGraou(world); this.graouEntity.setPosition(catLocation.getX(), catLocation.getY(), catLocation.getZ()); world.addEntity(this.graouEntity, CreatureSpawnEvent.SpawnReason.CUSTOM); catLocation.getChunk().load(true); hub.getServer().getScheduler().runTaskLater(hub, () -> this.graouEntity.postInit(catLocation.getYaw(), catLocation.getPitch()), 20L); this.catLocation = catLocation; this.door = door; this.treasureLocations = treasureLocations; this.openingLocations = openingLocations; this.animationTask = null; this.playerUsing = null; }
Meow(Hub hub, Location location) { super(hub); this.holograms = new HashMap<>(); WorldServer world = ((CraftWorld) location.getWorld()).getHandle(); this.meowEntity = new EntityMeow(world); this.meowEntity.setPosition(location.getX(), location.getY(), location.getZ()); world.addEntity(this.meowEntity, CreatureSpawnEvent.SpawnReason.CUSTOM); location.getChunk().load(true); hub.getServer().getScheduler().runTaskLater(hub, () -> this.meowEntity.postInit(location.getYaw(), location.getPitch()), 20L); this.random = new Random(); this.thankYouTask = null; this.lock = false; }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SLIME_SPLIT) { // allow slimes to always split return; } switch (event.getSpawnReason()) { case NATURAL: if (event.getLocation().getChunk().getEntities().length > MAX_NATURAL_CHUNK_ENTITIES) { event.setCancelled(true); } break; case CHUNK_GEN: if (event.getLocation().getChunk().getEntities().length > MAX_CHUNK_GENERATED_ENTITIES) { event.setCancelled(true); } break; default: break; } }
@EventHandler public void onSpawn(@Nonnull CreatureSpawnEvent event) { if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM || event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) { return; } if (!denySpawn) { return; } if (!event.getLocation().getWorld().getName().equals(worldName)) { return; } if (blacklist.length != 0) { if (Arrays.stream(blacklist).anyMatch(m -> m.equals(event.getEntityType()))) { event.setCancelled(true); } } else if (whitelist.length != 0) { if (Arrays.stream(whitelist).noneMatch(m -> m.equals(event.getEntityType()))) { event.setCancelled(true); } } else { event.setCancelled(true); } }
@Override public boolean spawn(EntityType type, Location location) { World nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); RideAbleEntityType rideAbleEntityType = RideAbleEntityType.valueOf(type); if (rideAbleEntityType == null) { return false; } Entity entity; try { entity = (Entity) rideAbleEntityType.getCustomClass().getConstructors()[0].newInstance(nmsWorld); } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { return false; } entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw()); return nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); }
@EventHandler public void onSpawn(CreatureSpawnEvent event) { if (getConfig().getBoolean("Config.Mode.BlockPayEntitiesSpawnedBySpawnerEggs") == true) { if (event.getSpawnReason() == SpawnReason.SPAWNER_EGG) { this.DisabledEntitiesHashMap.put(event.getEntity().getUniqueId(), true); } } if (getConfig().getBoolean("Config.Mode.BlockPayEntitiesSpawnedBySpawners") == true) { if (event.getSpawnReason() == SpawnReason.SPAWNER) { this.DisabledEntitiesHashMap.put(event.getEntity().getUniqueId(), true); } } if (getConfig().getBoolean("Config.Mode.BlockPayEntitiesSpawnedBySummonCommand") == true) { if (event.getSpawnReason() == SpawnReason.DEFAULT) { this.DisabledEntitiesHashMap.put(event.getEntity().getUniqueId(), true); } if (event.getSpawnReason() == SpawnReason.CUSTOM) { this.DisabledEntitiesHashMap.put(event.getEntity().getUniqueId(), true); } } }
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER) { if (DefaultConfig.isAntiFarmingSpawner()) { spawnedEntities.add(event.getEntity().getUniqueId()); return; } } if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) { if (DefaultConfig.isAntiFarmingSpawnerEgg()) { spawnedEntities.add(event.getEntity().getUniqueId()); return; } } }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntitySpawn(CreatureSpawnEvent event) { LivingEntity entity = event.getEntity(); if(!this.isMonster(entity)) return; SpawnReason reason = event.getSpawnReason(); if(reason == SpawnReason.SPAWNER || reason == SpawnReason.SPAWNER_EGG) { entity.setMetadata(this.ALLOW_TARGET_TAG, new FixedMetadataValue(GPFlags.instance, new Boolean(true))); return; } Flag flag = this.GetFlagInstanceAtLocation(event.getLocation(), null); if(flag == null) return; event.setCancelled(true); }
@EventHandler(priority = EventPriority.LOWEST) public void onEntitySpawn(CreatureSpawnEvent event) { if(!(event.getEntity() instanceof LivingEntity)) return; if(event.getLocation() == null) return; EntityType type = event.getEntityType(); if(type == EntityType.PLAYER) return; if(type == EntityType.ARMOR_STAND) return; SpawnReason reason = event.getSpawnReason(); if(reason == SpawnReason.SPAWNER || reason == SpawnReason.SPAWNER_EGG) return; Flag flag = this.GetFlagInstanceAtLocation(event.getLocation(), null); if(flag == null) return; event.setCancelled(true); }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { LivingEntity entity = event.getEntity(); World world = entity.getWorld(); PluginConfig worldConfig = plugin.getConfig(world); if (plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.TARGET_DISTANCE)) { if (worldConfig.getStringList(Config.FEATURE_TARGET_DISTANCE_MOBS).contains(entity.getType().name())) { try { //((CraftLivingEntity)entity).setfol BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); bloodMoonEntity.setFollowRangeMultiplier(worldConfig.getDouble(Config.FEATURE_TARGET_DISTANCE_MULTIPLIER)); } catch (IllegalArgumentException e) { // This means the entity is not supported *shrug* } } } }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { LivingEntity entity = event.getEntity(); World world = entity.getWorld(); PluginConfig worldConfig = plugin.getConfig(world); if (plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.MOVEMENT_SPEED)) { if (worldConfig.getStringList(Config.FEATURE_MOVEMENT_SPEED_MOBS).contains(entity.getType().name())) { try { BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); //EntityInsentient sam = (EntityInsentient)((CraftLivingEntity) entity).getHandle(); //System.err.println(bloodMoonEntity.toString() + "le mob"); double multiplier = worldConfig.getDouble((this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_MOVEMENT_SPEED_FAST_CHANCE)) ? Config.FEATURE_MOVEMENT_SPEED_FAST_MULTIPLIER : Config.FEATURE_MOVEMENT_SPEED_MULTIPLIER); bloodMoonEntity.setSpeedMultiplier(multiplier); } catch (IllegalArgumentException e) { // This means the entity is not supported *shrug* } } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.getSpawnReason() != SpawnReason.NATURAL) { //TODO: Should check for Custom instead of checking against natural? return; } EntityType type = event.getEntityType(); World world = event.getLocation().getWorld(); PluginConfig worldConfig = plugin.getConfig(world); if (plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.MORE_SPAWNING) && worldConfig.getStringList(Config.FEATURE_MORE_SPAWNING_MOBS).contains(type.getName().toUpperCase())) { for (int i = 0; i < Math.max(worldConfig.getInt(Config.FEATURE_MORE_SPAWNING_MULTIPLIER), 1); ++i) { for (BloodMoonEntityType bloodMoonEntity : BloodMoonEntityType.values()) { if (type == bloodMoonEntity.getEntityType()) { bloodMoonEntity.spawnEntity(event.getLocation().add((random.nextDouble() * 3) - 1.5, (random.nextDouble() * 3) - 1.5, (random.nextDouble() * 3) - 1.5)); return; } } } } }
@Override public GroupDataEntity prepare(DifficultyDamageScaler difficultydamagescaler, GroupDataEntity groupdataentity) { GroupDataEntity object = super.prepare(difficultydamagescaler, groupdataentity); if(this.world.random.nextInt(100) == 0) { CustomSkeleton i = new CustomSkeleton(this.world); i.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F); i.prepare(difficultydamagescaler, (GroupDataEntity)null); this.world.addEntity(i, CreatureSpawnEvent.SpawnReason.JOCKEY); i.mount(this); } // snip the reset of the method to avoid it running twice, this method is just here to make sure there is a chance // for skeleton jockeys to appear return object; }
@EventHandler public void on(ProjectileLaunchEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof Egg)) return; Egg egg = (Egg) entity; // skip our own eggs if (((CraftEgg) entity).getHandle() instanceof CustomChickenEgg) return; // cancel the launch event.setCancelled(true); EntityEgg original = ((CraftEgg) egg).getHandle(); // create our own egg from the original and spawn that CustomChickenEgg newEgg = new CustomChickenEgg(original.getWorld(), original.getShooter()); original.getWorld().addEntity(newEgg, CreatureSpawnEvent.SpawnReason.EGG); }
@Override protected void a(MovingObjectPosition movingobjectposition) { if(movingobjectposition.entity != null) { // added this.getThrower() instanceof CustomChicken ? 1.0F : 0.0F] // causes non-chicken thrown eggs to do no damage movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.getShooter()), this.getShooter() instanceof CustomChicken ? 1.0F : 0.0F); } // 1/32 chance to spawn if (this.random.nextInt(32) == 0) { CustomChicken chicken = new CustomChicken(this.getWorld()); chicken.setAge(-24000); chicken.setLocation(this.locX, this.locY, this.locZ, this.yaw, 0.0F); this.world.addEntity(chicken, CreatureSpawnEvent.SpawnReason.EGG); } // standard egg particles for(int i = 0; i < 8; ++i) { this.world.addParticle(EnumParticle.ITEM_CRACK, this.locX, this.locY, this.locZ, ((double)this.random.nextFloat() - 0.5D) * 0.08D, ((double)this.random.nextFloat() - 0.5D) * 0.08D, ((double)this.random.nextFloat() - 0.5D) * 0.08D, new int[]{Item.getId(Items.EGG)}); } // RIP this.die(); }
private boolean c() { Vec3D vec3d = this.a(new BlockPosition(this.g, this.h, this.i)); if(vec3d == null) { return false; } else { EntityZombie entityzombie; try { entityzombie = new CustomZombie(this.a); entityzombie.prepare(this.a.E(new BlockPosition(entityzombie)), (GroupDataEntity)null); entityzombie.setVillager(false); } catch (Exception var4) { var4.printStackTrace(); return false; } entityzombie.setPositionRotation(vec3d.a, vec3d.b, vec3d.c, this.a.random.nextFloat() * 360.0F, 0.0F); this.a.addEntity(entityzombie, CreatureSpawnEvent.SpawnReason.VILLAGE_INVASION); BlockPosition blockposition = this.f.a(); entityzombie.a(blockposition, this.f.b()); return true; } }
public void a(EntityLiving entityliving) { super.a(entityliving); if((this.world.getDifficulty() == EnumDifficulty.NORMAL || this.world.getDifficulty() == EnumDifficulty.HARD) && entityliving instanceof EntityVillager) { if(this.world.getDifficulty() != EnumDifficulty.HARD && this.random.nextBoolean()) { return; } EntityZombie entityzombie = new CustomZombie(this.world); entityzombie.m(entityliving); this.world.kill(entityliving); entityzombie.prepare(this.world.E(new BlockPosition(entityzombie)), (GroupDataEntity) null); entityzombie.setVillager(true); if(entityliving.isBaby()) { entityzombie.setBaby(true); } this.world.addEntity(entityzombie, CreatureSpawnEvent.SpawnReason.INFECTION); this.world.a((EntityHuman)null, 1016, new BlockPosition((int)this.locX, (int)this.locY, (int)this.locZ), 0); } }
@EventHandler public void on(CreatureSpawnEvent event) { if (!entityChecker.isEntityOfClassExact(event.getEntity(), toCheck)) return; if (skips.contains(event.getSpawnReason())) return; Location loc = event.getEntity().getLocation(); plugin.getLogger().severe( String.format("Invalid spawn occured for entity type %s at x:%f y:%f z:%f, automatically cancelling...", toCheck.getName(), loc.getX(), loc.getY(), loc.getZ() ) ); event.setCancelled(true); }
@EventHandler(priority = EventPriority.LOWEST) public void onEntitySpawn(CreatureSpawnEvent event) { //these rules apply only to creative worlds if(!GriefPrevention.instance.creativeRulesApply(event.getLocation())) return; //chicken eggs and breeding could potentially make a mess in the wilderness, once griefers get involved SpawnReason reason = event.getSpawnReason(); if(reason != SpawnReason.SPAWNER_EGG && reason != SpawnReason.BUILD_IRONGOLEM && reason != SpawnReason.BUILD_SNOWMAN) { event.setCancelled(true); return; } //otherwise, just apply the limit on total entities per claim (and no spawning in the wilderness!) Claim claim = this.dataStore.getClaimAt(event.getLocation(), false, null); if(claim == null || claim.allowMoreEntities() != null) { event.setCancelled(true); return; } }
public void a(EntityLiving entityliving) { super.a(entityliving); if ((this.world.difficulty == EnumDifficulty.NORMAL || this.world.difficulty == EnumDifficulty.HARD) && entityliving instanceof EntityVillager) { if (this.world.difficulty != EnumDifficulty.HARD && this.random.nextBoolean()) { return; } EntityZombie entityzombie = new EntityZombie(this.world); entityzombie.k(entityliving); this.world.kill(entityliving); entityzombie.prepare((GroupDataEntity) null); entityzombie.setVillager(true); if (entityliving.isBaby()) { entityzombie.setBaby(true); } this.world.addEntity(entityzombie, CreatureSpawnEvent.SpawnReason.INFECTION); // CraftBukkit - add SpawnReason this.world.a((EntityHuman) null, 1016, (int) this.locX, (int) this.locY, (int) this.locZ, 0); } }
@EventHandler(priority=EventPriority.LOWEST) public void onEntitySpawn(CreatureSpawnEvent event) { LivingEntity entity = event.getEntity(); Chunk chunk = entity.getLocation().getChunk(); if (chunk == lastChunk) { event.getEntity().remove(); event.setCancelled(true); return; } if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { return; } Entity[] entities = chunk.getEntities(); if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { event.getEntity().remove(); event.setCancelled(true); lastChunk = chunk; } else { lastChunk = null; } }
@EventHandler public void onSpawn(CreatureSpawnEvent event) { LivingEntity e = event.getEntity(); WorldSettings set = plugin.getWorlds().get(event.getEntity().getWorld().getName()); if (set == null) { return; } if (!set.getEntities().contains(e.getType())) { return; } if (!set.shouldExist(e)) { event.setCancelled(true); } else if (rand.nextDouble() > set.getRatio(e.getType())) { event.setCancelled(true); } else { AttributeInstance maxHealth = e.getAttribute(Attribute.GENERIC_MAX_HEALTH); maxHealth.setBaseValue(maxHealth.getBaseValue() * set.getHealth(e.getType())); e.setHealth(e.getMaxHealth()); } }
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { if (event == null || event.isCancelled() || event.getLocation() == null || !plugin.isSkyWorld(event.getLocation().getWorld())) { return; // Bail out, we don't care } if (!event.isCancelled() && ADMIN_INITIATED.contains(event.getSpawnReason())) { return; // Allow it, the above method would have blocked it if it should be blocked. } checkLimits(event, event.getEntity().getType(), event.getLocation()); if (!event.isCancelled() && event.getEntity() instanceof Squid) { Location loc = event.getLocation(); int z = loc.getBlockZ(); int x = loc.getBlockX(); if (loc.getWorld().getBiome(x, z) == Biome.DEEP_OCEAN && LocationUtil.findRoofBlock(loc).getType() == Material.PRISMARINE) { loc.getWorld().spawnEntity(loc, EntityType.GUARDIAN); event.setCancelled(true); } } if (!event.isCancelled() && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BUILD_WITHER && event.getEntity() instanceof Wither) { IslandInfo islandInfo = plugin.getIslandInfo(event.getLocation()); if (islandInfo != null && islandInfo.getLeader() != null) { event.getEntity().setCustomName(I18nUtil.tr("{0}''s Wither", islandInfo.getLeader())); event.getEntity().setMetadata("fromIsland", new FixedMetadataValue(plugin, islandInfo.getName())); } } }
/** * Track where the mob was created. This will determine its allowable movement zone. * @param e */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void mobSpawn(CreatureSpawnEvent e) { // Only cover withers in the island world if (!IslandGuard.inWorld(e.getEntity())) { return; } if (!e.getEntityType().equals(EntityType.WITHER) && !e.getEntityType().equals(EntityType.BLAZE) && !e.getEntityType().equals(EntityType.GHAST)) { return; } if (DEBUG) { plugin.getLogger().info("Flying mobs " + e.getEventName()); } // Store where this mob originated Island island = plugin.getGrid().getIslandAt(e.getLocation()); if (island != null) { if (DEBUG) { plugin.getLogger().info("DEBUG: Mob spawned on known island - id = " + e.getEntity().getUniqueId()); } mobSpawnInfo.put(e.getEntity(),island); } // Else do nothing - maybe an Op spawned it? If so, on their head be it! }