Java Code Examples for org.bukkit.event.entity.CreatureSpawnEvent#getEntity()

The following examples show how to use org.bukkit.event.entity.CreatureSpawnEvent#getEntity() . 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: 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 2
Source File: SpawnEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event == null || !plugin.getWorldManager().isSkyAssociatedWorld(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.getEntity() instanceof WaterMob) {
        Location loc = event.getLocation();
        if (isDeepOceanBiome(loc) && isPrismarineRoof(loc)) {
            loc.getWorld().spawnEntity(loc, EntityType.GUARDIAN);
            event.setCancelled(true);
        }
    }
    if (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()));
        }
    }
}
 
Example 3
Source File: SpawnEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPhantomSpawn(CreatureSpawnEvent event) {
    if (!(event.getEntity() instanceof Phantom) ||
            event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.NATURAL) {
        return;
    }

    World spawnWorld = event.getEntity().getWorld();
    if (!phantomsInOverworld && plugin.getWorldManager().isSkyWorld(spawnWorld)) {
        event.setCancelled(true);
    }

    if (!phantomsInNether && plugin.getWorldManager().isSkyNether(spawnWorld)) {
        event.setCancelled(true);
    }
}
 
Example 4
Source File: MobsMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void checkSpawn(final CreatureSpawnEvent event) {
  if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM
      || event.getEntity() instanceof ArmorStand) {
    return;
  }

  QueryResponse response =
      this.mobsFilter.query(
          new EntitySpawnQuery(event, event.getEntity(), event.getSpawnReason()));
  event.setCancelled(response.isDenied());
}
 
Example 5
Source File: LWCEntityListener.java    From Modern-LWC with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCreateSpawn(CreatureSpawnEvent e) {
    if (placedArmorStandPlayer != null) {
        Player player = plugin.getServer().getPlayer(placedArmorStandPlayer);
        Entity block = e.getEntity();
        placedArmorStandPlayer = null;
        if (player != null) {
            if (player.getWorld().equals(block.getWorld())
                    && player.getLocation().distance(block.getLocation()) <= 5) {
                entityCreatedByPlayer(block, player);
            }
        }
    }
}
 
Example 6
Source File: ListenerMobCombat.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@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 7
Source File: Compat18.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {

    Entity e = event.getEntity();

    //spawn arms on armor stands
    if (e instanceof ArmorStand && RedProtect.get().config.configRoot().hooks.armor_stand_arms) {
        ArmorStand as = (ArmorStand) e;
        as.setArms(true);
    }
}
 
Example 8
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 9
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 10
Source File: EntityListener.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Change rabbit's color and age depending on chance.
 * @param evt 
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onRabbitSpawned(CreatureSpawnEvent evt) {
    if (evt.getEntityType() == Carbon.injector().rabbitEntity)
        if (evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG ||
            evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG ||
            evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL ||
            evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BREEDING || 
            evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER) {
            Rabbit rabbit = (Rabbit)evt.getEntity();
            if (evt.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG && rabbit.hasParent()) {
                rabbit.setRabbitType(rabbit.getParent().getRabbitType());
                return;
            }
            int type = Utilities.random.nextInt(6);
            boolean isKiller = Utilities.random.nextInt(1000) == 999;
            if (evt.getSpawnReason() != CreatureSpawnEvent.SpawnReason.DISPENSE_EGG &&
                evt.getSpawnReason() != CreatureSpawnEvent.SpawnReason.SPAWNER_EGG &&
                evt.getSpawnReason() != CreatureSpawnEvent.SpawnReason.BREEDING &&
                evt.getSpawnReason() != CreatureSpawnEvent.SpawnReason.SPAWNER) {
                boolean isBaby = Utilities.random.nextInt(4) == 3;
                if (isBaby) {
                    rabbit.setBaby();
                }
            }
            if (isKiller) {
                rabbit.setRabbitType(EntityRabbit.TYPE_KILLER);
            } else {
                rabbit.setRabbitType(type);
            }
        }
}
 
