Cast, Convert & more

This commit is contained in:
skippyall
2026-03-16 23:01:58 +01:00
parent 9b61dba4c7
commit 7acd083e79
59 changed files with 1207 additions and 178 deletions
@@ -0,0 +1,36 @@
package io.github.skippyall.minions.command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.github.skippyall.minions.docs.DocsManager;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Identifier;
import java.util.concurrent.CompletableFuture;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandManager.argument;
public class DocsSubcommand {
public static final LiteralArgumentBuilder<ServerCommandSource> DOCS = literal("docs")
.then(
argument("docName", IdentifierArgumentType.identifier())
.suggests(DocsSubcommand::getSuggestions)
.executes(DocsSubcommand::execute)
);
public static CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
DocsManager.getDocsEntryIds().forEach(id -> builder.suggest(id.toString()));
return CompletableFuture.completedFuture(builder.build());
}
public static int execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
Identifier id = IdentifierArgumentType.getIdentifier(context, "docName");
DocsManager.showDocsEntry(context.getSource().getPlayerOrThrow(), id);
return 1;
}
}