Search in sources :

Example 66 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class RegionMarker method onBlockPlace.

@Listener
public void onBlockPlace(ChangeBlockEvent.Place 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.getFinal().getState().getType() != this) {
            continue;
        }
        Optional<Location<World>> optLoc = block.getFinal().getLocation();
        if (optLoc.isPresent()) {
            Optional<Region> optRef = service.getSelectedRegion(player);
            if (optRef.isPresent()) {
                Location<World> loc = optLoc.get();
                Region ref = optRef.get();
                if (ref.getWorldName().equals(loc.getExtent().getName())) {
                    if (ref.isMember(player)) {
                        RegionErrorStatus status = ref.addPoint(new RegionPoint(loc.getPosition()));
                        if (status == RegionErrorStatus.NONE) {
                            player.sendMessage(Text.of(TextColors.YELLOW, "Region marker added!"));
                            continue;
                        } else if (status == RegionErrorStatus.INTERSECT) {
                            player.sendMessage(Text.of(TextColors.RED, "No two regions can occupy the same space!"));
                        } else if (status == RegionErrorStatus.REGION_TOO_LARGE) {
                            player.sendMessage(Text.of(TextColors.RED, "You do not have enough power to expand your region!"));
                        }
                    }
                }
            }
        }
        block.setValid(false);
    }
}
Also used : RegionErrorStatus(com.skelril.skree.service.internal.region.RegionErrorStatus) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) RegionPoint(com.skelril.skree.service.internal.region.RegionPoint) Listener(org.spongepowered.api.event.Listener)

Example 67 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class RegionMaster method onBlockPlace.

@Listener
public void onBlockPlace(ChangeBlockEvent.Place 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.getFinal().getState().getType() != this) {
            continue;
        }
        Optional<Location<World>> optLoc = block.getFinal().getLocation();
        if (optLoc.isPresent()) {
            Optional<Region> optOriginRef = service.getSelectedRegion(player);
            Optional<Region> optRef = service.getOrCreate(optLoc.get(), player);
            if (optRef.isPresent()) {
                Region ref = optRef.get();
                Vector3d masterBlock = ref.getMasterBlock();
                Vector3d blockPos = optLoc.get().getPosition();
                // Determine if this is a new region or not
                if (!masterBlock.equals(blockPos)) {
                    if (blockPos.equals(recentlyClicked.get(player))) {
                        // Update the master block
                        ref.setMasterBlock(new RegionPoint(blockPos));
                        // Delete the existing master block
                        optLoc.get().getExtent().setBlockType(masterBlock.toInt(), BlockTypes.AIR, BlockChangeFlag.NONE, Cause.source(SkreePlugin.container()).build());
                        player.sendMessage(Text.of(TextColors.YELLOW, "Master block moved."));
                    } else {
                        recentlyClicked.put(player, blockPos);
                        block.setValid(false);
                        player.sendMessage(Text.of(TextColors.YELLOW, "Place the master block again to move this region's master block."));
                    }
                }
                service.setSelectedRegion(player, ref);
                if (!ref.equals(optOriginRef.orElse(null))) {
                    player.sendMessage(Text.of(TextColors.YELLOW, "Active region set!"));
                }
            }
        }
    }
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) 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 68 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class RegionMaster method onBlockInteract.

@Listener
public void onBlockInteract(InteractBlockEvent.Primary event, @Root Player player) {
    BlockSnapshot targetBlock = event.getTargetBlock();
    if (targetBlock.getState().getType() != this) {
        return;
    }
    Optional<Location<World>> optLoc = targetBlock.getLocation();
    if (!optLoc.isPresent()) {
        return;
    }
    Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
    if (!optService.isPresent()) {
        return;
    }
    RegionService service = optService.get();
    Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
    if (optRef.isPresent()) {
        Region ref = optRef.get();
        service.setSelectedRegion(player, ref);
        player.sendMessage(Text.of(TextColors.YELLOW, "Region selected!"));
    }
}
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 69 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class FocusTeleporter method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<org.spongepowered.api.item.inventory.ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    org.spongepowered.api.item.inventory.ItemStack held = optHeldItem.get();
    if (held.getItem() != this) {
        return;
    }
    Optional<Location<World>> optDestination = getDestination(held);
    if (!optDestination.isPresent()) {
        return;
    }
    Inventory result = player.getInventory().query((ItemType) Sponge.getRegistry().getType(ItemType.class, "skree:ender_focus").get());
    if (result.size() > 0) {
        Task.builder().execute(() -> {
            result.poll(1);
            player.setLocation(optDestination.get());
        }).delayTicks(1).submit(SkreePlugin.inst());
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : ItemType(org.spongepowered.api.item.ItemType) ItemStack(net.minecraft.item.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 70 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class BrokenGlass method dropBrokenGlass.

private void dropBrokenGlass(Transaction<BlockSnapshot> block, int variant) {
    Optional<Location<World>> optOrigin = block.getOriginal().getLocation();
    if (!optOrigin.isPresent()) {
        return;
    }
    new ItemDropper(optOrigin.get()).dropStacks(Collections.singleton(tf(new ItemStack(this, 1, variant))), SpawnTypes.DROPPED_ITEM);
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ItemStack(net.minecraft.item.ItemStack) Location(org.spongepowered.api.world.Location)

Aggregations

Location (org.spongepowered.api.world.Location)166 World (org.spongepowered.api.world.World)96 Listener (org.spongepowered.api.event.Listener)44 Player (org.spongepowered.api.entity.living.player.Player)40 Vector3d (com.flowpowered.math.vector.Vector3d)38 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)32 Vector3i (com.flowpowered.math.vector.Vector3i)31 Optional (java.util.Optional)28 Entity (org.spongepowered.api.entity.Entity)27 BlockType (org.spongepowered.api.block.BlockType)24 BlockState (org.spongepowered.api.block.BlockState)23 ItemStack (org.spongepowered.api.item.inventory.ItemStack)23 Direction (org.spongepowered.api.util.Direction)21 ArrayList (java.util.ArrayList)20 Keys (org.spongepowered.api.data.key.Keys)20 List (java.util.List)19 Text (org.spongepowered.api.text.Text)19 BlockPos (net.minecraft.util.math.BlockPos)18 Sponge (org.spongepowered.api.Sponge)15 Map (java.util.Map)14