Example 11
Source File: BreedingTaskType.java    From Quests with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBreed(CreatureSpawnEvent e) {
    if (!e.getSpawnReason().equals(SpawnReason.BREEDING)) {
        return;
    }

    Entity ent = e.getEntity();
    List<Entity> entList = ent.getNearbyEntities(10, 10, 10);

    if (entList.isEmpty()) {
        return;
    }
    // Check if there is a player in the list, otherwise: return.
    for (Entity current : entList) {

        if (current instanceof Player) {
            Player player = (Player) current;
            QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true);
            QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();

            for (Quest quest : super.getRegisteredQuests()) {
                if (questProgressFile.hasStartedQuest(quest)) {
                    QuestProgress questProgress = questProgressFile.getQuestProgress(quest);

                    for (Task task : quest.getTasksOfType(super.getType())) {
                        TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());

                        if (taskProgress.isCompleted()) {
                            continue;
                        }

                        int breedingNeeded = (int) task.getConfigValue("amount");
                        int breedingProgress;

                        if (taskProgress.getProgress() == null) {
                            breedingProgress = 0;
                        } else {
                            breedingProgress = (int) taskProgress.getProgress();
                        }

                        taskProgress.setProgress(breedingProgress + 1);

                        if (((int) taskProgress.getProgress()) >= breedingNeeded) {
                            taskProgress.setCompleted(true);
                        }
                    }
                }
            }
        }
    }
}
 
Example 12
Source File: NaturalMobSpawnEventHandler.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onSpawn(CreatureSpawnEvent event) {

    if (getIgnoreMob()) {
        setIgnoreMob(false);
        return;
    }

    if (event.isCancelled()) return;
    /*
    Deal with entities spawned within the plugin
     */
    if (EntityTracker.isEliteMob(event.getEntity())) return;

    if (!ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.NATURAL_MOB_SPAWNING))
        return;
    if (!ConfigValues.validMobsConfig.getBoolean(ValidMobsConfig.ALLOW_AGGRESSIVE_ELITEMOBS))
        return;
    if (!ConfigValues.validWorldsConfig.getBoolean("Valid worlds." + event.getEntity().getWorld().getName()))
        return;
    if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) && !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.SPAWNERS_SPAWN_ELITE_MOBS))
        return;
    if (event.getEntity().getCustomName() != null && ConfigValues.defaultConfig.getBoolean(DefaultConfig.PREVENT_ELITE_MOB_CONVERSION_OF_NAMED_MOBS))
        return;

    if (!(event.getSpawnReason() == NATURAL || event.getSpawnReason() == CUSTOM && !ConfigValues.defaultConfig.getBoolean(DefaultConfig.STRICT_SPAWNING_RULES)))
        return;
    if (!EliteMobProperties.isValidEliteMobType(event.getEntityType()))
        return;

    LivingEntity livingEntity = event.getEntity();

    int huntingGearChanceAdder = getHuntingGearBonus(livingEntity);

    Double validChance = (ConfigValues.mobCombatSettingsConfig.getDouble(MobCombatSettingsConfig.AGGRESSIVE_MOB_CONVERSION_PERCENTAGE) +
            huntingGearChanceAdder) / 100;

    if (!(ThreadLocalRandom.current().nextDouble() < validChance))
        return;

    NaturalEliteMobSpawnEventHandler.naturalMobProcessor(livingEntity, event.getSpawnReason());

}
 
Example 13
Source File: SmallTreasureGoblin.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler (priority = EventPriority.HIGHEST)
public void onSpawn(CreatureSpawnEvent event) {

    if (event.isCancelled()) return;
    if (!EventLauncher.verifyPlayerCount()) return;

    if (EliteMobs.validWorldList.contains(event.getEntity().getWorld())) {

        if (entityQueued && (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) ||
                event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM)) &&
                event.getEntity() instanceof Zombie) {

            entityQueued = false;
            initalizeEvent(event.getLocation());

        }

    }

}
 
