Search in sources :

Example 1 with ArgumentBuilder

use of com.mojang.brigadier.builder.ArgumentBuilder in project MinecraftForge by MinecraftForge.

the class DimensionsCommand method register.

static ArgumentBuilder<CommandSourceStack, ?> register() {
    return Commands.literal("dimensions").requires(// permission
    cs -> cs.hasPermission(0)).executes(ctx -> {
        ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.dimensions.list"), true);
        final Registry<DimensionType> reg = ctx.getSource().registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
        Map<ResourceLocation, List<ResourceLocation>> types = new HashMap<>();
        for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) {
            types.computeIfAbsent(reg.getKey(dim.dimensionType()), k -> new ArrayList<>()).add(dim.dimension().location());
        }
        types.keySet().stream().sorted().forEach(key -> {
            ctx.getSource().sendSuccess(new TextComponent(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
        });
        return 0;
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) CommandSourceStack(net.minecraft.commands.CommandSourceStack) Commands(net.minecraft.commands.Commands) HashMap(java.util.HashMap) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Registry(net.minecraft.core.Registry) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) Map(java.util.Map) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ArgumentBuilder(com.mojang.brigadier.builder.ArgumentBuilder) TextComponent(net.minecraft.network.chat.TextComponent) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArgumentBuilder (com.mojang.brigadier.builder.ArgumentBuilder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 CommandSourceStack (net.minecraft.commands.CommandSourceStack)1 Commands (net.minecraft.commands.Commands)1 Registry (net.minecraft.core.Registry)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 DimensionType (net.minecraft.world.level.dimension.DimensionType)1