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();
}
Aggregations