Search in sources :

Example 6 with RegionService

use of com.skelril.skree.service.RegionService in project Skree by Skelril.

the class RegionSelectCommand 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<Player> optPlayer = args.getOne("player");
    Optional<Location<World>> optLocation = args.getOne("location");
    Optional<Region> optRegion;
    if (optPlayer.isPresent()) {
        Player targPlayer = optPlayer.get();
        optRegion = service.get(targPlayer.getLocation());
        player.sendMessage(Text.of(TextColors.YELLOW, "Searching for ", targPlayer.getName(), "'s local region..."));
    } else if (optLocation.isPresent()) {
        optRegion = service.get(optLocation.get());
        player.sendMessage(Text.of(TextColors.YELLOW, "Searching for a region at the given location..."));
    } else {
        optRegion = service.get(player.getLocation());
        player.sendMessage(Text.of(TextColors.YELLOW, "Searching for your local region..."));
    }
    service.setSelectedRegion(player, optRegion.orElse(null));
    if (optRegion.isPresent()) {
        player.sendMessage(Text.of(TextColors.YELLOW, "Region found! View information with ", Text.of(TextColors.GREEN, TextActions.runCommand("/region info"), "/region info")));
    } else {
        player.sendMessage(Text.of(TextColors.YELLOW, "No region found, your region selection has been cleared"));
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) Location(org.spongepowered.api.world.Location)

Example 7 with RegionService

use of com.skelril.skree.service.RegionService in project Skree by Skelril.

the class RegionSetNameCommand 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();
    if (!ref.getMembers().contains(player.getUniqueId())) {
        player.sendMessage(Text.of(TextColors.RED, "You must be a member of the region to modify it!"));
        return CommandResult.empty();
    }
    String newName = args.<String>getOne("name").get();
    try {
        ref.setName(newName);
    } catch (IllegalArgumentException ex) {
        player.sendMessage(Text.of(TextColors.RED, "Invalid region name!"));
        return CommandResult.empty();
    }
    player.sendMessage(Text.of(TextColors.YELLOW, "Region name set to ", Text.of(TextColors.BLUE, newName.toUpperCase()), "."));
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService)

Example 8 with RegionService

use of com.skelril.skree.service.RegionService 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 9 with RegionService

use of com.skelril.skree.service.RegionService 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 10 with RegionService

use of com.skelril.skree.service.RegionService in project Skree by Skelril.

the class RegionAddMemberCommand 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();
    if (!ref.getMembers().contains(player.getUniqueId())) {
        player.sendMessage(Text.of(TextColors.RED, "You must be a member of the region to modify it!"));
        return CommandResult.empty();
    }
    List<UUID> newMembers = args.<User>getAll("player").stream().map(Identifiable::getUniqueId).filter(a -> !ref.getMembers().contains(a)).collect(Collectors.toList());
    ref.addMember(newMembers);
    player.sendMessage(Text.of(TextColors.YELLOW, "Added ", newMembers.size(), " players to the region."));
    return CommandResult.success();
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) GenericArguments.allOf(org.spongepowered.api.command.args.GenericArguments.allOf) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) UUID(java.util.UUID) 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) GenericArguments.user(org.spongepowered.api.command.args.GenericArguments.user) Player(org.spongepowered.api.entity.living.player.Player) TextColors(org.spongepowered.api.text.format.TextColors) Identifiable(org.spongepowered.api.util.Identifiable) Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) UUID(java.util.UUID) Identifiable(org.spongepowered.api.util.Identifiable)

Aggregations

RegionService (com.skelril.skree.service.RegionService)13 Region (com.skelril.skree.service.internal.region.Region)12 Player (org.spongepowered.api.entity.living.player.Player)7 Location (org.spongepowered.api.world.Location)6 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)5 Listener (org.spongepowered.api.event.Listener)5 RegionPoint (com.skelril.skree.service.internal.region.RegionPoint)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Sponge (org.spongepowered.api.Sponge)4 CommandException (org.spongepowered.api.command.CommandException)4 CommandResult (org.spongepowered.api.command.CommandResult)4 CommandSource (org.spongepowered.api.command.CommandSource)4 CommandContext (org.spongepowered.api.command.args.CommandContext)4 CommandExecutor (org.spongepowered.api.command.spec.CommandExecutor)4 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)4 Text (org.spongepowered.api.text.Text)4 TextColors (org.spongepowered.api.text.format.TextColors)4 UUID (java.util.UUID)2