org.bukkit.event.entity.EntitySpawnEvent Java Examples

The following examples show how to use org.bukkit.event.entity.EntitySpawnEvent. 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: BlockEventTracker.java    From GriefDefender with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFalling(EntitySpawnEvent event) {
    final Entity entity = event.getEntity();
    final World world = entity.getWorld();
    if (entity instanceof FallingBlock) {
        // add owner
        final Location location = entity.getLocation();
        final Block block = world.getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
        final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getWorld().getUID());
        final GDChunk gdChunk = claimWorldManager.getChunk(location.getChunk());
        final UUID ownerUniqueId = gdChunk.getBlockOwnerUUID(block.getLocation());
        if (ownerUniqueId != null) {
            final GDEntity gdEntity = new GDEntity(event.getEntity().getEntityId());
            gdEntity.setOwnerUUID(ownerUniqueId);
            gdEntity.setNotifierUUID(ownerUniqueId);
            EntityTracker.addTempEntity(gdEntity);
        }
    }
}
 
Example #2
Source File: EntitySpawnListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
    final Entity entity = event.getEntity();
    final Location location = entity.getLocation();
    final IslandManager islandManager = IridiumSkyblock.getIslandManager();
    final Island island = islandManager.getIslandViaLocation(location);
    if (island == null) return;

    if (!IridiumSkyblock.getConfiguration().blockedEntities.contains(event.getEntityType())) return;

    IridiumSkyblock.getInstance().entities.put(entity.getUniqueId(), island);
    monitorEntity(entity);
}
 
Example #3
Source File: ArmorStandListener.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler
public void armorStandStop(EntitySpawnEvent event)
{
    if(event.getEntityType() == EntityType.ARMOR_STAND)
        event.setCancelled(true);
}
 
Example #4
Source File: MergeHandler.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onSpawnMerge(EntitySpawnEvent event) {

    if (!ConfigValues.validWorldsConfig.getBoolean("Valid worlds." + event.getEntity().getWorld().getName()))
        return;
    validateEntityType(event.getEntity());

}
 
Example #5
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onFallBlockPlace(EntitySpawnEvent e) {
    if (e.getEntityType().equals(EntityType.FALLING_BLOCK)) {
        Region r = RedProtect.get().rm.getTopRegion(e.getLocation());
        if (r != null && !r.allowGravity()) {
            e.getEntity().remove();
        }
    }
}
 
Example #6
Source File: MobSpawningRate.java    From GlobalWarming with GNU Lesser General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onMobSpawn(EntitySpawnEvent event) {
    WorldClimateEngine worldEngine = ClimateEngine.getInstance().getClimateEngine(event.getLocation().getWorld().getUID());
    if (worldEngine != null && worldEngine.isEffectEnabled(ClimateEffectType.MOB_SPAWN_RATE)) {
        MobDistribution distribution = worldEngine.getEntityFitnessModel().getEntityFitnessMap().get(event.getEntityType());
        if (distribution != null) {
            double chance = distribution.getValue(worldEngine.getTemperature());
            double random = GlobalWarming.getInstance().getRandom().nextDouble();
            if (chance / 100.f <= random) {
                //Cancel the mob:
                event.setCancelled(true);

                //Spawn an alternative, if available:
                String alternative = distribution.getAlternate();
                if (alternative != null && !alternative.isEmpty()) {
                    try {
                        //Spawn:
                        Entity entity = event.getLocation().getWorld().spawn(
                                event.getLocation(),
                                EntityType.fromName(alternative).getEntityClass());

                        //Make it a baby, if possible (for fun):
                        if (entity instanceof Ageable) {
                            ((Ageable) entity).setBaby();
                        } else switch (entity.getType()) {
                            case PHANTOM:
                                ((Phantom) entity).setSize(1);
                                break;
                            case ZOMBIE:
                            case DROWNED:
                            case HUSK:
                            case PIG_ZOMBIE:
                            case ZOMBIE_VILLAGER:
                                ((Zombie) entity).setBaby(true);
                                break;
                        }

                    } catch (Exception e) {
                        GlobalWarming.getInstance().getLogger().warning(String.format(
                                "Error spawning alternate mob: [%s]",
                                distribution.getAlternate()));
                    }
                }
            }
        }
    }
}
 
Example #7
Source File: ThreadSafetyListener.java    From LagMonitor with MIT License 4 votes vote down vote up
@EventHandler
public void onSpawnChange(EntitySpawnEvent spawnEvent) {
    checkSafety(spawnEvent);
}
 
Example #8
Source File: ThreadSafetyListener.java    From LagMonitor with MIT License 4 votes vote down vote up
@EventHandler
public void onSpawnChange(EntitySpawnEvent spawnEvent) {
    checkSafety(spawnEvent);
}
 
Example #9
Source File: TheReturned.java    From EliteMobs with GNU General Public License v3.0 3 votes vote down vote up
@EventHandler
public void onSpawn(EntitySpawnEvent event) {

    if (!DeadMoon.eventOngoing) return;

    if (event.getEntity() instanceof LivingEntity && theReturnedList.contains(event.getEntity()))
        spawnTheReturned((Zombie) event.getEntity());

}