Search in sources :

Example 1 with GhastEntity

use of net.minecraft.entity.monster.GhastEntity in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method doEntityAddEventCalling.

public static boolean doEntityAddEventCalling(World world, Entity entity, SpawnReason spawnReason) {
    if (entity == null)
        return false;
    org.bukkit.event.Cancellable event = null;
    if (entity instanceof net.minecraft.entity.LivingEntity && !(entity instanceof ServerPlayerEntity)) {
        boolean isAnimal = entity instanceof AnimalEntity || entity instanceof WaterMobEntity || entity instanceof GolemEntity;
        boolean isMonster = entity instanceof MonsterEntity || entity instanceof GhastEntity || entity instanceof SlimeEntity;
        boolean isNpc = entity instanceof INPC;
        if (spawnReason != CreatureSpawnEvent.SpawnReason.CUSTOM) {
            if (isAnimal && !world.getWorldCB().getAllowAnimals() || isMonster && !world.getWorldCB().getAllowMonsters() || isNpc && !world.getServer().getServer().isSpawningAnimals()) {
                entity.removed = true;
                return false;
            }
        }
        event = CraftEventFactory.callCreatureSpawnEvent((net.minecraft.entity.LivingEntity) entity, spawnReason);
    } else if (entity instanceof ItemEntity) {
        event = CraftEventFactory.callItemSpawnEvent((ItemEntity) entity);
    } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Projectile) {
        // Not all projectiles extend ThrowableEntity, so check for Bukkit interface instead
        event = CraftEventFactory.callProjectileLaunchEvent(entity);
    } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Vehicle) {
        event = CraftEventFactory.callVehicleCreateEvent(entity);
    // Spigot start
    } else if (entity instanceof ExperienceOrbEntity) {
        ExperienceOrbEntity xp = (ExperienceOrbEntity) entity;
        double radius = world.spigotConfig.expMerge;
        if (radius > 0) {
            List<Entity> entities = world.getEntities(entity, entity.getBoundingBox().inflate(radius, radius, radius));
            for (Entity e : entities) {
                if (e instanceof ExperienceOrbEntity) {
                    ExperienceOrbEntity loopItem = (ExperienceOrbEntity) e;
                    if (!loopItem.removed) {
                        xp.value += loopItem.value;
                        loopItem.remove();
                    }
                }
            }
        }
    // Spigot end
    } else if (!(entity instanceof ServerPlayerEntity)) {
        event = CraftEventFactory.callEntitySpawnEvent(entity);
    }
    if (event != null && (event.isCancelled() || entity.removed)) {
        Entity vehicle = entity.getVehicle();
        if (vehicle != null) {
            vehicle.removed = true;
        }
        for (Entity passenger : entity.getPassengers()) {
            passenger.removed = true;
        }
        entity.removed = true;
        return false;
    }
    return true;
}
Also used : SlimeEntity(net.minecraft.entity.monster.SlimeEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) LivingEntity(org.bukkit.entity.LivingEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) StriderEntity(net.minecraft.entity.passive.StriderEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) MobEntity(net.minecraft.entity.MobEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) Cancellable(org.bukkit.event.Cancellable) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) GhastEntity(net.minecraft.entity.monster.GhastEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) Vehicle(org.bukkit.entity.Vehicle) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) Projectile(org.bukkit.entity.Projectile) INPC(net.minecraft.entity.INPC)

Example 2 with GhastEntity

use of net.minecraft.entity.monster.GhastEntity in project LoliServer by Loli-Server.

the class CraftEventFactory method doEntityAddEventCalling.

