org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason Java Examples
The following examples show how to use
org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.isCancelled() || event.getSpawnReason() == SpawnReason.CUSTOM) { return; } for (String gameName : Main.getGameNames()) { Game game = Main.getGame(gameName); if (game.getStatus() != GameStatus.DISABLED) // prevent creature spawn everytime, not just in game if (/*(game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) &&*/ game.getOriginalOrInheritedPreventSpawningMobs()) { if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) { event.setCancelled(true); return; //} } else /*if (game.getStatus() == GameStatus.WAITING) {*/ if (game.getLobbyWorld() == event.getLocation().getWorld()) { if (event.getLocation().distanceSquared(game.getLobbySpawn()) <= Math .pow(Main.getConfigurator().config.getInt("prevent-lobby-spawn-mobs-in-radius"), 2)) { event.setCancelled(true); return; } } } } }
Example #2
Source File: WorldListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.isCancelled() || event.getSpawnReason() == SpawnReason.CUSTOM) { return; } for (String gameName : Main.getGameNames()) { Game game = Main.getGame(gameName); if (game.getStatus() != GameStatus.DISABLED) // prevent creature spawn everytime, not just in game if (/*(game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) &&*/ game.getOriginalOrInheritedPreventSpawningMobs()) { if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) { event.setCancelled(true); return; //} } else /*if (game.getStatus() == GameStatus.WAITING) {*/ if (game.getLobbyWorld() == event.getLocation().getWorld()) { if (event.getLocation().distanceSquared(game.getLobbySpawn()) <= Math .pow(Main.getConfigurator().config.getInt("prevent-lobby-spawn-mobs-in-radius"), 2)) { event.setCancelled(true); return; } } } } }
Example #3
Source File: CraftWorld.java From Thermos with GNU General Public License v3.0 | 6 votes |
public Entity spawnEntity(Location loc, EntityType entityType) { // Cauldron start - handle custom entity spawns from plugins if (EntityRegistry.entityClassMap.get(entityType.getName()) != null) { net.minecraft.entity.Entity entity = null; entity = getEntity(EntityRegistry.entityClassMap.get(entityType.getName()), world); if (entity != null) { entity.setLocationAndAngles(loc.getX(), loc.getY(), loc.getZ(), 0, 0); world.addEntity(entity, SpawnReason.CUSTOM); return entity.getBukkitEntity(); } } // Cauldron end return spawn(loc, entityType.getEntityClass()); }
Example #4
Source File: MobBaseZombie.java From civcraft with GNU General Public License v2.0 | 6 votes |
public static Entity spawn(Location loc, ICustomMob iCustom, String name) { CraftWorld world = (CraftWorld) loc.getWorld(); World mcWorld = world.getHandle(); MobBaseZombie zombie = new MobBaseZombie(mcWorld, iCustom); if (name != null) { zombie.setCustomName(name); zombie.setCustomNameVisible(true); } iCustom.setEntity(zombie); zombie.setPosition(loc.getX(), loc.getY(), loc.getZ()); mcWorld.addEntity(zombie, SpawnReason.CUSTOM); return zombie; }
Example #5
Source File: MobBaseWitch.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static Entity spawnCustom(Location loc, ICustomMob iCustom) { CraftWorld world = (CraftWorld) loc.getWorld(); World mcWorld = world.getHandle(); MobBaseWitch witch = new MobBaseWitch(mcWorld, iCustom); iCustom.setEntity(witch); witch.setPosition(loc.getX(), loc.getY(), loc.getZ()); mcWorld.addEntity(witch, SpawnReason.CUSTOM); return witch; }
Example #6
Source File: ListenerMobCombat.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
private boolean checkMobSpawnReasonDisabled(LivingEntity enemy) { FileConfiguration config = this.expansion.getConfig("mob-tagger.yml"); List<String> spawnReasonList = config.getStringList("spawn-reason-list"); if(spawnReasonList.contains("*")) return true; SpawnReason spawnReason = getSpawnReason(enemy); String spawnReasonName = spawnReason.name(); return spawnReasonList.contains(spawnReasonName); }
Example #7
Source File: ListenerMobCombat.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
private SpawnReason getSpawnReason(LivingEntity entity) { if(entity == null) return SpawnReason.DEFAULT; if(!entity.hasMetadata("combatlogx_spawn_reason")) return SpawnReason.DEFAULT; List<MetadataValue> spawnReasonValues = entity.getMetadata("combatlogx_spawn_reason"); for(MetadataValue metadataValue : spawnReasonValues) { Object object = metadataValue.value(); if(!(object instanceof SpawnReason)) continue; return (SpawnReason) object; } return SpawnReason.DEFAULT; }
Example #8
Source File: Spigot_v1_15_R2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @Override public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) { checkNotNull(location); checkNotNull(state); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); WorldServer worldServer = craftWorld.getHandle(); Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle()); if (createdEntity != null) { CompoundTag nativeTag = state.getNbtData(); if (nativeTag != null) { NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag); for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.remove(name); } readTagIntoEntity(tag, createdEntity); } createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); worldServer.addEntity(createdEntity, SpawnReason.CUSTOM); return createdEntity.getBukkitEntity(); } else { return null; } }
Example #9
Source File: CraftWorld.java From Thermos with GNU General Public License v3.0 | 5 votes |
public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException { Validate.notNull(location, "Location cannot be null"); Validate.notNull(material, "Material cannot be null"); Validate.isTrue(material.isBlock(), "Material must be a block"); double x = location.getBlockX() + 0.5; double y = location.getBlockY() + 0.5; double z = location.getBlockZ() + 0.5; net.minecraft.entity.item.EntityFallingBlock entity = new net.minecraft.entity.item.EntityFallingBlock(world, x, y, z, net.minecraft.block.Block.getBlockById(material.getId()), data); entity.field_145812_b = 1; // ticksLived world.addEntity(entity, SpawnReason.CUSTOM); return (FallingBlock) entity.getBukkitEntity(); }
Example #10
Source File: CauldronHooks.java From Thermos with GNU General Public License v3.0 | 5 votes |
public static void logEntitySpawn(World world, Entity entity, SpawnReason spawnReason) { if (MinecraftServer.cauldronConfig.entitySpawnLogging.getValue()) { logInfo("Dim: {0} Spawning ({1}): {2}", world.provider.dimensionId, spawnReason, entity); logInfo("Dim: {0} Entities Last Tick: {1}", world.provider.dimensionId, world.entitiesTicked); logInfo("Dim: {0} Tiles Last Tick: {1}", world.provider.dimensionId, world.tilesTicked); //logInfo("Chunk Is Active: {0}", world.inActiveChunk(entity)); logStack(); } }
Example #11
Source File: Spigot_v1_16_R1.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @Override public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) { checkNotNull(location); checkNotNull(state); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); WorldServer worldServer = craftWorld.getHandle(); Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle()); if (createdEntity != null) { CompoundTag nativeTag = state.getNbtData(); if (nativeTag != null) { NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag); for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.remove(name); } readTagIntoEntity(tag, createdEntity); } createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); worldServer.addEntity(createdEntity, SpawnReason.CUSTOM); return createdEntity.getBukkitEntity(); } else { return null; } }
Example #12
Source File: MobBaseWither.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static Entity spawnCustom(Location loc, ICustomMob iCustom) { CraftWorld world = (CraftWorld) loc.getWorld(); World mcWorld = world.getHandle(); MobBaseWither pigzombie = new MobBaseWither(mcWorld, iCustom); iCustom.setEntity(pigzombie); pigzombie.setPosition(loc.getX(), loc.getY(), loc.getZ()); mcWorld.addEntity(pigzombie, SpawnReason.CUSTOM); return pigzombie; }
Example #13
Source File: Spigot_v1_14_R4.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @Override public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) { checkNotNull(location); checkNotNull(state); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); WorldServer worldServer = craftWorld.getHandle(); Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle()); if (createdEntity != null) { CompoundTag nativeTag = state.getNbtData(); if (nativeTag != null) { NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag); for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.remove(name); } readTagIntoEntity(tag, createdEntity); } createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); worldServer.addEntity(createdEntity, SpawnReason.CUSTOM); return createdEntity.getBukkitEntity(); } else { return null; } }
Example #14
Source File: MobBaseIronGolem.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static Entity spawnCustom(Location loc, ICustomMob iCustom) { CraftWorld world = (CraftWorld) loc.getWorld(); World mcWorld = world.getHandle(); MobBaseIronGolem pigzombie = new MobBaseIronGolem(mcWorld, iCustom); iCustom.setEntity(pigzombie); pigzombie.setPosition(loc.getX(), loc.getY(), loc.getZ()); mcWorld.addEntity(pigzombie, SpawnReason.CUSTOM); return pigzombie; }
Example #15
Source File: MobBaseZombie.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static Entity spawnCustom(Location loc, ICustomMob iCustom) { CraftWorld world = (CraftWorld) loc.getWorld(); World mcWorld = world.getHandle(); MobBaseZombie zombie = new MobBaseZombie(mcWorld, iCustom); iCustom.setEntity(zombie); zombie.setPosition(loc.getX(), loc.getY(), loc.getZ()); mcWorld.addEntity(zombie, SpawnReason.CUSTOM); return zombie; }
Example #16
Source File: MobBaseZombieGiant.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static Entity spawnCustom(Location loc, ICustomMob iCustom) { CraftWorld world = (CraftWorld) loc.getWorld(); World mcWorld = world.getHandle(); MobBaseZombieGiant zombie = new MobBaseZombieGiant(mcWorld, iCustom); iCustom.setEntity(zombie); zombie.setPosition(loc.getX(), loc.getY(), loc.getZ()); mcWorld.addEntity(zombie, SpawnReason.CUSTOM); return zombie; }
Example #17
Source File: MobBaseVillager.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static Entity spawn(Location loc, String name) { CraftWorld world = (CraftWorld) loc.getWorld(); World mcWorld = world.getHandle(); MobBaseVillager zombie = new MobBaseVillager(mcWorld); // if (name != null) { // zombie.setCustomName(name); // zombie.setCustomNameVisible(true); // } zombie.setPosition(loc.getX(), loc.getY(), loc.getZ()); mcWorld.addEntity(zombie, SpawnReason.CUSTOM); return zombie; }
Example #18
Source File: MobBasePigZombie.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static Entity spawnCustom(Location loc, ICustomMob iCustom) { CraftWorld world = (CraftWorld) loc.getWorld(); World mcWorld = world.getHandle(); MobBasePigZombie pigzombie = new MobBasePigZombie(mcWorld, iCustom); iCustom.setEntity(pigzombie); pigzombie.setPosition(loc.getX(), loc.getY(), loc.getZ()); mcWorld.addEntity(pigzombie, SpawnReason.CUSTOM); return pigzombie; }
Example #19
Source File: WorldListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBedWarsSpawnIsCancelled(CreatureSpawnEvent event) { if (!event.isCancelled()) { return; } // Fix for uSkyBlock plugin if (event.getSpawnReason() == SpawnReason.CUSTOM && Main.getInstance().isEntityInGame(event.getEntity())) { event.setCancelled(false); } }
Example #20
Source File: Spigot_v1_13_R2_2.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @Override public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) { checkNotNull(location); checkNotNull(state); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); WorldServer worldServer = craftWorld.getHandle(); Entity createdEntity = createEntityFromId(state.getType().getId(), craftWorld.getHandle()); if (createdEntity != null) { CompoundTag nativeTag = state.getNbtData(); if (nativeTag != null) { NBTTagCompound tag = (NBTTagCompound) fromNative(nativeTag); for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.remove(name); } readTagIntoEntity(tag, createdEntity); } createdEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); worldServer.addEntity(createdEntity, SpawnReason.CUSTOM); return createdEntity.getBukkitEntity(); } else { return null; } }
Example #21
Source File: NmsManagerImpl.java From HolographicDisplays with GNU General Public License v3.0 | 5 votes |
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); if (validateEntityMethod == null) { return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); } final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
Example #22
Source File: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 5 votes |
/** * CreatureSpawnEvent */ public static CreatureSpawnEvent callCreatureSpawnEvent(EntityLivingBase entityliving, SpawnReason spawnReason) { LivingEntity entity = (LivingEntity) entityliving.getBukkitEntity(); CraftServer craftServer = (CraftServer) entity.getServer(); CreatureSpawnEvent event = new CreatureSpawnEvent(entity, spawnReason); craftServer.getPluginManager().callEvent(event); return event; }
Example #23
Source File: WorldListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBedWarsSpawnIsCancelled(CreatureSpawnEvent event) { if (!event.isCancelled()) { return; } // Fix for uSkyBlock plugin if (event.getSpawnReason() == SpawnReason.CUSTOM && Main.getInstance().isEntityInGame(event.getEntity())) { event.setCancelled(false); } }
Example #24
Source File: CraftWorld.java From Kettle with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public <T extends Entity> T addEntity(net.minecraft.entity.Entity entity, SpawnReason reason, Consumer<T> function) throws IllegalArgumentException { Preconditions.checkArgument(entity != null, "Cannot spawn null entity"); if (entity instanceof EntityLiving) { ((EntityLiving) entity).onInitialSpawn(getHandle().getDifficultyForLocation(new BlockPos(entity)), null); } if (function != null) { function.accept((T) entity.getBukkitEntity()); } world.spawnEntity(entity, reason); return (T) entity.getBukkitEntity(); }
Example #25
Source File: NetherSpawning.java From askyblock with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onSkeletonSpawn(final CreatureSpawnEvent e) { if (DEBUG) plugin.getLogger().info("DEBUG: " + e.getEventName()); if (!Settings.hackSkeletonSpawners) { return; } if (!hasWitherSkeleton) { // Only if this type of Entity exists return; } // Check for spawn reason if (e.getSpawnReason().equals(SpawnReason.SPAWNER) && e.getEntityType().equals(EntityType.SKELETON)) { if (!Settings.createNether || !Settings.newNether || ASkyBlock.getNetherWorld() == null) { return; } // Check world if (!e.getLocation().getWorld().equals(ASkyBlock.getNetherWorld())) { return; } if (random.nextDouble() < WITHER_SKELETON_SPAWN_CHANCE) { if (DEBUG) plugin.getLogger().info("DEBUG: Wither Skelly spawned"); e.setCancelled(true); e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.WITHER_SKELETON); } else { if (DEBUG) plugin.getLogger().info("DEBUG: Standard Skelly spawned"); } } }
Example #26
Source File: ListenerMobCombat.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onSpawn(CreatureSpawnEvent e) { LivingEntity entity = e.getEntity(); SpawnReason spawnReason = e.getSpawnReason(); FixedMetadataValue fixedValue = new FixedMetadataValue(this.expansion.getPlugin().getPlugin(), spawnReason); entity.setMetadata("combatlogx_spawn_reason", fixedValue); }
Example #27
Source File: CraftWorld.java From Kettle with GNU General Public License v3.0 | 5 votes |
public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException { Validate.notNull(location, "Location cannot be null"); Validate.notNull(material, "Material cannot be null"); Validate.isTrue(material.isBlock(), "Material must be a block"); EntityFallingBlock entity = new EntityFallingBlock(world, location.getX(), location.getY(), location.getZ(), CraftMagicNumbers.getBlock(material).getStateFromMeta(data)); entity.ticksExisted = 1; world.spawnEntity(entity, SpawnReason.CUSTOM); return (FallingBlock) entity.getBukkitEntity(); }
Example #28
Source File: CraftWorld.java From Kettle with GNU General Public License v3.0 | 5 votes |
public Item dropItem(Location loc, ItemStack item) { Validate.notNull(item, "Cannot drop a Null item."); Validate.isTrue(item.getTypeId() != 0, "Cannot drop AIR."); EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item)); entity.pickupDelay = 10; world.spawnEntity(entity, SpawnReason.CUSTOM); // TODO this is inconsistent with how Entity.getBukkitEntity() works. // However, this entity is not at the moment backed by a server entity class so it may be left. return new CraftItem(world.getServer(), entity); }
Example #29
Source File: NmsManagerImpl.java From HolographicDisplays with GNU General Public License v3.0 | 5 votes |
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); if (validateEntityMethod == null) { return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); } final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
Example #30
Source File: CraftWorld.java From Kettle with GNU General Public License v3.0 | 5 votes |
public Entity spawnEntity(Location loc, EntityType entityType) { if (EntityRegistry.entityClassMap.get(entityType.getName()) != null) { net.minecraft.entity.Entity entity = null; entity = getEntity(EntityRegistry.entityClassMap.get(entityType.getName()), world); if (entity != null) { entity.setLocationAndAngles(loc.getX(), loc.getY(), loc.getZ(), 0, 0); world.spawnEntity(entity, SpawnReason.CUSTOM); return entity.getBukkitEntity(); } } return spawn(loc, entityType.getEntityClass()); }