Search in sources :

Example 1 with RegionService

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

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

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

the class RegionRemMemberCommand 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> oldMembers = args.<User>getAll("player").stream().map(Identifiable::getUniqueId).filter(a -> ref.getMembers().contains(a)).collect(Collectors.toList());
    ref.remMember(oldMembers);
    player.sendMessage(Text.of(TextColors.YELLOW, "Removed ", oldMembers.size(), " players from 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)

Example 4 with RegionService

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

the class RegionCleanupCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    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();
    int removedCount = service.cleanup();
    src.sendMessage(Text.of(TextColors.YELLOW, removedCount, " region components invalidated."));
    return CommandResult.success();
}
Also used : RegionService(com.skelril.skree.service.RegionService)

Example 5 with RegionService

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

the class RegionInfoCommand 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();
    }
    DecimalFormat countFormat = new DecimalFormat("#,###");
    Region ref = optRef.get();
    player.sendMessage(Text.of(TextColors.GOLD, "Region information for: ", (ref.isActive() ? TextColors.BLUE : TextColors.RED), ref.getName().toUpperCase()));
    player.sendMessage(Text.of(countFormat.format(ref.getPowerLevel()), TextColors.YELLOW, " power cores"));
    player.sendMessage(Text.of(countFormat.format(ref.getArea()), TextColors.YELLOW, " block area"));
    player.sendMessage(Text.of(countFormat.format(ref.getMaximumArea()), TextColors.YELLOW, " block maximum area"));
    player.sendMessage(Text.of(TextActions.runCommand("/region listmembers"), TextActions.showText(Text.of("List the region's members")), countFormat.format(ref.getMembers().size()), TextColors.YELLOW, " members"));
    player.sendMessage(Text.of(TextActions.runCommand("/region listmarkers"), TextActions.showText(Text.of("List the region's marker block positions")), countFormat.format(ref.getPoints().size()), TextColors.YELLOW, " active markers"));
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) DecimalFormat(java.text.DecimalFormat) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService)

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