public static boolean doEntityAddEventCalling(World world, Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
    if (entity == null)
        return false;
    Cancellable event = null;
    if (entity instanceof LivingEntity && !(entity instanceof ServerPlayerEntity)) {
        boolean isAnimal = entity instanceof AnimalEntity || entity instanceof WaterMobEntity || entity instanceof GolemEntity;
        boolean isMonster = entity instanceof MonsterEntity || entity instanceof GhastEntity || entity instanceof SlimeEntity;
        boolean isNpc = entity instanceof NPC;
        if (spawnReason != CreatureSpawnEvent.SpawnReason.CUSTOM) {
            if (isAnimal && !world.getWorld().getAllowAnimals() || isMonster && !world.getWorld().getAllowMonsters() || isNpc && !world.getServer().getServer().areNpcsEnabled()) {
                entity.removed = true;
                return false;
            }
        }
        event = CraftEventFactory.callCreatureSpawnEvent((LivingEntity) entity, spawnReason);
    } else if (entity instanceof ItemEntity) {
        event = CraftEventFactory.callItemSpawnEvent((ItemEntity) entity);
    } else if (entity.getBukkitEntity() instanceof Projectile) {
        // Not all projectiles extend EntityProjectile, so check for Bukkit interface instead
        event = CraftEventFactory.callProjectileLaunchEvent(entity);
    } else if (entity.getBukkitEntity() instanceof Vehicle) {
        event = CraftEventFactory.callVehicleCreateEvent(entity);
    } else if (entity.getBukkitEntity() instanceof LightningStrike) {
        LightningStrikeEvent.Cause cause = (spawnReason == CreatureSpawnEvent.SpawnReason.COMMAND ? LightningStrikeEvent.Cause.COMMAND : LightningStrikeEvent.Cause.UNKNOWN);
        event = CraftEventFactory.callLightningStrikeEvent((LightningStrike) entity.getBukkitEntity(), cause);
    } else // Spigot start
    if (entity instanceof ExperienceOrbEntity) {
        ExperienceOrbEntity xp = (ExperienceOrbEntity) entity;
        double radius = world.spigotConfig.expMerge;
        if (radius > 0) {
            List<Entity> entities = world.getEntities(entity, entity.getBoundingBox().inflate(radius, radius, radius));
            for (Entity e : entities) {
                if (e instanceof ExperienceOrbEntity) {
                    ExperienceOrbEntity loopItem = (ExperienceOrbEntity) e;
                    if (!loopItem.removed) {
                        xp.value += loopItem.value;
                        loopItem.remove();
                    }
                }
            }
        }
    // Spigot end
    } else if (!(entity instanceof ServerPlayerEntity)) {
        event = CraftEventFactory.callEntitySpawnEvent(entity);
    }
    if (event != null && (event.isCancelled() || entity.removed)) {
        Entity vehicle = entity.getVehicle();
        if (vehicle != null) {
            vehicle.removed = true;
        }
        for (Entity passenger : entity.getIndirectPassengers()) {
            passenger.removed = true;
        }
        entity.removed = true;
        return false;
    }
    return true;
}
Also used : SlimeEntity(net.minecraft.entity.monster.SlimeEntity) StriderEntity(net.minecraft.entity.passive.StriderEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) LivingEntity(net.minecraft.entity.LivingEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PiglinEntity(net.minecraft.entity.monster.piglin.PiglinEntity) MobEntity(net.minecraft.entity.MobEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) Cancellable(org.bukkit.event.Cancellable) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) LightningStrikeEvent(org.bukkit.event.weather.LightningStrikeEvent) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) LivingEntity(net.minecraft.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) ArrayList(java.util.ArrayList) List(java.util.List) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity)

Aggregations

AreaEffectCloudEntity (net.minecraft.entity.AreaEffectCloudEntity)2 Entity (net.minecraft.entity.Entity)2 MobEntity (net.minecraft.entity.MobEntity)2 EnderDragonEntity (net.minecraft.entity.boss.dragon.EnderDragonEntity)2 ExperienceOrbEntity (net.minecraft.entity.item.ExperienceOrbEntity)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 VillagerEntity (net.minecraft.entity.merchant.villager.VillagerEntity)2 AbstractRaiderEntity (net.minecraft.entity.monster.AbstractRaiderEntity)2 GhastEntity (net.minecraft.entity.monster.GhastEntity)2 MonsterEntity (net.minecraft.entity.monster.MonsterEntity)2 SlimeEntity (net.minecraft.entity.monster.SlimeEntity)2 SpellcastingIllagerEntity (net.minecraft.entity.monster.SpellcastingIllagerEntity)2 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)2 GolemEntity (net.minecraft.entity.passive.GolemEntity)2 StriderEntity (net.minecraft.entity.passive.StriderEntity)2 WaterMobEntity (net.minecraft.entity.passive.WaterMobEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 FireworkRocketEntity (net.minecraft.entity.projectile.FireworkRocketEntity)2 PotionEntity (net.minecraft.entity.projectile.PotionEntity)2