Search in sources :

Example 6 with Home

use of io.github.nucleuspowered.nucleus.api.nucleusdata.Home in project Nucleus by NucleusPowered.

the class ListHomeCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // args.getOne(subject);
    User user = this.getUserFromArgs(User.class, src, player, args);
    Text header;
    boolean other = src instanceof User && !((User) src).getUniqueId().equals(user.getUniqueId());
    if (other && user.hasPermission(this.exempt)) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.listhome.exempt"));
    }
    List<Home> msw = homeHandler.getHomes(user);
    if (msw.isEmpty()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.nohomes"));
        return CommandResult.empty();
    }
    if (other) {
        header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.name", user.getName());
    } else {
        header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.normal");
    }
    List<Text> lt = msw.stream().sorted(Comparator.comparing(NamedLocation::getName)).map(x -> {
        Optional<Location<World>> olw = x.getLocation();
        if (!olw.isPresent()) {
            return Text.builder().append(Text.builder(x.getName()).color(TextColors.RED).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphoverinvalid", x.getName()))).build()).build();
        } else {
            final Location<World> lw = olw.get();
            return Text.builder().append(Text.builder(x.getName()).color(TextColors.GREEN).style(TextStyles.UNDERLINE).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphover", x.getName()))).onClick(TextActions.runCommand(other ? "/homeother " + user.getName() + " " + x.getName() : "/home " + x.getName())).build()).append(plugin.getMessageProvider().getTextMessageWithFormat("home.location", lw.getExtent().getName(), String.valueOf(lw.getBlockX()), String.valueOf(lw.getBlockY()), String.valueOf(lw.getBlockZ()))).build();
        }
    }).collect(Collectors.toList());
    PaginationList.Builder pb = Util.getPaginationBuilder(src).title(Text.of(TextColors.YELLOW, header)).padding(Text.of(TextColors.GREEN, "-")).contents(lt);
    pb.sendTo(src);
    return CommandResult.success();
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) HashMap(java.util.HashMap) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) PaginationList(org.spongepowered.api.service.pagination.PaginationList) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Home(io.github.nucleuspowered.nucleus.api.nucleusdata.Home) SelectorWrapperArgument(io.github.nucleuspowered.nucleus.argumentparsers.SelectorWrapperArgument) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) TextColors(org.spongepowered.api.text.format.TextColors) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) NicknameArgument(io.github.nucleuspowered.nucleus.argumentparsers.NicknameArgument) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) HomeHandler(io.github.nucleuspowered.nucleus.modules.home.handlers.HomeHandler) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Comparator(java.util.Comparator) User(org.spongepowered.api.entity.living.player.User) Optional(java.util.Optional) Text(org.spongepowered.api.text.Text) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World) PaginationList(org.spongepowered.api.service.pagination.PaginationList) Home(io.github.nucleuspowered.nucleus.api.nucleusdata.Home) Location(org.spongepowered.api.world.Location) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)

Aggregations

Home (io.github.nucleuspowered.nucleus.api.nucleusdata.Home)6 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)4 World (org.spongepowered.api.world.World)3 UseHomeEvent (io.github.nucleuspowered.nucleus.modules.home.events.UseHomeEvent)2 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 Util (io.github.nucleuspowered.nucleus.Util)1 NucleusException (io.github.nucleuspowered.nucleus.api.exceptions.NucleusException)1 NamedLocation (io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)1 NicknameArgument (io.github.nucleuspowered.nucleus.argumentparsers.NicknameArgument)1 SelectorWrapperArgument (io.github.nucleuspowered.nucleus.argumentparsers.SelectorWrapperArgument)1 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)1 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)1 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)1 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)1 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)1 PermissionInformation (io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation)1 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)1 HomeHandler (io.github.nucleuspowered.nucleus.modules.home.handlers.HomeHandler)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1