类org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason源码实例Demo

下面列出了怎么用org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason的API类实例代码及写法,或者点击链接到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 项目: Thermos   文件: CraftWorld.java
public Entity spawnEntity(Location loc, EntityType entityType) {
    // Cauldron start - handle custom entity spawns from plugins
    if (EntityRegistry.entityClassMap.get(entityType.getName()) != null)
    {
        net.minecraft.entity.Entity entity = null;
        entity = getEntity(EntityRegistry.entityClassMap.get(entityType.getName()), world);
        if (entity != null)
        {
            entity.setLocationAndAngles(loc.getX(), loc.getY(), loc.getZ(), 0, 0);
            world.addEntity(entity, SpawnReason.CUSTOM);
            return entity.getBukkitEntity();
        }
    }
    // Cauldron end
    return spawn(loc, entityType.getEntityClass());
}
 
源代码4 项目: civcraft   文件: MobBaseZombie.java
public static Entity spawn(Location loc, ICustomMob iCustom, String name) {
	CraftWorld world = (CraftWorld) loc.getWorld();
	World mcWorld = world.getHandle();
	MobBaseZombie zombie = new MobBaseZombie(mcWorld, iCustom);
	
	if (name != null) {
		zombie.setCustomName(name);
		zombie.setCustomNameVisible(true);
	}
	iCustom.setEntity(zombie);
	
	zombie.setPosition(loc.getX(), loc.getY(), loc.getZ());
	mcWorld.addEntity(zombie, SpawnReason.CUSTOM);
	
	return zombie;
}
 
源代码5 项目: 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);
    }
}
 
源代码6 项目: 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);
    }
}
 
源代码7 项目: Kettle   文件: CraftWorld.java
public Item dropItem(Location loc, ItemStack item) {
    Validate.notNull(item, "Cannot drop a Null item.");
    Validate.isTrue(item.getTypeId() != 0, "Cannot drop AIR.");
    EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item));
    entity.pickupDelay = 10;
    world.spawnEntity(entity, SpawnReason.CUSTOM);
    // TODO this is inconsistent with how Entity.getBukkitEntity() works.
    // However, this entity is not at the moment backed by a server entity class so it may be left.
    return new CraftItem(world.getServer(), entity);
}
 
源代码8 项目: Kettle   文件: CraftWorld.java
public Entity spawnEntity(Location loc, EntityType entityType) {
    if (EntityRegistry.entityClassMap.get(entityType.getName()) != null) {
        net.minecraft.entity.Entity entity = null;
        entity = getEntity(EntityRegistry.entityClassMap.get(entityType.getName()), world);
        if (entity != null) {
            entity.setLocationAndAngles(loc.getX(), loc.getY(), loc.getZ(), 0, 0);
            world.spawnEntity(entity, SpawnReason.CUSTOM);
            return entity.getBukkitEntity();
        }
    }
    return spawn(loc, entityType.getEntityClass());
}
 
源代码9 项目: Kettle   文件: CraftWorld.java
public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException {
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(material, "Material cannot be null");
    Validate.isTrue(material.isBlock(), "Material must be a block");

    EntityFallingBlock entity = new EntityFallingBlock(world, location.getX(), location.getY(), location.getZ(), CraftMagicNumbers.getBlock(material).getStateFromMeta(data));
    entity.ticksExisted = 1;

    world.spawnEntity(entity, SpawnReason.CUSTOM);
    return (FallingBlock) entity.getBukkitEntity();
}
 
源代码10 项目: Kettle   文件: CraftWorld.java
@SuppressWarnings("unchecked")
public <T extends Entity> T addEntity(net.minecraft.entity.Entity entity, SpawnReason reason, Consumer<T> function) throws IllegalArgumentException {
    Preconditions.checkArgument(entity != null, "Cannot spawn null entity");

    if (entity instanceof EntityLiving) {
        ((EntityLiving) entity).onInitialSpawn(getHandle().getDifficultyForLocation(new BlockPos(entity)), null);
    }

    if (function != null) {
        function.accept((T) entity.getBukkitEntity());
    }

    world.spawnEntity(entity, reason);
    return (T) entity.getBukkitEntity();
}
 
源代码11 项目: Kettle   文件: CraftEventFactory.java
/**
 * CreatureSpawnEvent
 */
public static CreatureSpawnEvent callCreatureSpawnEvent(EntityLivingBase entityliving, SpawnReason spawnReason) {
    LivingEntity entity = (LivingEntity) entityliving.getBukkitEntity();
    CraftServer craftServer = (CraftServer) entity.getServer();

    CreatureSpawnEvent event = new CreatureSpawnEvent(entity, spawnReason);
    craftServer.getPluginManager().callEvent(event);
    return event;
}
 
