mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Move module commands under /iris module <root> <command...>
Module commands get their own branch, with the alias /iris m. <root> is the root a module registers through ToolingRegistry.registerCommand, so /iris module structure list|info|verify replaces /iris structure list. - Bukkit: the branch word is taken before the Director runs; the Director first, then dispatcher fallback and the merged completions are gone. The first word completes "module". - Modded: the greedy-string tails at the /iris root and inside the structure literal are gone. The module and m literals take one greedy string, because the roots belong to the modules of the pack the sender resolves to when the line runs, so they cannot be Brigadier nodes when the tree is built. - /iris module alone lists the mounted roots and their commands; an unknown root is an error that points to that list. - Permissions are unchanged: iris.all, and commands opened to everyone. - /iris structure import and capture stay Director commands.
This commit is contained in:
1 parent
88fe8c8bcd
commit
f7aaed79a6
33 files changed
+230
-102
No files matched your search
+1
-1
@@ -52,7 +52,7 @@ public class CommandStructure implements DirectorExecutor {
|
||||
int imported = jigsaws.imported() + templates.imported() + groups.imported() + captured.imported();
|
||||
int failed = jigsaws.failed() + templates.failed() + groups.failed() + captured.failed();
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STRUCTURE_IMPORT_COMPLETE_STRUCTURES_OBJECTS_WRITTEN_FAILED, MessageArgument.untrusted("imported", imported), MessageArgument.untrusted("failed", failed)));
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STRUCTURE_REFERENCE_THEM_FROM_BIOME_REGION_DIMENSION_STRUCTURES_LIST_RUN_IRIS, MessageArgument.untrusted("value", dimension.getLoadKey())));
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STRUCTURE_REFERENCE_THEM_FROM_BIOME_REGION_DIMENSION_STRUCTURES_LIST_RUN_IRIS));
|
||||
}
|
||||
|
||||
@Director(name = "capture", description = "Capture live registered structures into editable Iris objects by generating each one in a throwaway scratch world and reading back its blocks. This standalone command overwrites its owned outputs; structures wider/taller than the capture cap and anything that will not generate in a flat overworld are skipped. Each captured structure becomes a single-piece Iris structure you can place from a biome/region/dimension 'structures' list. /iris structure import runs a restricted final capture pass only for non-jigsaw structures that have no loadable NBT template.", descriptionKey = "iris.director.commandstructure.director.capture_code_generated_structures_that_have_no_nbt_template_swamp_huts_igloos", aliases = {"cap"}, origin = DirectorOrigin.BOTH)
|
||||
|
||||
@@ -59,6 +59,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -183,7 +184,7 @@ public class CommandSVC implements IrisService, CommandExecutor, TabCompleter, D
|
||||
}
|
||||
|
||||
private void denyUnlessOpenToEveryone(CommandSender sender, ToolingSender toolingSender, String[] args) {
|
||||
if (tooling.executeIfOpenToEveryone(toolingSender, Arrays.asList(args))) {
|
||||
if (isModuleBranch(args) && tooling.executeIfOpenToEveryone(toolingSender, wordsAfterBranch(args))) {
|
||||
return;
|
||||
}
|
||||
ComponentMessenger.sendSection(sender, IrisLanguage.text(
|
||||
@@ -192,19 +193,33 @@ public class CommandSVC implements IrisService, CommandExecutor, TabCompleter, D
|
||||
));
|
||||
}
|
||||
|
||||
private static boolean isModuleBranch(String[] args) {
|
||||
return args.length > 0 && ToolingCommands.isBranchWord(args[0]);
|
||||
}
|
||||
|
||||
private static List<String> wordsAfterBranch(String[] args) {
|
||||
return Arrays.asList(args).subList(1, args.length);
|
||||
}
|
||||
|
||||
public List<String> tabCompleteRoot(CommandSender sender, String alias, String[] args) {
|
||||
List<String> suggestions = new ArrayList<>(runDirectorTab(sender, alias, args));
|
||||
for (String toolingSuggestion : tooling.complete(new BukkitToolingSender(sender), Arrays.asList(args))) {
|
||||
if (!suggestions.contains(toolingSuggestion)) {
|
||||
suggestions.add(toolingSuggestion);
|
||||
}
|
||||
}
|
||||
List<String> suggestions = isModuleBranch(args) && args.length > 1
|
||||
? tooling.complete(new BukkitToolingSender(sender), wordsAfterBranch(args))
|
||||
: directorSuggestionsWithModuleBranch(sender, alias, args);
|
||||
if (sender instanceof Player player && IrisSettings.get().getGeneral().isCommandSounds()) {
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.25f, RNG.r.f(0.125f, 1.95f));
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
private List<String> directorSuggestionsWithModuleBranch(CommandSender sender, String alias, String[] args) {
|
||||
List<String> suggestions = new ArrayList<>(runDirectorTab(sender, alias, args));
|
||||
boolean typingFirstWord = args.length == 1;
|
||||
if (typingFirstWord && ToolingCommands.BRANCH.startsWith(args[0].toLowerCase(Locale.ROOT))) {
|
||||
suggestions.add(ToolingCommands.BRANCH);
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
private PluginCommand findBukkitCommand() {
|
||||
try {
|
||||
return Iris.instance.getCommand(ROOT_COMMAND);
|
||||
@@ -233,6 +248,12 @@ public class CommandSVC implements IrisService, CommandExecutor, TabCompleter, D
|
||||
}
|
||||
|
||||
private void executeCommand(CommandSender sender, ToolingSender toolingSender, String label, String[] args) {
|
||||
if (isModuleBranch(args)) {
|
||||
tooling.execute(toolingSender, wordsAfterBranch(args));
|
||||
playSuccessSound(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sendHelpIfRequested(sender, args)) {
|
||||
playSuccessSound(sender);
|
||||
return;
|
||||
@@ -245,11 +266,6 @@ public class CommandSVC implements IrisService, CommandExecutor, TabCompleter, D
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.isHandled() && tooling.execute(toolingSender, Arrays.asList(args))) {
|
||||
playSuccessSound(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
playFailureSound(sender);
|
||||
if (result.getMessage() == null || result.getMessage().trim().isEmpty()) {
|
||||
new VolmitSender(sender).sendMessage(C.RED + IrisLanguage.text(IrisMessages.COMMAND_UNKNOWN));
|
||||
|
||||
+3
-1
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.modded.command;
|
||||
|
||||
import art.arcane.iris.core.tooling.ToolingCommands;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.LongArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
@@ -151,7 +152,8 @@ final class ModdedCommandTree {
|
||||
root.then(ModdedStructureCommands.tree("str"));
|
||||
root.then(ModdedDeveloperCommands.tree("developer"));
|
||||
root.then(ModdedDeveloperCommands.tree("dev"));
|
||||
root.then(ModdedToolingTail.after());
|
||||
root.then(ModdedModuleBranch.tree(ToolingCommands.BRANCH));
|
||||
root.then(ModdedModuleBranch.tree(ToolingCommands.BRANCH_ALIAS));
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
+20
-21
@@ -20,52 +20,51 @@ package art.arcane.iris.modded.command;
|
||||
|
||||
import art.arcane.iris.core.tooling.ToolingCommands;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* The tail of a command node that hands the rest of the line to the commands modules register
|
||||
* ({@link ToolingCommands}). It is a greedy string next to the node's literals, and Brigadier takes a literal that matches
|
||||
* before any argument, so a literal command always wins over a module's.
|
||||
* {@code /iris module <root> <command...>}: the one branch that hands its words to the commands modules register
|
||||
* ({@link ToolingCommands}). The roots belong to the modules of whichever pack the sender resolves to when the line runs,
|
||||
* so the branch cannot describe them as Brigadier nodes when the tree is built; it takes the rest of the line as one
|
||||
* greedy string. The dispatcher decides who may run what, so the literal has no permission of its own.
|
||||
*/
|
||||
final class ModdedToolingTail {
|
||||
private static final String ARGUMENT_NAME = "tooling";
|
||||
final class ModdedModuleBranch {
|
||||
private static final String ARGUMENT_NAME = "command";
|
||||
private static final int COMMAND_ACCEPTED = 1;
|
||||
private static final ToolingCommands TOOLING = ToolingCommands.forBoundPlatform();
|
||||
|
||||
private ModdedToolingTail() {
|
||||
private ModdedModuleBranch() {
|
||||
}
|
||||
|
||||
/** A tail for the node reached after {@code leadingWords}, which the dispatcher puts before the words the sender types. */
|
||||
static RequiredArgumentBuilder<CommandSourceStack, String> after(String... leadingWords) {
|
||||
List<String> leading = List.of(leadingWords);
|
||||
return Commands.argument(ARGUMENT_NAME, StringArgumentType.greedyString())
|
||||
.suggests((CommandContext<CommandSourceStack> context, SuggestionsBuilder builder) -> suggest(context.getSource(), leading, builder))
|
||||
.executes((CommandContext<CommandSourceStack> context) -> run(
|
||||
context.getSource(), leading, StringArgumentType.getString(context, ARGUMENT_NAME)));
|
||||
static LiteralArgumentBuilder<CommandSourceStack> tree(String literal) {
|
||||
return Commands.literal(literal)
|
||||
.executes((CommandContext<CommandSourceStack> context) -> run(context.getSource(), ""))
|
||||
.then(Commands.argument(ARGUMENT_NAME, StringArgumentType.greedyString())
|
||||
.suggests((CommandContext<CommandSourceStack> context, SuggestionsBuilder builder) ->
|
||||
suggest(context.getSource(), builder))
|
||||
.executes((CommandContext<CommandSourceStack> context) ->
|
||||
run(context.getSource(), StringArgumentType.getString(context, ARGUMENT_NAME))));
|
||||
}
|
||||
|
||||
private static int run(CommandSourceStack source, List<String> leading, String typed) {
|
||||
List<String> words = new ArrayList<>(leading);
|
||||
words.addAll(Arrays.stream(typed.trim().split("\\s+")).filter(word -> !word.isEmpty()).toList());
|
||||
private static int run(CommandSourceStack source, String typed) {
|
||||
List<String> words = Arrays.stream(typed.trim().split("\\s+")).filter(word -> !word.isEmpty()).toList();
|
||||
TOOLING.executeOffThread(new ModdedToolingSender(source), words);
|
||||
return COMMAND_ACCEPTED;
|
||||
}
|
||||
|
||||
private static CompletableFuture<Suggestions> suggest(CommandSourceStack source, List<String> leading, SuggestionsBuilder builder) {
|
||||
private static CompletableFuture<Suggestions> suggest(CommandSourceStack source, SuggestionsBuilder builder) {
|
||||
ModdedCommandFeedback.tab(source);
|
||||
String typed = builder.getRemaining();
|
||||
List<String> words = new ArrayList<>(leading);
|
||||
words.addAll(Arrays.asList(typed.split(" ", -1)));
|
||||
List<String> words = Arrays.asList(typed.split(" ", -1));
|
||||
SuggestionsBuilder lastWord = builder.createOffset(builder.getStart() + typed.lastIndexOf(' ') + 1);
|
||||
TOOLING.complete(new ModdedToolingSender(source), words).forEach(lastWord::suggest);
|
||||
return lastWord.buildFuture();
|
||||
+1
-2
@@ -26,7 +26,7 @@ import net.minecraft.commands.Commands;
|
||||
|
||||
/**
|
||||
* The {@code /iris structure} literals that only explain the Bukkit-only import and capture. The structure module's own
|
||||
* commands ({@code list}, {@code info}, {@code verify}) reach the sender through the tooling tail of this node.
|
||||
* commands ({@code list}, {@code info}, {@code verify}) are under {@code /iris module structure}.
|
||||
*/
|
||||
public final class ModdedStructureCommands {
|
||||
private static final String IMPORT_EXPLANATION = "Structure import rebuilds vanilla & datapack structures as editable Iris resources through Bukkit/NMS template managers; run /iris structure import on a Bukkit server against this pack, then copy the pack folder over.";
|
||||
@@ -47,7 +47,6 @@ public final class ModdedStructureCommands {
|
||||
root.then(message("all", IMPORT_EXPLANATION));
|
||||
root.then(message("capture", CAPTURE_EXPLANATION));
|
||||
root.then(message("cap", CAPTURE_EXPLANATION));
|
||||
root.then(ModdedToolingTail.after(name));
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
+32
-1
@@ -5,7 +5,10 @@ import art.arcane.iris.core.localization.PackDownloadMessages;
|
||||
import art.arcane.iris.core.lifecycle.LifecycleOperationCoordinator;
|
||||
import art.arcane.iris.core.pack.PackDownloader;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.tree.ArgumentCommandNode;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
@@ -159,11 +162,39 @@ public class IrisModdedCommandParityTest {
|
||||
assertNotNull("iris", iris.getCommand());
|
||||
for (String category : new String[]{"help", "find", "goto", "pregen", "pregenerate", "object", "o",
|
||||
"edit", "studio", "std", "s", "pack", "pk", "world", "w", "datapack", "datapacks", "dp",
|
||||
"structure", "struct", "str", "developer", "dev"}) {
|
||||
"structure", "struct", "str", "developer", "dev", "module", "m"}) {
|
||||
assertNotNull(category, child(iris, category).getCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moduleCommandsHaveTheirOwnBranchAndNoTailElsewhere() {
|
||||
CommandNode<CommandSourceStack> iris = irisNode();
|
||||
|
||||
for (CommandNode<CommandSourceStack> node : iris.getChildren()) {
|
||||
assertTrue(node.getName() + " must be a literal", node instanceof LiteralCommandNode);
|
||||
}
|
||||
for (CommandNode<CommandSourceStack> node : child(iris, "structure").getChildren()) {
|
||||
assertTrue("structure " + node.getName() + " must be a literal", node instanceof LiteralCommandNode);
|
||||
}
|
||||
for (String branch : new String[]{"module", "m"}) {
|
||||
CommandNode<CommandSourceStack> module = child(iris, branch);
|
||||
assertNotNull(branch + " lists the mounted commands on its own", module.getCommand());
|
||||
CommandNode<CommandSourceStack> rest = child(module, "command");
|
||||
assertTrue(rest instanceof ArgumentCommandNode);
|
||||
assertEquals(StringArgumentType.StringType.GREEDY_PHRASE, ((StringArgumentType) ((ArgumentCommandNode<?, ?>) rest).getType()).getType());
|
||||
assertNotNull(rest.getCommand());
|
||||
}
|
||||
}
|
||||
|
||||
private static CommandNode<CommandSourceStack> irisNode() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
CommandDispatcher<CommandSourceStack> dispatcher = new CommandDispatcher<>();
|
||||
IrisModdedCommands.register(dispatcher);
|
||||
return child(dispatcher.getRoot(), "iris");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consoleHelpListsEveryEntryWithInlineUsageAndDescription() {
|
||||
List<String> root = ModdedCommandHelp.consoleLines("");
|
||||
|
||||
-3
@@ -282,12 +282,9 @@ public class IrisModdedStructureCommandTest {
|
||||
@Test
|
||||
public void structureListInfoAndVerifyBelongToTheStructureModule() throws IOException {
|
||||
String source = source("ModdedStructureCommands.java");
|
||||
String tree = source("ModdedCommandTree.java");
|
||||
|
||||
assertTrue(source.contains("ModdedToolingTail.after(name)"));
|
||||
assertFalse(source.contains("Commands.literal(\"list\")"));
|
||||
assertFalse(source.contains("verifyTree("));
|
||||
assertTrue(tree.contains("root.then(ModdedToolingTail.after())"));
|
||||
}
|
||||
|
||||
private String source(String fileName) throws IOException {
|
||||
|
||||
Reference in new issue
Block a user