Search in sources :

Example 1 with BlockRecord

use of com.skelril.skree.content.zone.global.cursedmine.restoration.BlockRecord 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)

Aggregations

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 ExperienceOrb (org.spongepowered.api.entity.ExperienceOrb)1 Listener (org.spongepowered.api.event.Listener)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1