源代码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 项目: CombatLogX   文件: ListenerMobCombat.java
private boolean checkMobSpawnReasonDisabled(LivingEntity enemy) {
    FileConfiguration config = this.expansion.getConfig("mob-tagger.yml");
    List<String> spawnReasonList = config.getStringList("spawn-reason-list");
    if(spawnReasonList.contains("*")) return true;
    
    SpawnReason spawnReason = getSpawnReason(enemy);
    String spawnReasonName = spawnReason.name();
    return spawnReasonList.contains(spawnReasonName);
}
 
源代码14 项目: CombatLogX   文件: ListenerMobCombat.java
private SpawnReason getSpawnReason(LivingEntity entity) {
    if(entity == null) return SpawnReason.DEFAULT;
    if(!entity.hasMetadata("combatlogx_spawn_reason")) return SpawnReason.DEFAULT;

    List<MetadataValue> spawnReasonValues = entity.getMetadata("combatlogx_spawn_reason");
    for(MetadataValue metadataValue : spawnReasonValues) {
        Object object = metadataValue.value();
        if(!(object instanceof SpawnReason)) continue;
        
        return (SpawnReason) object;
    }
    
    return SpawnReason.DEFAULT;
}
 
源代码15 项目: Thermos   文件: CraftWorld.java
public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException {
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(material, "Material cannot be null");
    Validate.isTrue(material.isBlock(), "Material must be a block");

    double x = location.getBlockX() + 0.5;
    double y = location.getBlockY() + 0.5;
    double z = location.getBlockZ() + 0.5;

    net.minecraft.entity.item.EntityFallingBlock entity = new net.minecraft.entity.item.EntityFallingBlock(world, x, y, z, net.minecraft.block.Block.getBlockById(material.getId()), data);
    entity.field_145812_b = 1; // ticksLived

    world.addEntity(entity, SpawnReason.CUSTOM);
    return (FallingBlock) entity.getBukkitEntity();
}
 
源代码16 项目: Thermos   文件: CauldronHooks.java
public static void logEntitySpawn(World world, Entity entity, SpawnReason spawnReason)
{
    if (MinecraftServer.cauldronConfig.entitySpawnLogging.getValue())
    {
        logInfo("Dim: {0} Spawning ({1}): {2}", world.provider.dimensionId, spawnReason, entity);
        logInfo("Dim: {0} Entities Last Tick: {1}", world.provider.dimensionId, world.entitiesTicked);
        logInfo("Dim: {0} Tiles Last Tick: {1}", world.provider.dimensionId, world.tilesTicked);
        //logInfo("Chunk Is Active: {0}", world.inActiveChunk(entity));
        logStack();
    }
}
 
源代码17 项目: civcraft   文件: MobBaseVillager.java
public static Entity spawn(Location loc, String name) {
		CraftWorld world = (CraftWorld) loc.getWorld();
		World mcWorld = world.getHandle();
		MobBaseVillager zombie = new MobBaseVillager(mcWorld);
		
//		if (name != null) {
//			zombie.setCustomName(name);
//			zombie.setCustomNameVisible(true);
//		}
		
		zombie.setPosition(loc.getX(), loc.getY(), loc.getZ());
		mcWorld.addEntity(zombie, SpawnReason.CUSTOM);
		
		return zombie;
	}
 
源代码18 项目: civcraft   文件: MobBasePigZombie.java
public static Entity spawnCustom(Location loc, ICustomMob iCustom) {
	CraftWorld world = (CraftWorld) loc.getWorld();
	World mcWorld = world.getHandle();
	MobBasePigZombie pigzombie = new MobBasePigZombie(mcWorld, iCustom);
	iCustom.setEntity(pigzombie);
	
	pigzombie.setPosition(loc.getX(), loc.getY(), loc.getZ());
	mcWorld.addEntity(pigzombie, SpawnReason.CUSTOM);
	
	return pigzombie;
}
 
源代码19 项目: civcraft   文件: MobBaseZombieGiant.java
public static Entity spawnCustom(Location loc, ICustomMob iCustom) {
	CraftWorld world = (CraftWorld) loc.getWorld();
	World mcWorld = world.getHandle();
	MobBaseZombieGiant zombie = new MobBaseZombieGiant(mcWorld, iCustom);
	iCustom.setEntity(zombie);

	zombie.setPosition(loc.getX(), loc.getY(), loc.getZ());
	mcWorld.addEntity(zombie, SpawnReason.CUSTOM);
	
	return zombie;
}
 
