org.bukkit.event.entity.CreatureSpawnEvent Java Examples

The following examples show how to use org.bukkit.event.entity.CreatureSpawnEvent. 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: SpawnUtil.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EntityPet spawn(IPet pet, Player owner) {
    Location l = owner.getLocation();
    PetPreSpawnEvent spawnEvent = new PetPreSpawnEvent(pet, l);
    EchoPet.getPlugin().getServer().getPluginManager().callEvent(spawnEvent);
    if (spawnEvent.isCancelled()) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Pet spawn was cancelled externally.");
        EchoPet.getManager().removePet(pet, true);
        return null;
    }
    l = spawnEvent.getSpawnLocation();
    World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
    EntityPet entityPet = (EntityPet) pet.getPetType().getNewEntityPetInstance(mcWorld, pet);

    entityPet.setLocation(new Location(mcWorld.getWorld(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()));
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    if (!mcWorld.addEntity(entityPet, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Failed to spawn pet entity.");
        EchoPet.getManager().removePet(pet, true);
    } else {
        Particle.MAGIC_RUNES.builder().at(l).show();
    }
    return entityPet;
}
 
Example #2
Source File: EntitySpawnHandler.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public <T extends ControllableEntityHandle<? extends LivingEntity>> T createHandle(ControllableEntity entity, Location location) {
    SafeConstructor<ControllableEntityHandle> entityConstructor = new Reflection().reflect(entity.getEntityType().getHandleClass()).getSafeConstructor(World.class, entity.getEntityType().getControllableInterface());

    EntityRegistrationEntry oldEntry = GameRegistry.get(IEntityRegistry.class).getDefaultEntryFor(entity.getEntityType());
    GameRegistry.get(IEntityRegistry.class).register(new EntityRegistrationEntry(
            entity.getEntityType().getName(),
            entity.getEntityType().getId(),
            entity.getEntityType().getHandleClass()
    ));

    WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
    T handle = (T) entityConstructor.getAccessor().invoke(worldServer, entity);

    handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    worldServer.addEntity((net.minecraft.server.v1_7_R1.Entity) handle, CreatureSpawnEvent.SpawnReason.CUSTOM);

    GameRegistry.get(IEntityRegistry.class).register(oldEntry);

    Material beneath = location.getBlock().getRelative(BlockFace.DOWN).getType();
    if (beneath.isBlock()) { // What lies beneath
        ((Entity) handle).onGround = true;
    }

    return handle;
}
 
Example #3
Source File: SpawnEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent e){
    LivingEntity entity = e.getEntity();

    // IEntityTools before running task
    if(!(entity instanceof Mob)){
        return;
    }
    if(sm.getLogic().doSpawnChecks(entity, e.getSpawnReason().toString())){
        return;
    }
    if(sm.getLogic().makeWaiting(entity, e.getSpawnReason())){
        return;
    }
    // BukkitRunnable to delay this, so the needed metadata can be set before attempting to merge.
    new SpawnTask(sm, entity).runTask(sm);
}
 
Example #4
Source File: StackLogic.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean makeWaiting(Entity entity, CreatureSpawnEvent.SpawnReason reason){
    if(!sm.getCustomConfig().getBoolean("wait-to-stack.enabled")){
        return false;
    }
    if(!sm.getCustomConfig().getStringList("wait-to-stack.entity-types")
            .contains(entity.getType().toString())){
        return false;
    }
    if(!sm.getCustomConfig().getStringList("wait-to-stack.spawn-reasons")
            .contains(reason.toString())){
        return false;
    }
    int waitingTime = sm.getCustomConfig().getInt("wait-to-stack.wait-time");
    StackTools.addWaiting(entity, waitingTime);
    return true;
}
 
