Search in sources :

Example 1 with BlockSnapshot

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

the class RegionMarker method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
    Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
    if (!optService.isPresent()) {
        return;
    }
    RegionService service = optService.get();
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        if (!block.isValid()) {
            continue;
        }
        if (block.getOriginal().getState().getType() != this) {
            continue;
        }
        Optional<Location<World>> optLoc = block.getOriginal().getLocation();
        if (optLoc.isPresent()) {
            Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
            if (optRef.isPresent()) {
                Region ref = optRef.get();
                if (ref.isMember(player)) {
                    ref.remPoint(new RegionPoint(optLoc.get().getPosition()));
                    player.sendMessage(Text.of(TextColors.YELLOW, "Region marker deleted!"));
                }
            }
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) Location(org.spongepowered.api.world.Location) RegionPoint(com.skelril.skree.service.internal.region.RegionPoint) Listener(org.spongepowered.api.event.Listener)

Example 2 with BlockSnapshot

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

the class RegionMaster method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
    Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
    if (!optService.isPresent()) {
        return;
    }
    RegionService service = optService.get();
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        if (!block.isValid()) {
            continue;
        }
        if (block.getOriginal().getState().getType() != this) {
            continue;
        }
        Optional<Location<World>> optLoc = block.getOriginal().getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
        if (!optRef.isPresent()) {
            continue;
        }
        Region ref = optRef.get();
        if (!ref.getFullPoints().isEmpty()) {
            block.setValid(false);
            player.sendMessage(Text.of(TextColors.RED, "You must first delete all markers!"));
        } else {
            service.rem(optLoc.get());
            player.sendMessage(Text.of(TextColors.YELLOW, "Region deleted!"));
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 3 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 4 with BlockSnapshot

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

the class CustomTerragu method process.

public void process(ChangeBlockEvent.Break event) {
    if (event.getTransactions().size() > 1) {
        return;
    }
    Optional<Player> optPlayer = event.getCause().first(Player.class);
    if (optPlayer.isPresent()) {
        Player player = optPlayer.get();
        Optional<Direction> optClickedDir = Optional.ofNullable(clickMap.get(player));
        Optional<org.spongepowered.api.item.inventory.ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
        if (optStack.isPresent() && optClickedDir.isPresent()) {
            if (optStack.get().getItem() == this) {
                ItemStack stack = tf(optStack.get());
                for (Transaction<BlockSnapshot> snapshot : event.getTransactions()) {
                    if (!snapshot.getOriginal().getLocation().isPresent()) {
                        return;
                    }
                    int maxDist = getMaxEditDist(stack);
                    int dmg = destroyLine(player, optClickedDir.get(), maxDist - 1, snapshot.getOriginal());
                    stack.damageItem(dmg, tf(player));
                    player.setItemInHand(HandTypes.MAIN_HAND, tf(stack));
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemStack(net.minecraft.item.ItemStack) Direction(org.spongepowered.api.util.Direction)

Example 5 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)144 World (org.spongepowered.api.world.World)64 Listener (org.spongepowered.api.event.Listener)61 Location (org.spongepowered.api.world.Location)27 BlockState (org.spongepowered.api.block.BlockState)21 BlockPos (net.minecraft.util.math.BlockPos)20 Entity (org.spongepowered.api.entity.Entity)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)17 BlockType (org.spongepowered.api.block.BlockType)15 Direction (org.spongepowered.api.util.Direction)15 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)14 Vector3d (com.flowpowered.math.vector.Vector3d)13 ArrayList (java.util.ArrayList)13 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)13 Player (org.spongepowered.api.entity.living.player.Player)12 User (org.spongepowered.api.entity.living.player.User)11 LocatableBlock (org.spongepowered.api.world.LocatableBlock)11