源代码20 项目: civcraft   文件: MobBaseZombie.java
public static Entity spawnCustom(Location loc, ICustomMob iCustom) {
	CraftWorld world = (CraftWorld) loc.getWorld();
	World mcWorld = world.getHandle();
	MobBaseZombie zombie = new MobBaseZombie(mcWorld, iCustom);
	iCustom.setEntity(zombie);

	zombie.setPosition(loc.getX(), loc.getY(), loc.getZ());
	mcWorld.addEntity(zombie, SpawnReason.CUSTOM);
	
	return zombie;
}
 
源代码21 项目: civcraft   文件: MobBaseIronGolem.java
public static Entity spawnCustom(Location loc, ICustomMob iCustom) {
	CraftWorld world = (CraftWorld) loc.getWorld();
	World mcWorld = world.getHandle();
	MobBaseIronGolem pigzombie = new MobBaseIronGolem(mcWorld, iCustom);
	iCustom.setEntity(pigzombie);
	
	pigzombie.setPosition(loc.getX(), loc.getY(), loc.getZ());
	mcWorld.addEntity(pigzombie, SpawnReason.CUSTOM);
	
	return pigzombie;
}
 
源代码22 项目: civcraft   文件: MobBaseWitch.java
public static Entity spawnCustom(Location loc, ICustomMob iCustom) {
	CraftWorld world = (CraftWorld) loc.getWorld();
	World mcWorld = world.getHandle();
	MobBaseWitch witch = new MobBaseWitch(mcWorld, iCustom);
	iCustom.setEntity(witch);
	
	witch.setPosition(loc.getX(), loc.getY(), loc.getZ());
	mcWorld.addEntity(witch, SpawnReason.CUSTOM);
	
	return witch;
}
 
源代码23 项目: civcraft   文件: MobBaseWither.java
public static Entity spawnCustom(Location loc, ICustomMob iCustom) {
	CraftWorld world = (CraftWorld) loc.getWorld();
	World mcWorld = world.getHandle();
	MobBaseWither pigzombie = new MobBaseWither(mcWorld, iCustom);
	iCustom.setEntity(pigzombie);
	
	pigzombie.setPosition(loc.getX(), loc.getY(), loc.getZ());
	mcWorld.addEntity(pigzombie, SpawnReason.CUSTOM);
	
	return pigzombie;
}
 
源代码24 项目: worldedit-adapters   文件: Spigot_v1_16_R1.java
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

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

    Entity createdEntity = createEntityFromId(state.getType().getId(), 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, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
源代码25 项目: worldedit-adapters   文件: Spigot_v1_15_R2.java
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

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

    Entity createdEntity = createEntityFromId(state.getType().getId(), 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, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
源代码26 项目: worldedit-adapters   文件: Spigot_v1_14_R4.java
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

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

    Entity createdEntity = createEntityFromId(state.getType().getId(), 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, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
源代码27 项目: worldedit-adapters   文件: Spigot_v1_13_R2_2.java
@Nullable
@Override
public org.bukkit.entity.Entity createEntity(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);

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

    Entity createdEntity = createEntityFromId(state.getType().getId(), 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, SpawnReason.CUSTOM);
        return createdEntity.getBukkitEntity();
    } else {
        return null;
    }
}
 
源代码28 项目: askyblock   文件: NetherSpawning.java
@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");
        }
    }
}
 
源代码29 项目: HolographicDisplays   文件: NmsManagerImpl.java
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add");

if (validateEntityMethod == null) {
	return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
}

      final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
      final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0);
      
      if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) {
      	// This should never happen
          nmsEntity.dead = true;
          return false;
      }
      
      nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
      nmsWorld.entityList.add(nmsEntity);
      
      try {
	validateEntityMethod.invoke(nmsWorld, nmsEntity);
} catch (Exception e) {
	e.printStackTrace();
	return false;
}
      return true;
  }
 
源代码30 项目: HolographicDisplays   文件: NmsManagerImpl.java
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add");

if (validateEntityMethod == null) {
	return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
}

      final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0);
      final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0);
      
      if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) {
      	// This should never happen
          nmsEntity.dead = true;
          return false;
      }
      
      nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity);
      nmsWorld.entityList.add(nmsEntity);
      
      try {
	validateEntityMethod.invoke(nmsWorld, nmsEntity);
} catch (Exception e) {
	e.printStackTrace();
	return false;
}
      return true;
  }
 
 类所在包
 类方法
 同包方法