org.bukkit.event.entity.CreatureSpawnEvent#getEntity ( )源码实例Demo

下面列出了org.bukkit.event.entity.CreatureSpawnEvent#getEntity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: StackMob-3   文件: SpawnEvent.java
@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);
}
 
源代码2 项目: uSkyBlock   文件: SpawnEvents.java
@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()));
        }
    }
}
 
源代码3 项目: uSkyBlock   文件: SpawnEvents.java
@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);
    }
}
 
源代码4 项目: PGM   文件: MobsMatchModule.java
@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());
}
 
源代码5 项目: Modern-LWC   文件: LWCEntityListener.java
@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);
            }
        }
    }
}
 
源代码6 项目: CombatLogX   文件: ListenerMobCombat.java
@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);
}
 
源代码7 项目: RedProtect   文件: Compat18.java
@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);
    }
}
 
源代码8 项目: iDisguise   文件: EventListener.java
@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);
}
 
源代码9 项目: uSkyBlock   文件: NetherTerraFormEvents.java
/**
 * 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
            }
        }
    }
}
 
源代码10 项目: Carbon   文件: EntityListener.java
/**
 * 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);
            }
        }
}
 
源代码11 项目: Quests   文件: BreedingTaskType.java
@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);
                        }
                    }
                }
            }
        }
    }
}
 
源代码12 项目: EliteMobs   文件: NaturalMobSpawnEventHandler.java
@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());

}
 
源代码13 项目: EliteMobs   文件: SmallTreasureGoblin.java
@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());

        }

    }

}
 
源代码14 项目: askyblock   文件: EntityLimits.java
/**
 * 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());
    }
}
 
源代码15 项目: askyblock   文件: EntityLimits.java
@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);
    }
}