Search in sources :

Example 1 with Wither

use of org.spongepowered.api.entity.living.monster.Wither in project Skree by Skelril.

the class WildernessWorldWrapper method onEntityDeath.

@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
    Entity entity = event.getTargetEntity();
    Location<World> loc = entity.getLocation();
    Optional<Integer> optLevel = getLevel(loc);
    if (!optLevel.isPresent()) {
        return;
    }
    int level = optLevel.get();
    if (entity instanceof Monster) {
        DropTable dropTable;
        if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
            dropTable = netherMobDropTable;
        } else {
            dropTable = commonDropTable;
        }
        Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
        if (optDamageSource.isPresent()) {
            Entity srcEntity;
            if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
                srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
            } else {
                srcEntity = optDamageSource.get().getSource();
            }
            int dropTier = level;
            if (srcEntity instanceof Player) {
                Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
                if (optHeldItem.isPresent()) {
                    Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
                    if (optLooting.isPresent()) {
                        dropTier += optLooting.get().getLevel();
                    }
                }
                dropTier = getDropTier(dropTier);
                Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
                int times = 1;
                Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
                if (optService.isPresent()) {
                    ModifierService service = optService.get();
                    if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
                        times *= 2;
                    }
                }
                ItemDropper dropper = new ItemDropper(loc);
                for (int i = 0; i < times; ++i) {
                    dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
                }
                Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
                optHighScores.ifPresent(highScoreService -> highScoreService.update((Player) srcEntity, ScoreTypes.WILDERNESS_MOB_KILLS, 1));
            }
        }
        if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
            entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
        }
    }
    if (entity instanceof Player) {
        Player player = (Player) entity;
        GRAVE_STONE.createGraveFromDeath(player);
        Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
        optHighScores.ifPresent(highScoreService -> highScoreService.update(player, ScoreTypes.WILDERNESS_DEATHS, 1));
    }
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Player(org.spongepowered.api.entity.living.player.Player) ItemDropper(com.skelril.nitro.item.ItemDropper) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) DropTable(com.skelril.nitro.droptable.DropTable) MasterDropTable(com.skelril.nitro.droptable.MasterDropTable) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) HighScoreService(com.skelril.skree.service.HighScoreService) WanderingBoss(com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss) Boss(org.spongepowered.api.entity.living.monster.Boss) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Monster(org.spongepowered.api.entity.living.monster.Monster) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 2 with Wither

use of org.spongepowered.api.entity.living.monster.Wither in project RedProtect by FabioZumbi12.

the class RPEntityListener method onCreatureSpawn.

@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {
    for (Entity e : event.getEntities()) {
        if (e == null || e.getType() == null) {
            continue;
        }
        if (!(e instanceof Living)) {
            continue;
        }
        Optional<SpawnTypes> cause = event.getCause().first(SpawnTypes.class);
        RedProtect.get().logger.debug("entity", "SpawnCause: " + (cause.map(Object::toString).orElse(" null")));
        if (e instanceof Wither && cause.isPresent() && cause.get().equals(SpawnTypes.PLACEMENT)) {
            Region r = RedProtect.get().rm.getTopRegion(e.getLocation());
            if (r != null && !r.canSpawnWhiter()) {
                event.isCancelled();
                return;
            }
        }
        if (e instanceof Monster) {
            Location<World> l = e.getLocation();
            Region r = RedProtect.get().rm.getTopRegion(l);
            if (r != null && !r.canSpawnMonsters()) {
                RedProtect.get().logger.debug("entity", "Cancelled spawn of monster " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
        }
        if (e instanceof Animal || e instanceof Golem || e instanceof Ambient || e instanceof Aquatic) {
            Location<World> l = e.getLocation();
            Region r = RedProtect.get().rm.getTopRegion(l);
            if (r != null && !r.canSpawnPassives()) {
                RedProtect.get().logger.debug("entity", "Cancelled spawn of animal " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
        }
        RedProtect.get().logger.debug("entity", "RPEntityListener - Spawn mob " + e.getType().getName());
    }
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Entity(org.spongepowered.api.entity.Entity) Living(org.spongepowered.api.entity.living.Living) World(org.spongepowered.api.world.World) Golem(org.spongepowered.api.entity.living.golem.Golem) Ambient(org.spongepowered.api.entity.living.Ambient) Aquatic(org.spongepowered.api.entity.living.Aquatic) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) Listener(org.spongepowered.api.event.Listener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Example 3 with Wither

use of org.spongepowered.api.entity.living.monster.Wither in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onCreatureSpawn.

@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {
    for (Entity e : event.getEntities()) {
        if (e == null || RedProtect.get().rm.getTopRegion(e.getLocation()) != null) {
            continue;
        }
        if (e instanceof Wither && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-wither")) {
            RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Wither " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        if (e instanceof Monster && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-monsters")) {
            RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Monster " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        if ((e instanceof Animal || e instanceof Villager || e instanceof Ambient || e instanceof Golem) && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-passives")) {
            RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Animal " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        RedProtect.get().logger.debug("spawn", "RPGlobalListener - Spawn mob " + e.getType().getName());
    }
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Golem(org.spongepowered.api.entity.living.golem.Golem) Entity(org.spongepowered.api.entity.Entity) Ambient(org.spongepowered.api.entity.living.Ambient) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Villager(org.spongepowered.api.entity.living.Villager) Listener(org.spongepowered.api.event.Listener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Aggregations

Monster (org.spongepowered.api.entity.living.monster.Monster)3 Wither (org.spongepowered.api.entity.living.monster.Wither)3 Listener (org.spongepowered.api.event.Listener)3 Entity (org.spongepowered.api.entity.Entity)2 Ambient (org.spongepowered.api.entity.living.Ambient)2 Animal (org.spongepowered.api.entity.living.animal.Animal)2 Golem (org.spongepowered.api.entity.living.golem.Golem)2 IsCancelled (org.spongepowered.api.event.filter.IsCancelled)2 World (org.spongepowered.api.world.World)2 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)1 DropTable (com.skelril.nitro.droptable.DropTable)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 ItemDropper (com.skelril.nitro.item.ItemDropper)1 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 WanderingBoss (com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss)1 HighScoreService (com.skelril.skree.service.HighScoreService)1 ModifierService (com.skelril.skree.service.ModifierService)1 ItemEnchantment (org.spongepowered.api.data.meta.ItemEnchantment)1 Aquatic (org.spongepowered.api.entity.living.Aquatic)1 Living (org.spongepowered.api.entity.living.Living)1