Skip to content

Commit

Permalink
cloud 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Jan 27, 2024
1 parent da7ab52 commit 11b78dc
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 191 deletions.
Binary file added .DS_Store
Binary file not shown.
13 changes: 8 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ listOf(configurations.implementation, configurations.include, configurations.mod
dependencies {
minecraft("com.mojang", "minecraft", minecraftVersion)
mappings(loom.officialMojangMappings())
modImplementation("net.fabricmc", "fabric-loader", "0.15.3")
modImplementation("net.fabricmc", "fabric-loader", "0.15.6")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.92.1+1.20.4")

bom(platform("cloud.commandframework:cloud-bom:1.8.4"))
modImplementation(include("cloud.commandframework", "cloud-fabric"))
implementation(include("cloud.commandframework", "cloud-minecraft-extras"))
bom(platform("org.incendo:cloud-bom:2.0.0-beta.1"))
bom(platform("org.incendo:cloud-minecraft-bom:2.0.0-beta.1"))
modImplementation("org.incendo:cloud-fabric:2.0.0-beta.1")
include("org.incendo:cloud-fabric:2.0.0-beta.1")
implementation("org.incendo:cloud-minecraft-extras")
include("org.incendo:cloud-minecraft-extras")

modImplementation(include("net.kyori", "adventure-platform-fabric", "5.11.0-SNAPSHOT"))
modImplementation(include("net.kyori", "adventure-platform-fabric", "5.11.0"))

bom(platform("org.spongepowered:configurate-bom:4.1.2"))
implementation(include("org.spongepowered", "configurate-core"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
*/
package xyz.jpenilla.modscommand;

import cloud.commandframework.CommandManager;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricClientCommandManager;
import java.util.function.Function;
import net.fabricmc.api.ClientModInitializer;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.SenderMapper;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.fabric.FabricClientCommandManager;
import xyz.jpenilla.modscommand.command.Commander;
import xyz.jpenilla.modscommand.command.Commands;
import xyz.jpenilla.modscommand.command.RegistrableCommand;
Expand All @@ -34,9 +35,11 @@ public final class ModsCommandClientModInitializer implements ClientModInitializ
@Override
public void onInitializeClient() {
final FabricClientCommandManager<Commander> manager = new FabricClientCommandManager<>(
CommandExecutionCoordinator.simpleCoordinator(),
Commander.ClientCommander::new,
commander -> ((Commander.ClientCommander) commander).source()
ExecutionCoordinator.simpleCoordinator(),
SenderMapper.create(
Commander.ClientCommander::new,
commander -> ((Commander.ClientCommander) commander).source()
)
);
Commands.configureCommandManager(manager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
*/
package xyz.jpenilla.modscommand;

import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricServerCommandManager;
import cloud.commandframework.permission.Permission;
import java.io.IOException;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.SenderMapper;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.fabric.FabricServerCommandManager;
import org.incendo.cloud.permission.Permission;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.jpenilla.modscommand.command.Commander;
Expand Down Expand Up @@ -57,9 +58,11 @@ public void onInitialize() {
LOGGER.info("Mods Command detected {} loaded mods ({} top-level).", mods.totalModCount(), mods.topLevelModCount()); // We identify ourselves in log messages due to Vanilla MC's terrible Log4j config.

final FabricServerCommandManager<Commander> manager = new FabricServerCommandManager<>(
CommandExecutionCoordinator.simpleCoordinator(),
Commander.ServerCommander::new,
commander -> ((Commander.ServerCommander) commander).source()
ExecutionCoordinator.simpleCoordinator(),
SenderMapper.create(
Commander.ServerCommander::new,
commander -> ((Commander.ServerCommander) commander).source()
)
);
Commands.configureCommandManager(manager);

Expand Down
21 changes: 7 additions & 14 deletions src/main/java/xyz/jpenilla/modscommand/command/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,24 @@
*/
package xyz.jpenilla.modscommand.command;

import cloud.commandframework.execution.FilteringCommandSuggestionProcessor;
import cloud.commandframework.fabric.FabricCommandManager;
import cloud.commandframework.minecraft.extras.MinecraftExceptionHandler;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import xyz.jpenilla.modscommand.command.argument.ModDescriptionArgument;

import static cloud.commandframework.minecraft.extras.AudienceProvider.nativeAudience;
import org.incendo.cloud.fabric.FabricCommandManager;
import org.incendo.cloud.minecraft.extras.MinecraftExceptionHandler;
import xyz.jpenilla.modscommand.command.argument.parser.ModDescriptionParser;

@DefaultQualifier(NonNull.class)
public final class Commands {
private Commands() {
}

public static void configureCommandManager(final @NonNull FabricCommandManager<Commander, ?> manager) {
manager.commandSuggestionProcessor(new FilteringCommandSuggestionProcessor<>(
FilteringCommandSuggestionProcessor.Filter.<Commander>contains(true).andTrimBeforeLastSpace()
));

manager.brigadierManager().setNativeNumberSuggestions(false);

new MinecraftExceptionHandler<Commander>()
.withDefaultHandlers()
.apply(manager, nativeAudience());
MinecraftExceptionHandler.<Commander>createNative()
.defaultHandlers()
.registerTo(manager);

ModDescriptionArgument.registerParser(manager);
ModDescriptionParser.registerParser(manager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package xyz.jpenilla.modscommand.command;

import cloud.commandframework.CommandManager;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.CommandManager;

@DefaultQualifier(NonNull.class)
public interface RegistrableCommand {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Mods Command
* Copyright (c) 2022 Jason Penilla
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.jpenilla.modscommand.command.argument.parser;

import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.context.CommandInput;
import org.incendo.cloud.parser.ArgumentParseResult;
import org.incendo.cloud.parser.ArgumentParser;
import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.suggestion.BlockingSuggestionProvider;
import xyz.jpenilla.modscommand.command.Commander;
import xyz.jpenilla.modscommand.model.ModDescription;

import static org.incendo.cloud.parser.ArgumentParseResult.failure;
import static org.incendo.cloud.parser.ArgumentParseResult.success;
import static xyz.jpenilla.modscommand.model.Mods.mods;

@DefaultQualifier(NonNull.class)
public final class ModDescriptionParser implements ArgumentParser<Commander, ModDescription>, BlockingSuggestionProvider.Strings<Commander> {
public static void registerParser(final CommandManager<Commander> manager) {
manager.parserRegistry().registerParserSupplier(
TypeToken.get(ModDescription.class),
parserParameters -> new ModDescriptionParser()
);
}

public static ParserDescriptor<Commander, ModDescription> modDescriptionParser() {
return ParserDescriptor.of(new ModDescriptionParser(), ModDescription.class);
}

@Override
public ArgumentParseResult<ModDescription> parse(final CommandContext<Commander> commandContext, final CommandInput input) {
final String read = input.readString();
final @Nullable ModDescription meta = mods().findMod(read);
if (meta != null) {
return success(meta);
}
return failure(new IllegalArgumentException(
String.format("No mod with id '%s'.", read)
));
}

@Override
public Iterable<String> stringSuggestions(final CommandContext<Commander> commandContext, final CommandInput input) {
return mods().allMods()
.map(ModDescription::modId)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
*/
package xyz.jpenilla.modscommand.command.commands;

import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.permission.CommandPermission;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
Expand All @@ -30,6 +26,10 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.permission.Permission;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
Expand All @@ -49,12 +49,12 @@
@DefaultQualifier(NonNull.class)
public final class DumpModsCommand implements RegistrableCommand {
private final String label;
private final @Nullable CommandPermission permission;
private final @Nullable Permission permission;
private final Path dumpFile;

public DumpModsCommand(
final String primaryAlias,
final @Nullable CommandPermission permission
final @Nullable Permission permission
) {
this.label = primaryAlias;
this.permission = permission;
Expand Down Expand Up @@ -83,19 +83,19 @@ private void executeDumpModList(final CommandContext<Commander> ctx) {
.content("Saved list of installed mods to ")
.append(text(builder -> {
builder.content(this.dumpFile.getFileName().toString()).color(PINK);
if (ctx.getSender() instanceof Commander.ClientCommander) {
if (ctx.sender() instanceof Commander.ClientCommander) {
builder.clickEvent(openFile(this.dumpFile.toAbsolutePath().toString()))
.hoverEvent(text("Click to open file!", EMERALD));
}
}))
.append(text(" in the game directory."));
ctx.getSender().sendMessage(message);
ctx.sender().sendMessage(message);
final TextComponent.Builder copyMessage = text()
.content("Click here to copy it's contents to the clipboard.")
.color(PINK)
.clickEvent(copyToClipboard(dump))
.hoverEvent(text("Click to copy to clipboard!", EMERALD));
ctx.getSender().sendMessage(copyMessage);
ctx.sender().sendMessage(copyMessage);
}

private static String createDump() throws ConfigurateException {
Expand Down
Loading

0 comments on commit 11b78dc

Please sign in to comment.