Search in sources :

Example 11 with RegionService

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

Example 12 with RegionService

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

the class RegionListMembersCommand 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();
    UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
    PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
    List<Text> result = ref.getMembers().stream().map(userService::get).filter(Optional::isPresent).map(Optional::get).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).map(a -> Text.of((a.isOnline() ? TextColors.GREEN : TextColors.RED), a.getName())).collect(Collectors.toList());
    pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Region Members")).padding(Text.of(" ")).sendTo(src);
    return CommandResult.success();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) 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) UserStorageService(org.spongepowered.api.service.user.UserStorageService) 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) Optional(java.util.Optional) 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)

Example 13 with RegionService

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

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