Example 14
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Prevents mobs spawning naturally at spawn or in an island
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onNaturalMobSpawn(final CreatureSpawnEvent e) {
    // if grid is not loaded yet, return.
    if (plugin.getGrid() == null) {
        return;
    }
    // If not in the right world, return
    if (!IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    // Deal with natural spawning
    if (e.getSpawnReason().equals(SpawnReason.NATURAL)
            || e.getSpawnReason().equals(SpawnReason.CHUNK_GEN)
            || e.getSpawnReason().equals(SpawnReason.DEFAULT)
            || e.getSpawnReason().equals(SpawnReason.MOUNT)
            || e.getSpawnReason().equals(SpawnReason.JOCKEY)
            || e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)) {
        if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
            if (!actionAllowed(e.getLocation(), SettingsFlag.MONSTER_SPAWN)) {                
                if (DEBUG3)
                    plugin.getLogger().info("Natural monster spawn cancelled.");
                // Mobs not allowed to spawn
                e.setCancelled(true);
                return;
            }
        } else if (e.getEntity() instanceof Animals) {
            if (!actionAllowed(e.getLocation(), SettingsFlag.MOB_SPAWN)) {
                // Animals are not allowed to spawn
                if (DEBUG2)
                    plugin.getLogger().info("Natural animal spawn cancelled.");
                e.setCancelled(true);
                return;
            }
        }
    }
    if (DEBUG2) {
        plugin.getLogger().info("Mob spawn allowed " + e.getEventName());
        plugin.getLogger().info(e.getSpawnReason().toString());
        plugin.getLogger().info(e.getEntityType().toString());
    }
}
 
Example 15
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onVillagerSpawn(final CreatureSpawnEvent e) {
    // If not an villager
    if (!(e.getEntity() instanceof Villager)) {
        return;
    }
    if (DEBUG3) {
        plugin.getLogger().info("Villager spawn event! " + e.getEventName());
        plugin.getLogger().info("Reason:" + e.getSpawnReason().toString());
        plugin.getLogger().info("Entity:" + e.getEntityType().toString());
    }
    // Only cover overworld
    if (!e.getEntity().getWorld().equals(ASkyBlock.getIslandWorld())) {
        return;
    }
    // If there's no limit - leave it
    if (Settings.villagerLimit <= 0) {
        return;
    }
    // We only care about villagers breeding, being cured or coming from a spawn egg, etc.
    if (e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.BREEDING
            && e.getSpawnReason() != SpawnReason.DISPENSE_EGG && e.getSpawnReason() != SpawnReason.SPAWNER_EGG
            && e.getSpawnReason() != SpawnReason.CURED) {
        return;
    }
    Island island = plugin.getGrid().getProtectedIslandAt(e.getLocation());
    if (island == null || island.getOwner() == null || island.isSpawn()) {
        // No island, no limit
        return;
    }
    int limit = Settings.villagerLimit * Math.max(1,plugin.getPlayers().getMembers(island.getOwner()).size());
    //plugin.getLogger().info("DEBUG: villager limit = " + limit);
    //long time = System.nanoTime();
    int pop = island.getPopulation();
    //plugin.getLogger().info("DEBUG: time = " + ((System.nanoTime() - time)*0.000000001));
    if (pop >= limit) {
        plugin.getLogger().warning(
                "Island at " + island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ() + " hit the island villager limit of "
                        + limit);
        //plugin.getLogger().info("Stopped villager spawning on island " + island.getCenter());
        // Get all players in the area
        List<Entity> players = e.getEntity().getNearbyEntities(10,10,10);
        for (Entity player: players) {
            if (player instanceof Player) {
                Player p = (Player) player;
                Util.sendMessage(p, ChatColor.RED + plugin.myLocale(island.getOwner()).villagerLimitError.replace("[number]", String.valueOf(limit)));
            }
        }
        plugin.getMessages().tellTeam(island.getOwner(), ChatColor.RED + plugin.myLocale(island.getOwner()).villagerLimitError.replace("[number]", String.valueOf(limit)));
        if (e.getSpawnReason().equals(SpawnReason.CURED)) {
            // Easter Egg. Or should I say Easter Apple?
            ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE);
            // Nerfed
            //goldenApple.setDurability((short)1);
            e.getLocation().getWorld().dropItemNaturally(e.getLocation(), goldenApple);
        }
        e.setCancelled(true);
    }
}