Search in sources :

Example 66 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.

the class GoldRushListener method onPlayerInteractEvent.

@Listener(order = Order.FIRST)
public void onPlayerInteractEvent(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
    Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    GoldRushInstance inst = optInst.get();
    BlockSnapshot snapshot = event.getTargetBlock();
    BlockState state = snapshot.getState();
    if (!snapshot.getLocation().isPresent()) {
        return;
    }
    Location<World> targetBlock = snapshot.getLocation().get();
    if (state.getType() == BlockTypes.WALL_SIGN && inst.getLockLocations().contains(targetBlock)) {
        Optional<TileEntity> optTileEnt = snapshot.getLocation().get().getTileEntity();
        if (!optTileEnt.isPresent()) {
            return;
        }
        TileEntity tileEntity = optTileEnt.get();
        Optional<List<Text>> optTexts = tileEntity.get(Keys.SIGN_LINES);
        if (!optTexts.isPresent()) {
            return;
        }
        List<Text> texts = optTexts.get();
        boolean unlocked = false;
        String text = texts.get(1).toPlain().toLowerCase();
        NonNullList<ItemStack> itemStacks = tf(player).inventory.mainInventory;
        for (int i = 0; i < itemStacks.size(); ++i) {
            ItemStack is = itemStacks.get(i);
            if (is == ItemStack.EMPTY || is.getItem() != CustomItemTypes.GOLD_RUSH_KEY) {
                continue;
            }
            if (text.contains("blue")) {
                if (is.getItemDamage() != 1) {
                    continue;
                }
            } else if (text.contains("red")) {
                if (is.getItemDamage() != 0) {
                    continue;
                }
            } else {
                continue;
            }
            unlocked = true;
            itemStacks.set(i, ItemStack.EMPTY);
            break;
        }
        if (unlocked) {
            tf(player).inventoryContainer.detectAndSendChanges();
            texts.set(2, Text.of("Locked"));
            texts.set(3, Text.of("- Unlocked -"));
            tileEntity.offer(Keys.SIGN_LINES, texts);
        }
    } else if (state.getType() == BlockTypes.LEVER) {
        Task.builder().execute(() -> {
            if (inst.checkLevers()) {
                inst.completeGame();
            }
        }).delayTicks(1).submit(SkreePlugin.inst());
    } else if (targetBlock.equals(inst.getRewardChestLoc()) && inst.isComplete()) {
        event.setUseItemResult(Tristate.FALSE);
        event.setUseBlockResult(Tristate.FALSE);
        player.sendMessage(Text.of(TextColors.YELLOW, "You have successfully robbed the bank!"));
        inst.payPlayer(player);
    } else if (!inst.isLocked()) {
        if (state.getType() == BlockTypes.STONE_BUTTON) {
            inst.tryToStart();
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 67 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.

the class JungleRaidEffectListener method onBlockBurn.

@Listener
public void onBlockBurn(ChangeBlockEvent event) {
    if (event.getCause().root() instanceof Player) {
        return;
    }
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockType finalType = transaction.getFinal().getState().getType();
        if (finalType != BlockTypes.FIRE) {
            continue;
        }
        Optional<JungleRaidInstance> optInst = manager.getApplicableZone(transaction.getOriginal().getLocation().get());
        if (optInst.isPresent()) {
            JungleRaidInstance inst = optInst.get();
            if (inst.isFlagEnabled(JungleRaidFlag.NO_FIRE_SPREAD)) {
                event.setCancelled(true);
            }
            break;
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Example 68 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.

the class CursedMineListener method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First 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 69 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.

the class CursedMineListener method onBlockPlace.

@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player) {
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockType originalType = transaction.getFinal().getState().getType();
        BlockType finalType = transaction.getFinal().getState().getType();
        if (isRedstoneTransition(originalType, finalType)) {
            continue;
        }
        event.setCancelled(true);
        break;
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Example 70 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.

the class CursedMineListener method onPlayerInteract.

@Listener
public void onPlayerInteract(ChangeBlockEvent event) {
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        BlockSnapshot snapshot = block.getOriginal();
        Optional<CursedMineInstance> optInst = manager.getApplicableZone(snapshot);
        if (optInst.isPresent() && triggerBlocks.contains(snapshot.getState().getType())) {
            optInst.get().activatePumps();
            break;
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)150 World (org.spongepowered.api.world.World)67 Listener (org.spongepowered.api.event.Listener)66 Location (org.spongepowered.api.world.Location)26 BlockState (org.spongepowered.api.block.BlockState)22 Entity (org.spongepowered.api.entity.Entity)21 BlockPos (net.minecraft.util.math.BlockPos)20 CauseStackManager (org.spongepowered.api.event.CauseStackManager)19 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)18 IBlockState (net.minecraft.block.state.IBlockState)18 Transaction (org.spongepowered.api.data.Transaction)18 BlockType (org.spongepowered.api.block.BlockType)15 Player (org.spongepowered.api.entity.living.player.Player)15 Direction (org.spongepowered.api.util.Direction)15 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)14 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)14 Vector3d (com.flowpowered.math.vector.Vector3d)13 ArrayList (java.util.ArrayList)13 User (org.spongepowered.api.entity.living.player.User)11 ItemStack (org.spongepowered.api.item.inventory.ItemStack)11