Example #5
Source File: SpawnUtil.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EntityPet spawn(IPet pet, Player owner) {
    Location l = owner.getLocation();
    PetPreSpawnEvent spawnEvent = new PetPreSpawnEvent(pet, l);
    EchoPet.getPlugin().getServer().getPluginManager().callEvent(spawnEvent);
    if (spawnEvent.isCancelled()) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Pet spawn was cancelled externally.");
        EchoPet.getManager().removePet(pet, true);
        return null;
    }
    l = spawnEvent.getSpawnLocation();
    World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
    EntityPet entityPet = (EntityPet) pet.getPetType().getNewEntityPetInstance(mcWorld, pet);

    entityPet.setLocation(new Location(mcWorld.getWorld(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()));
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    if (!mcWorld.addEntity(entityPet, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Failed to spawn pet entity.");
        EchoPet.getManager().removePet(pet, true);
    } else {
        Particle.MAGIC_RUNES.builder().at(l).show();
    }
    return entityPet;
}
 
Example #6
Source File: SpawnUtil.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EntityPet spawn(IPet pet, Player owner) {
    Location l = owner.getLocation();
    PetPreSpawnEvent spawnEvent = new PetPreSpawnEvent(pet, l);
    EchoPet.getPlugin().getServer().getPluginManager().callEvent(spawnEvent);
    if (spawnEvent.isCancelled()) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Pet spawn was cancelled externally.");
        EchoPet.getManager().removePet(pet, true);
        return null;
    }
    l = spawnEvent.getSpawnLocation();
    World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
    EntityPet entityPet = (EntityPet) pet.getPetType().getNewEntityPetInstance(mcWorld, pet);

    entityPet.setLocation(new Location(mcWorld.getWorld(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()));
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    if (!mcWorld.addEntity(entityPet, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Failed to spawn pet entity.");
        EchoPet.getManager().removePet(pet, true);
    } else {
        Particle.MAGIC_RUNES.builder().at(l).show();
    }
    return entityPet;
}
 
Example #7
Source File: FlyingMobEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Track where the mob was created. This will determine its allowable movement zone.
 * @param e - event
 */
@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!
}
 
Example #8
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #9
Source File: SpawnUtil.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EntityPet spawn(IPet pet, Player owner) {
    Location l = owner.getLocation();
    PetPreSpawnEvent spawnEvent = new PetPreSpawnEvent(pet, l);
    EchoPet.getPlugin().getServer().getPluginManager().callEvent(spawnEvent);
    if (spawnEvent.isCancelled()) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Pet spawn was cancelled externally.");
        EchoPet.getManager().removePet(pet, true);
        return null;
    }
    l = spawnEvent.getSpawnLocation();
    World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
    EntityPet entityPet = (EntityPet) pet.getPetType().getNewEntityPetInstance(mcWorld, pet);

    entityPet.setLocation(new Location(mcWorld.getWorld(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()));
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    if (!mcWorld.addEntity(entityPet, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Failed to spawn pet entity.");
        EchoPet.getManager().removePet(pet, true);
    } else {
        Particle.MAGIC_RUNES.builder().at(l).show();
    }
    return entityPet;
}
 
Example #10
Source File: SpawnUtil.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EntityPet spawn(IPet pet, Player owner) {
    Location l = owner.getLocation();
    PetPreSpawnEvent spawnEvent = new PetPreSpawnEvent(pet, l);
    EchoPet.getPlugin().getServer().getPluginManager().callEvent(spawnEvent);
    if (spawnEvent.isCancelled()) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Pet spawn was cancelled externally.");
        EchoPet.getManager().removePet(pet, true);
        return null;
    }
    l = spawnEvent.getSpawnLocation();
    World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
    EntityPet entityPet = (EntityPet) pet.getPetType().getNewEntityPetInstance(mcWorld, pet);

    entityPet.setLocation(new Location(mcWorld.getWorld(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()));
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    if (!mcWorld.addEntity(entityPet, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Failed to spawn pet entity.");
        EchoPet.getManager().removePet(pet, true);
    } else {
        Particle.MAGIC_RUNES.builder().at(l).show();
    }
    return entityPet;
}
 
Example #11
Source File: SpawnUtil.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EntityPet spawn(IPet pet, Player owner) {
    Location l = owner.getLocation();
    PetPreSpawnEvent spawnEvent = new PetPreSpawnEvent(pet, l);
    EchoPet.getPlugin().getServer().getPluginManager().callEvent(spawnEvent);
    if (spawnEvent.isCancelled()) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Pet spawn was cancelled externally.");
        EchoPet.getManager().removePet(pet, true);
        return null;
    }
    l = spawnEvent.getSpawnLocation();
    World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
    EntityPet entityPet = (EntityPet) pet.getPetType().getNewEntityPetInstance(mcWorld, pet);

    entityPet.setLocation(new Location(mcWorld.getWorld(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()));
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    if (!mcWorld.addEntity(entityPet, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
        owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Failed to spawn pet entity.");
        EchoPet.getManager().removePet(pet, true);
    } else {
        Particle.MAGIC_RUNES.builder().at(l).show();
    }
    return entityPet;
}
 
Example #12
Source File: EntitySpawnHandler.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public <T extends ControllableEntityHandle<? extends LivingEntity>> T createEntityHandle(ControllableEntity entity, Location location) {
    SafeConstructor<ControllableEntityHandle> entityConstructor = getConstructorFor(entity.getEntityType());

    EntityRegistrationEntry oldEntry = GameRegistry.get(IEntityRegistry.class).getDefaultEntryFor(entity.getEntityType());
    GameRegistry.get(IEntityRegistry.class).register(new EntityRegistrationEntry(
            entity.getEntityType().getName(),
            entity.getEntityType().getId(),
            entity.getEntityType().getHandleClass()
    ));

    WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
    T handle = (T) entityConstructor.getAccessor().invoke(worldServer, entity);

    handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    worldServer.addEntity((net.minecraft.server.v1_8_R1.Entity) handle, CreatureSpawnEvent.SpawnReason.CUSTOM);

    GameRegistry.get(IEntityRegistry.class).register(oldEntry);

    Material beneath = location.getBlock().getRelative(BlockFace.DOWN).getType();
    if (beneath.isBlock()) { // What lies beneath
        ((Entity) handle).onGround = true;
    }

    return handle;
}
 
Example #13
Source File: EntityListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntitySpawn(CreatureSpawnEvent ese) {
  if (BedwarsRel.getInstance().getGameManager() == null) {
    return;
  }

  if (ese.getLocation() == null) {
    return;
  }

  if (ese.getLocation().getWorld() == null) {
    return;
  }

  Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(ese.getLocation());
  if (game == null) {
    return;
  }

  if (game.getState() == GameState.STOPPED) {
    return;
  }

  if (ese.getEntityType().equals(EntityType.CREEPER)
      || ese.getEntityType().equals(EntityType.CAVE_SPIDER)
      || ese.getEntityType().equals(EntityType.SPIDER)
      || ese.getEntityType().equals(EntityType.ZOMBIE)
      || ese.getEntityType().equals(EntityType.SKELETON)
      || ese.getEntityType().equals(EntityType.SILVERFISH)) {
    ese.setCancelled(true);
  }
}
 
Example #14
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 5 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_13_R2.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example #15
Source File: NMSImpl.java    From TabooLib with MIT License 5 votes vote down vote up
@Override
public <T extends Entity> T spawn(Location location, Class<T> entity, Consumer<T> e) {
    if (Version.isAfter(Version.v1_12)) {
        return location.getWorld().spawn(location, entity, e::accept);
    } else {
        Object createEntity = ((CraftWorld) location.getWorld()).createEntity(location, entity);
        try {
            e.accept((T) ((net.minecraft.server.v1_13_R2.Entity) createEntity).getBukkitEntity());
        } catch (Throwable t) {
            t.printStackTrace();
        }
        return ((CraftWorld) location.getWorld()).addEntity((net.minecraft.server.v1_13_R2.Entity) createEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
    }
}
 
Example #16
Source File: NetherSpawning.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@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 #17
Source File: SpawnFilter.java    From CardinalPGM with MIT License 5 votes vote down vote up
@Override
public FilterState evaluate(final Object... objects) {
    for (Object object : objects) {
        if (object instanceof CreatureSpawnEvent) {
            if (((CreatureSpawnEvent) object).getSpawnReason().equals(reason))
                return ALLOW;
            else
                return DENY;
        }
    }
    return (getParent() == null ? ABSTAIN : getParent().evaluate(objects));
}
 
Example #18
Source File: SpawnEventsTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onPhantomSpawn_overworldNotAllowed() {
    when(worldManager.isSkyWorld(any(World.class))).thenReturn(true);

    CreatureSpawnEvent event = new CreatureSpawnEvent(getFakePhantom(),
            CreatureSpawnEvent.SpawnReason.NATURAL);
    spawnEvents.setPhantomsInOverworld(false);
    spawnEvents.onPhantomSpawn(event);

    assertTrue(event.isCancelled());
}
 
Example #19
Source File: EntityTracker.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void registerNaturalEntity(CreatureSpawnEvent event) {
    if (event.isCancelled()) return;
    if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) ||
            event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM) &&
                    !ConfigValues.defaultConfig.getBoolean(DefaultConfig.STRICT_SPAWNING_RULES))
        registerNaturalEntity(event.getEntity());
}
 
Example #20
Source File: FaweAdapter_1_10.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(state);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    WorldServer worldServer = craftWorld.getHandle();

    net.minecraft.server.v1_10_R1.Entity createdEntity = createEntityFromId(state.getTypeId(), 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, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    }
    return null;
}
 
Example #21
Source File: SpawnEventsTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onPhantomSpawn_notInNetherWorld() {
    when(worldManager.isSkyNether(any(World.class))).thenReturn(false);

    CreatureSpawnEvent event = new CreatureSpawnEvent(getFakePhantom(),
            CreatureSpawnEvent.SpawnReason.NATURAL);
    spawnEvents.setPhantomsInNether(false);
    spawnEvents.onPhantomSpawn(event);

    assertFalse(event.isCancelled());
}
 
Example #22
Source File: NMSImpl.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean spawnEntity(NMSInsentientEntity wrapper, Location l) {
    EntityLiving entity = ((NMSEntityInsentientImpl) wrapper).getHandle();
    entity.spawnIn(((CraftWorld) l.getWorld()).getHandle());
    entity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    return entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example #23
Source File: NMSImpl.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean spawnEntity(NMSInsentientEntity wrapper, Location l) {
    EntityLiving entity = ((NMSEntityInsentientImpl) wrapper).getHandle();
    entity.spawnIn(((CraftWorld) l.getWorld()).getHandle());
    ((LivingEntity) entity.getBukkitEntity()).setCollidable(false);
    entity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    return entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example #24
Source File: NMSImpl.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean spawnEntity(NMSInsentientEntity wrapper, Location l) {
    EntityLiving entity = ((NMSEntityInsentientImpl) wrapper).getHandle();
    entity.spawnIn(((CraftWorld) l.getWorld()).getHandle());
    ((LivingEntity) entity.getBukkitEntity()).setCollidable(false);
    entity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    return entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example #25
Source File: CreatureForceSpawnListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
void onCreatureSpawn(CreatureSpawnEvent event) {
	if (nextSpawnLocation == null) return;
	if (event.getEntityType() == nextEntityType && event.getLocation().equals(nextSpawnLocation)) {
		event.setCancelled(false);
	} else {
		// this shouldn't normally be reached..
		Log.debug("Shopkeeper entity-spawning seems to be out of sync: spawn-force was activated for an entity of type "
				+ nextEntityType.name() + " at location " + nextSpawnLocation.toString() + ", but a (different) entity of type "
				+ event.getEntityType().name() + " was spawned at location " + event.getLocation().toString() + ".");
	}
	nextSpawnLocation = null;
	nextEntityType = null;
}
 
Example #26
Source File: EventListener.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onCreatureSpawn(CreatureSpawnEvent event) {
	final LivingEntity livingEntity = event.getEntity();
	final int entityId = livingEntity.getEntityId();
	EntityIdList.addEntity(livingEntity);
	Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
		
		public void run() {
			if(livingEntity == null || !livingEntity.isValid()) {
				EntityIdList.removeEntity(entityId);
			}
		}
		
	}, 40L);
}
 
Example #27
Source File: NMSImpl.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean spawnEntity(NMSInsentientEntity wrapper, Location l) {
    EntityLiving entity = ((NMSEntityInsentientImpl) wrapper).getHandle();
    entity.spawnIn(((CraftWorld) l.getWorld()).getHandle());
    ((LivingEntity) entity.getBukkitEntity()).setCollidable(false);
    entity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
    if (!l.getChunk().isLoaded()) {
        l.getChunk().load();
    }
    return entity.world.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example #28
Source File: TrashMobEntity.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
public TrashMobEntity(EntityType entityType, Location location, String name) {

        super(entityType, location, 1, name, CreatureSpawnEvent.SpawnReason.CUSTOM);
        super.setHasCustomHealth(true);
        super.getLivingEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(1);
        super.getLivingEntity().setHealth(1);
        super.setHasSpecialLoot(false);

    }
 
Example #29
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Comes AFTER the SpawnEvents{@link #onCreatureSpawn(CreatureSpawnEvent)} - so cancelled will have effect
 * @param e
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent e) {
    if (!spawnEnabled || e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL) {
        return;
    }
    if (!plugin.getWorldManager().isSkyNether(e.getLocation().getWorld())) {
        return;
    }
    if (e.getLocation().getBlockY() > plugin.getWorldManager().getNetherWorld().getMaxHeight()) {
        // Block spawning above nether...
        e.setCancelled(true);
        return;
    }
    if (e.getEntity() instanceof PigZombie) {
        Block block = e.getLocation().getBlock().getRelative(BlockFace.DOWN);
        if (isNetherFortressWalkway(block)) {
            e.setCancelled(true);
            double p = RND.nextDouble();
            if (p <= chanceWither && block.getRelative(BlockFace.UP, 3).getType() == Material.AIR) {
                WitherSkeleton mob = (WitherSkeleton) e.getLocation().getWorld().spawnEntity(
                    e.getLocation(), EntityType.WITHER_SKELETON);
                mob.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD, 1));
            } else if (p <= chanceWither+chanceBlaze) {
                e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.BLAZE);
            } else if (p <= chanceWither+chanceBlaze+chanceSkeleton) {
                e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.SKELETON);
            } else {
                e.setCancelled(false); // Spawn PigZombie
            }
        }
    }
}
 
Example #30
Source File: SpawnEventsTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onPhantomSpawn_notInSkyworld() {
    when(worldManager.isSkyWorld(any(World.class))).thenReturn(false);

    CreatureSpawnEvent event = new CreatureSpawnEvent(getFakePhantom(),
            CreatureSpawnEvent.SpawnReason.NATURAL);
    spawnEvents.setPhantomsInOverworld(false);
    spawnEvents.onPhantomSpawn(event);

    assertFalse(event.isCancelled());
}