Search in sources :

Example 1 with WarpCategory

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);
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) WarpHandler(io.github.nucleuspowered.nucleus.modules.warp.handlers.WarpHandler) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory) WarpConfigAdapter(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter) 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) Nullable(javax.annotation.Nullable) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) WarpConfig(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig) Set(java.util.Set) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) Objects(java.util.Objects) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Comparator(java.util.Comparator) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Text(org.spongepowered.api.text.Text)

Example 2 with WarpCategory

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);
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) WarpHandler(io.github.nucleuspowered.nucleus.modules.warp.handlers.WarpHandler) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory) WarpConfigAdapter(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter) 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) Nullable(javax.annotation.Nullable) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) WarpConfig(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig) Set(java.util.Set) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) Objects(java.util.Objects) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Comparator(java.util.Comparator) Text(org.spongepowered.api.text.Text)

Example 3 with WarpCategory

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)));
}
Also used : Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Tuple(org.spongepowered.api.util.Tuple) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory)

Example 4 with WarpCategory

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())));
}
Also used : WarpCategoryDataNode(io.github.nucleuspowered.nucleus.configurate.datatypes.WarpCategoryDataNode) LocationDataModule(io.github.nucleuspowered.nucleus.dataservices.modular.LocationDataModule) Location(org.spongepowered.api.world.Location) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Vector3d(com.flowpowered.math.vector.Vector3d) WarpCategoryDataNode(io.github.nucleuspowered.nucleus.configurate.datatypes.WarpCategoryDataNode) UUID(java.util.UUID) LocationData(io.github.nucleuspowered.nucleus.internal.LocationData) Maps(com.google.common.collect.Maps) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) WarpNode(io.github.nucleuspowered.nucleus.configurate.datatypes.WarpNode) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) Text(org.spongepowered.api.text.Text) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory) World(org.spongepowered.api.world.World) Map(java.util.Map) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Util(io.github.nucleuspowered.nucleus.Util) DataKey(io.github.nucleuspowered.nucleus.dataservices.modular.DataKey) Nullable(javax.annotation.Nullable) ModularGeneralService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularGeneralService) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers)

Aggregations

Warp (io.github.nucleuspowered.nucleus.api.nucleusdata.Warp)4 WarpCategory (io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory)4 Util (io.github.nucleuspowered.nucleus.Util)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Nullable (javax.annotation.Nullable)3 Text (org.spongepowered.api.text.Text)3 Location (org.spongepowered.api.world.Location)3 World (org.spongepowered.api.world.World)3 PermissionRegistry (io.github.nucleuspowered.nucleus.internal.PermissionRegistry)2 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)2 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)2 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)2 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)2 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)2 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)2 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)2 WarpConfig (io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig)2 WarpConfigAdapter (io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter)2