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

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

源代码1 项目: BedWars   文件: WorldListener.java
@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;
                        }
                    }
            }
    }
}
 
源代码2 项目: BedWars   文件: WorldListener.java
@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;
                        }
                    }
            }
    }
}
 
源代码3 项目: VoxelGamesLibv2   文件: MobFeature.java
@EventHandler
public void onSpawn(@Nonnull CreatureSpawnEvent event) {
    if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM ||
            event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) {
        return;
    }
    if (!denySpawn) {
        return;
    }
    if (!event.getLocation().getWorld().getName().equals(worldName)) {
        return;
    }

    if (blacklist.length != 0) {
        if (Arrays.stream(blacklist).anyMatch(m -> m.equals(event.getEntityType()))) {
            event.setCancelled(true);
        }
    } else if (whitelist.length != 0) {
        if (Arrays.stream(whitelist).noneMatch(m -> m.equals(event.getEntityType()))) {
            event.setCancelled(true);
        }
    } else {
        event.setCancelled(true);
    }
}
 
源代码4 项目: DungeonsXL   文件: DMobListener.java
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
    World world = event.getLocation().getWorld();

    EditWorld editWorld = plugin.getEditWorld(world);
    GameWorld gameWorld = plugin.getGameWorld(world);

    if (editWorld != null || gameWorld != null) {
        switch (event.getSpawnReason()) {
            case CHUNK_GEN:
            case JOCKEY:
            case MOUNT:
            case NATURAL:
                event.setCancelled(true);
        }
    }
}
 
源代码5 项目: 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()));
        }
    }
}
 
源代码6 项目: 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);
    }
}
 
源代码7 项目: BedWars   文件: WorldListener.java
@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);
    }
}
 
源代码8 项目: 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());
}
 
源代码9 项目: PGM   文件: OwnedMobTracker.java
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSlimeSplit(CreatureSpawnEvent event) {
  switch (event.getSpawnReason()) {
    case SLIME_SPLIT:
      Slime parent = splitter.get();
      if (parent != null) {
        MobInfo info = resolveEntity(parent);
        if (info != null) {
          entities().trackEntity(event.getEntity(), info);
        }
      }
      break;
  }
}
 
源代码10 项目: BedWars   文件: WorldListener.java
@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);
    }
}
 
源代码11 项目: ProjectAres   文件: OwnedMobTracker.java
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSlimeSplit(CreatureSpawnEvent event) {
    switch(event.getSpawnReason()) {
        case SLIME_SPLIT:
            Slime parent = splitter.get();
            if(parent != null) {
                MobInfo info = resolveEntity(parent);
                if(info != null) {
                    entities().trackEntity(event.getEntity(), info);
                }
            }
            break;
    }
}
 
源代码12 项目: 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);
}
 
源代码13 项目: 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
            }
        }
    }
}
 
源代码14 项目: 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);
            }
        }
}
 
源代码15 项目: ProjectAres   文件: MobsMatchModule.java
@EventHandler(ignoreCancelled = true)
public void checkSpawn(final CreatureSpawnEvent event) {
    if(event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.CUSTOM) {
        event.setCancelled(mobsFilter.query(new EntitySpawnQuery(event, event.getEntity(), event.getSpawnReason())).isDenied());
    }
}
 
源代码16 项目: 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());

}
 
源代码17 项目: 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);
    }
}
 
源代码18 项目: CardinalPGM   文件: MobModule.java
@EventHandler
public void onMobSpawn(CreatureSpawnEvent event) {
    if (event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.CUSTOM && filter.evaluate(event, event.getSpawnReason(), event.getEntityType(), event.getEntity()).equals(FilterState.DENY))
        event.setCancelled(true);
}
 
源代码19 项目: Shopkeepers   文件: BlockVillagerSpawnListener.java
@EventHandler(ignoreCancelled = true)
void onSpawn(CreatureSpawnEvent event) {
	if (event.getEntityType() == EntityType.VILLAGER && event.getSpawnReason() != SpawnReason.CUSTOM) {
		event.setCancelled(true);
	}
}
 
源代码20 项目: EliteMobs   文件: DeadMoon.java
@EventHandler(priority = EventPriority.HIGHEST)
public void onSpawn(CreatureSpawnEvent event) {

    if (event.isCancelled()) return;

    if (event.getEntity().getWorld().getTime() < 13184 || event.getEntity().getWorld().getTime() > 22800) return;
    if (!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL)) return;
    if (!(event.getEntity().getType().equals(EntityType.ZOMBIE)) && !(event.getEntity().getType().equals(EntityType.HUSK)))
        return;
    if (!EventLauncher.verifyPlayerCount()) return;

    if (!EliteMobs.validWorldList.contains(event.getEntity().getWorld())) return;

    if (event.getEntity().getWorld().getEnvironment().equals(World.Environment.NETHER) ||
            event.getEntity().getWorld().getEnvironment().equals(World.Environment.THE_END)) return;

    if (MoonPhaseDetector.detectMoonPhase(event.getEntity().getWorld()) != MoonPhaseDetector.moonPhase.NEW_MOON)
        return;

    if (!ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.NATURAL_MOB_SPAWNING) ||
            !ConfigValues.validMobsConfig.getBoolean(ValidMobsConfig.ALLOW_AGGRESSIVE_ELITEMOBS))
        return;


    if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) && !ConfigValues.mobCombatSettingsConfig.getBoolean(MobCombatSettingsConfig.SPAWNERS_SPAWN_ELITE_MOBS))
        return;

    if (!(event.getSpawnReason() == NATURAL || event.getSpawnReason() == CUSTOM)) return;

    if (!EntityTracker.isEliteMob(event.getEntity()))
        NaturalEliteMobSpawnEventHandler.naturalMobProcessor(event.getEntity(), CreatureSpawnEvent.SpawnReason.NATURAL);

    //add entityQueued
    if (entityQueued && !TheReturned.isTheReturned(event.getEntity())
            && (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) ||
            event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM))) {

        eventOngoing = true;
        entityQueued = false;

        EventMessage.sendEventMessage(event.getEntity(), ConfigValues.eventsConfig.getString(EventsConfig.DEADMOON_ANNOUNCEMENT_MESSAGE));

        ZombieKing.spawnZombieKing(event.getLocation());
        terminateEvent(event.getEntity());

    }

}