use of io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory in project Nucleus by NucleusPowered.
the class ListWarpCommand method createMain.
private void createMain(final CommandSource src, final Map<WarpCategory, List<Warp>> warps) {
List<Text> lt = warps.keySet().stream().filter(Objects::nonNull).sorted(Comparator.comparing(WarpCategory::getId)).map(s -> {
Text.Builder t = Text.builder("> ").color(TextColors.GREEN).style(TextStyles.ITALIC).append(s.getDisplayName()).onClick(TextActions.executeCallback(source -> createSub(source, s, warps)));
s.getDescription().ifPresent(x -> t.append(Text.of(" - ")).append(Text.of(TextColors.RESET, TextStyles.NONE, x)));
return t.build();
}).collect(Collectors.toList());
// Uncategorised
if (warps.containsKey(null)) {
lt.add(Text.builder("> " + this.defaultName).color(TextColors.GREEN).style(TextStyles.ITALIC).onClick(TextActions.executeCallback(source -> createSub(source, null, warps))).build());
}
MessageProvider messageProvider = plugin.getMessageProvider();
Util.getPaginationBuilder(src).header(messageProvider.getTextMessageWithFormat("command.warps.list.headercategory")).title(messageProvider.getTextMessageWithFormat("command.warps.list.maincategory")).padding(Text.of(TextColors.GREEN, "-")).contents(lt).sendTo(src);
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory in project Nucleus by NucleusPowered.
the class ListWarpCommand method createSub.
private void createSub(final CommandSource src, @Nullable final WarpCategory category, final Map<WarpCategory, List<Warp>> warpDataList) {
final boolean econExists = plugin.getEconHelper().economyServiceExists();
Text name = category == null ? Text.of(this.defaultName) : category.getDisplayName();
List<Text> lt = warpDataList.get(category).stream().sorted(Comparator.comparing(Warp::getName)).map(s -> createWarp(s, s.getName(), econExists, defaultCost)).collect(Collectors.toList());
Util.getPaginationBuilder(src).title(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warps.list.category", name)).padding(Text.of(TextColors.GREEN, "-")).contents(lt).footer(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.list.back").toBuilder().onClick(TextActions.executeCallback(s -> createMain(s, warpDataList))).build()).sendTo(src);
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory in project Nucleus by NucleusPowered.
the class SetCategoryCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
String warpName = args.<Warp>getOne(warpKey).get().getName();
if (args.hasAny("r")) {
// Remove the category.
if (handler.setWarpCategory(warpName, null)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.removed", warpName));
return CommandResult.success();
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.noremove", warpName));
}
Optional<Tuple<String, Boolean>> categoryOp = args.getOne(categoryKey);
if (!categoryOp.isPresent()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.required"));
}
Tuple<String, Boolean> category = categoryOp.get();
if (!args.hasAny("n") && !category.getSecond()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.requirenew", category.getFirst()).toBuilder().onClick(TextActions.runCommand("/warp setcategory -n " + warpName + " " + category.getFirst())).build());
return CommandResult.empty();
}
// Add the category.
if (handler.setWarpCategory(warpName, category.getFirst())) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.added", category.getFirst(), warpName));
return CommandResult.success();
}
WarpCategory c = handler.getWarpCategoryOrDefault(category.getFirst());
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warp.category.couldnotadd", c.getDisplayName(), Text.of(warpName)));
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory in project Nucleus by NucleusPowered.
the class WarpGeneralDataModule method getWarpCategory.
public Optional<WarpCategory> getWarpCategory(String category) {
Preconditions.checkArgument(category != null && !category.isEmpty());
if (warps.values().stream().noneMatch(x -> x.getCategory().orElse("").equalsIgnoreCase(category))) {
return Optional.empty();
}
WarpCategoryDataNode w = warpCategories.get(category);
if (w == null) {
w = new WarpCategoryDataNode();
updateOrSetWarpCategory(category.toLowerCase(), null, null);
}
return Optional.of(new WarpCategoryData(category, w.getDisplayName().map(TextSerializers.JSON::deserialize).orElse(Text.of(category)), w.getDescription().map(TextSerializers.JSON::deserialize).orElse(null), () -> getWarps().values().stream().filter(x -> x.getCategory().map(y -> y.equals(category)).orElse(false)).collect(Collectors.toList())));
}
Aggregations