mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Autocomplete export and cleanup modes
- Suggest mode and format values for datapack export - Suggest preview and apply for pack cleanup mode
This commit is contained in:
1 parent
8531fcf103
commit
cdb4e68708
7 files changed
+132
-3
No files matched your search
@@ -20,6 +20,8 @@ package art.arcane.iris.command;
|
||||
|
||||
import art.arcane.iris.Iris;
|
||||
import art.arcane.iris.command.handlers.DimensionHandler;
|
||||
import art.arcane.iris.command.specialhandlers.ExportFormatHandler;
|
||||
import art.arcane.iris.command.specialhandlers.ExportModeHandler;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.localization.BukkitCommandMessages;
|
||||
import art.arcane.iris.localization.C;
|
||||
@@ -104,13 +106,13 @@ public class CommandDatapack implements DirectorExecutor {
|
||||
IrisDimension dimension,
|
||||
@Param(name = "version", description = "Target Minecraft version, 26.3 or later (blank uses the latest)", descriptionKey = "iris.director.commanddatapack.param.export_version", defaultValue = "")
|
||||
String version,
|
||||
@Param(name = "mode", description = "Output mode: preset, dimension, or overworld", descriptionKey = "iris.director.commanddatapack.param.export_mode", defaultValue = WorldgenExportRequest.DEFAULT_MODE)
|
||||
@Param(name = "mode", description = "Output mode: preset, dimension, or overworld", descriptionKey = "iris.director.commanddatapack.param.export_mode", defaultValue = WorldgenExportRequest.DEFAULT_MODE, customHandler = ExportModeHandler.class)
|
||||
String mode,
|
||||
@Param(name = "namespace", description = "Namespace for the exported resources", descriptionKey = "iris.director.commanddatapack.param.export_namespace", defaultValue = WorldgenExportRequest.DEFAULT_NAMESPACE)
|
||||
String namespace,
|
||||
@Param(name = "output", description = "Output name in the datapack exports folder (blank uses the dimension and version)", descriptionKey = "iris.director.commanddatapack.param.export_output", defaultValue = "")
|
||||
String output,
|
||||
@Param(name = "format", description = "zip or directory", descriptionKey = "iris.director.commanddatapack.param.export_format", defaultValue = WorldgenExportRequest.DEFAULT_FORMAT)
|
||||
@Param(name = "format", description = "zip or directory", descriptionKey = "iris.director.commanddatapack.param.export_format", defaultValue = WorldgenExportRequest.DEFAULT_FORMAT, customHandler = ExportFormatHandler.class)
|
||||
String format,
|
||||
@Param(name = "objects", description = "Include objects as structure templates", descriptionKey = "iris.director.commanddatapack.param.export_objects", defaultValue = "true")
|
||||
boolean objects,
|
||||
|
||||
@@ -35,6 +35,7 @@ import art.arcane.iris.localization.C;
|
||||
import art.arcane.iris.localization.ChatReport;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.command.handlers.DimensionHandler;
|
||||
import art.arcane.iris.command.specialhandlers.CleanupModeHandler;
|
||||
import art.arcane.iris.platform.bukkit.plugin.VolmitSender;
|
||||
import art.arcane.volmlib.util.director.annotations.Director;
|
||||
import art.arcane.volmlib.util.director.annotations.Param;
|
||||
@@ -162,7 +163,7 @@ public class CommandPack implements DirectorExecutor {
|
||||
public void cleanup(
|
||||
@Param(description = "The pack folder name to clean", descriptionKey = "iris.director.commandpack.param.pack_folder_name_clean")
|
||||
String pack,
|
||||
@Param(description = "preview or apply", descriptionKey = "iris.director.commandpack.param.preview_apply", defaultValue = "preview")
|
||||
@Param(description = "preview or apply", descriptionKey = "iris.director.commandpack.param.preview_apply", defaultValue = "preview", customHandler = CleanupModeHandler.class)
|
||||
String mode
|
||||
) {
|
||||
VolmitSender s = sender();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class CleanupModeHandler extends FixedChoiceHandler {
|
||||
public CleanupModeHandler() {
|
||||
super("preview", "apply");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String canonicalize(String input) {
|
||||
String mode = input.trim().toLowerCase(Locale.ROOT);
|
||||
if (!mode.equals("preview") && !mode.equals("apply")) {
|
||||
throw new IllegalArgumentException("Cleanup mode must be preview or apply.");
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.DatapackExportDestinations;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ExportFormatHandler extends FixedChoiceHandler {
|
||||
public ExportFormatHandler() {
|
||||
super("zip", "directory");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String canonicalize(String input) {
|
||||
return DatapackExportDestinations.parseFormat(input).name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportMode;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ExportModeHandler extends FixedChoiceHandler {
|
||||
public ExportModeHandler() {
|
||||
super("preset", "dimension", "overworld");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String canonicalize(String input) {
|
||||
return WorldgenExportMode.parse(input).name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.iris.command.DirectorParameterHandler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FixedChoiceHandler implements DirectorParameterHandler<String> {
|
||||
private final List<String> choices;
|
||||
|
||||
protected FixedChoiceHandler(String... choices) {
|
||||
this.choices = List.of(choices);
|
||||
}
|
||||
|
||||
protected abstract String canonicalize(String input);
|
||||
|
||||
@Override
|
||||
public KList<String> getPossibilities() {
|
||||
return new KList<>(choices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(String input, boolean force) throws DirectorParsingException {
|
||||
try {
|
||||
return canonicalize(input);
|
||||
} catch (IllegalArgumentException error) {
|
||||
throw new DirectorParsingException(error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> type) {
|
||||
return type == String.class;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package art.arcane.iris.command.specialhandlers;
|
||||
|
||||
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class FixedChoiceHandlerTest {
|
||||
@Test
|
||||
public void exportModeSuggestsAndCanonicalizesEveryMode() throws Exception {
|
||||
ExportModeHandler handler = new ExportModeHandler();
|
||||
assertEquals(List.of("preset", "dimension", "overworld"), handler.getPossibilities());
|
||||
assertEquals("preset", handler.parse(" PRESET ", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("nether", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportFormatSuggestsAndCanonicalizesAliases() throws Exception {
|
||||
ExportFormatHandler handler = new ExportFormatHandler();
|
||||
assertEquals(List.of("zip", "directory"), handler.getPossibilities());
|
||||
assertEquals("directory", handler.parse("folder", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("tar", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanupModeSuggestsAndRejectsUnknownModes() throws Exception {
|
||||
CleanupModeHandler handler = new CleanupModeHandler();
|
||||
assertEquals(List.of("preview", "apply"), handler.getPossibilities());
|
||||
assertEquals("apply", handler.parse("Apply", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("delete", false));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user