Search in sources :

Example 1 with Identifiable

use of org.spongepowered.api.util.Identifiable 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 2 with Identifiable

use of org.spongepowered.api.util.Identifiable 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)2 Region (com.skelril.skree.service.internal.region.Region)2 List (java.util.List)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Sponge (org.spongepowered.api.Sponge)2 CommandException (org.spongepowered.api.command.CommandException)2 CommandResult (org.spongepowered.api.command.CommandResult)2 CommandSource (org.spongepowered.api.command.CommandSource)2 CommandContext (org.spongepowered.api.command.args.CommandContext)2 GenericArguments.allOf (org.spongepowered.api.command.args.GenericArguments.allOf)2 GenericArguments.user (org.spongepowered.api.command.args.GenericArguments.user)2 CommandExecutor (org.spongepowered.api.command.spec.CommandExecutor)2 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)2 Player (org.spongepowered.api.entity.living.player.Player)2 User (org.spongepowered.api.entity.living.player.User)2 Text (org.spongepowered.api.text.Text)2 TextColors (org.spongepowered.api.text.format.TextColors)2 Identifiable (org.spongepowered.api.util.Identifiable)2