Search in sources :

Example 1 with RegionPoint

use of com.skelril.skree.service.internal.region.RegionPoint 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 RegionPoint

use of com.skelril.skree.service.internal.region.RegionPoint 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 3 with RegionPoint

use of com.skelril.skree.service.internal.region.RegionPoint 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 4 with RegionPoint

use of com.skelril.skree.service.internal.region.RegionPoint in project Skree by Skelril.

the class RegionListMarkersCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!(src instanceof Player)) {
        src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
        return CommandResult.empty();
    }
    Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
        return CommandResult.empty();
    }
    RegionService service = optService.get();
    Player player = (Player) src;
    Optional<Region> optRef = service.getSelectedRegion(player);
    if (!optRef.isPresent()) {
        player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
        return CommandResult.empty();
    }
    Region ref = optRef.get();
    PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
    List<RegionPoint> points = ref.getPoints();
    List<Text> result = ref.getFullPoints().stream().map(a -> Text.of((points.contains(a) ? TextColors.GREEN : TextColors.RED), a.getFloorX(), ", ", a.getFloorY(), ", ", a.getFloorZ())).collect(Collectors.toList());
    pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Region Markers")).padding(Text.of(" ")).sendTo(src);
    return CommandResult.success();
}
Also used : RegionPoint(com.skelril.skree.service.internal.region.RegionPoint) CommandResult(org.spongepowered.api.command.CommandResult) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Collectors(java.util.stream.Collectors) RegionService(com.skelril.skree.service.RegionService) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) List(java.util.List) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Region(com.skelril.skree.service.internal.region.Region) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) TextColors(org.spongepowered.api.text.format.TextColors) Player(org.spongepowered.api.entity.living.player.Player) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) RegionPoint(com.skelril.skree.service.internal.region.RegionPoint)

Aggregations

RegionService (com.skelril.skree.service.RegionService)4 Region (com.skelril.skree.service.internal.region.Region)4 RegionPoint (com.skelril.skree.service.internal.region.RegionPoint)4 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)3 Listener (org.spongepowered.api.event.Listener)3 Location (org.spongepowered.api.world.Location)3 Vector3d (com.flowpowered.math.vector.Vector3d)1 RegionErrorStatus (com.skelril.skree.service.internal.region.RegionErrorStatus)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Sponge (org.spongepowered.api.Sponge)1 CommandException (org.spongepowered.api.command.CommandException)1 CommandResult (org.spongepowered.api.command.CommandResult)1 CommandSource (org.spongepowered.api.command.CommandSource)1 CommandContext (org.spongepowered.api.command.args.CommandContext)1 CommandExecutor (org.spongepowered.api.command.spec.CommandExecutor)1 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)1 Player (org.spongepowered.api.entity.living.player.Player)1 PaginationService (org.spongepowered.api.service.pagination.PaginationService)1