Search in sources :

Example 1 with ExperienceOrb

use of org.spongepowered.api.entity.ExperienceOrb in project Skree by Skelril.

the class CursedMineListener method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Player player) {
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    CursedMineInstance inst = optInst.get();
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        event.setCancelled(true);
        return;
    }
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        BlockType originalType = block.getOriginal().getState().getType();
        if (cursedOres.contains(originalType)) {
            // we were having some multi-firing problems
            if (inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()))) {
                /*if (Probability.getChance(3000)) {
                        ChatUtil.send(player, "You feel as though a spirit is trying to tell you something...");
                        player.getInventory().addItem(BookUtil.Lore.Areas.theGreatMine());
                    }*/
                ExperienceOrb xpOrb = (ExperienceOrb) player.getWorld().createEntity(EntityTypes.EXPERIENCE_ORB, block.getOriginal().getLocation().get().getPosition());
                xpOrb.offer(Keys.CONTAINED_EXPERIENCE, (70 - player.getLocation().getBlockY()) / 2);
                inst.eatFood(player);
                inst.poison(player, 6);
                inst.ghost(player, originalType);
            }
        } else if (stealableFluids.contains(originalType)) {
            inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()));
        } else {
            block.setCustom(block.getOriginal());
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockRecord(com.skelril.skree.content.zone.global.cursedmine.restoration.BlockRecord) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 2 with ExperienceOrb

use of org.spongepowered.api.entity.ExperienceOrb in project ClearMob by axle2005.

the class EntityLimiter method handle.

@Listener(beforeModifications = true)
public void handle(SpawnEntityEvent event) throws Exception {
    List<Entity> entity = event.getEntities();
    Integer count = 0;
    Integer xpcount = 0;
    for (World w : plugin.getWorlds()) {
        for (Entity e : w.getEntities()) {
            if (e instanceof Monster && !(e instanceof Boss)) {
                count++;
            }
            if (e instanceof ExperienceOrb) {
                xpcount++;
            }
        }
    }
    for (int i = 0; i < entity.size(); i++) {
        if (entity.get(i) instanceof Monster && (count > plugin.getMobLimit()) && !(entity.get(i) instanceof Boss)) {
            event.setCancelled(true);
        }
        if ((entity.get(i) instanceof ExperienceOrb && entity.get(i).getNearbyEntities(10).size() > 20)) {
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Boss(org.spongepowered.api.entity.living.monster.Boss) Monster(org.spongepowered.api.entity.living.monster.Monster) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 3 with ExperienceOrb

use of org.spongepowered.api.entity.ExperienceOrb in project ClearMob by axle2005.

the class ClearEntity method run.

public static void run(ClearMob plugin, EntityType tile, Collection<World> worlds, CommandSource src) {
    int removedentities = 0;
    Collection<Entity> e = new ArrayList<Entity>();
    for (World world : worlds) {
        for (Entity entity : world.getEntities()) {
            e.add(entity);
        }
    }
    if (!e.isEmpty()) {
        for (Entity entity : e) {
            if (!(entity instanceof Item) && !(entity instanceof Player) && !(entity instanceof ExperienceOrb)) {
                if ((entity.getType().equals(tile))) {
                    entity.getLocation().removeBlock(Cause.source(Sponge.getPluginManager().fromInstance(plugin).get()).build());
                    removedentities++;
                }
            }
        }
    }
    feedback(plugin, src, removedentities);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Item(org.spongepowered.api.entity.Item) Player(org.spongepowered.api.entity.living.player.Player) ArrayList(java.util.ArrayList) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) World(org.spongepowered.api.world.World)

Example 4 with ExperienceOrb

use of org.spongepowered.api.entity.ExperienceOrb in project ClearMob by axle2005.

the class ClearXP method run.

public static int run(ClearMob plugin, Collection<World> worlds, CommandSource src) {
    int removedentities = 0;
    Collection<Entity> e = new ArrayList<Entity>();
    for (World world : worlds) {
        for (Entity entity : world.getEntities()) {
            e.add(entity);
        }
    }
    if (!e.isEmpty()) {
        for (Entity entity : e) {
            if ((entity instanceof ExperienceOrb)) {
                entity.remove();
                removedentities++;
            }
        }
    }
    feedback(plugin, src, removedentities);
    return removedentities;
}
Also used : Entity(org.spongepowered.api.entity.Entity) ArrayList(java.util.ArrayList) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) World(org.spongepowered.api.world.World)

Aggregations

ExperienceOrb (org.spongepowered.api.entity.ExperienceOrb)4 Entity (org.spongepowered.api.entity.Entity)3 World (org.spongepowered.api.world.World)3 ArrayList (java.util.ArrayList)2 Listener (org.spongepowered.api.event.Listener)2 BlockRecord (com.skelril.skree.content.zone.global.cursedmine.restoration.BlockRecord)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 BlockType (org.spongepowered.api.block.BlockType)1 Item (org.spongepowered.api.entity.Item)1 Boss (org.spongepowered.api.entity.living.monster.Boss)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Player (org.spongepowered.api.entity.living.player.Player)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1