Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/main/java/space/essem/image2map/Image2Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void onInitialize() {
.requires(Permissions.require("image2map.use", CONFIG.minPermLevel))
.then(literal("create")
.requires(Permissions.require("image2map.create", 0))
.then(argument("width", IntegerArgumentType.integer(1))
.then(argument("height", IntegerArgumentType.integer(1))
.then(argument("width", IntegerArgumentType.integer(1, CONFIG.maxSize))
.then(argument("height", IntegerArgumentType.integer(1, CONFIG.maxSize))
.then(argument("mode", StringArgumentType.word()).suggests(new DitherModeSuggestionProvider())
.then(argument("path", StringArgumentType.greedyString())
.executes(this::createMap))
Expand All @@ -96,8 +96,8 @@ public void onInitialize() {
)
.then(literal("create-folder")
.requires(Permissions.require("image2map.createfolder", 3).and(x -> CONFIG.allowLocalFiles))
.then(argument("width", IntegerArgumentType.integer(1))
.then(argument("height", IntegerArgumentType.integer(1))
.then(argument("width", IntegerArgumentType.integer(1, CONFIG.maxSize))
.then(argument("height", IntegerArgumentType.integer(1, CONFIG.maxSize))
.then(argument("mode", StringArgumentType.word()).suggests(new DitherModeSuggestionProvider())
.then(argument("path", StringArgumentType.greedyString())
.executes(this::createMapFromFolder))
Expand Down Expand Up @@ -305,6 +305,11 @@ private int createMap(CommandContext<CommandSourceStack> context) throws Command

int finalHeight = height;
int finalWidth = width;

if (finalHeight > CONFIG.maxSize || finalWidth > CONFIG.maxSize) {
source.sendSuccess(() -> Component.literal("Map size exceeds maximum allowed (" + CONFIG.maxSize + "x" + CONFIG.maxSize + "), was " + finalWidth + "x" + finalHeight), false);
return null;
}
source.sendSuccess(() -> Component.literal("Converting into maps..."), false);

CompletableFuture.supplyAsync(() -> MapRenderer.render(image, mode, finalWidth, finalHeight)).thenAcceptAsync(mapImage -> {
Expand Down Expand Up @@ -350,6 +355,10 @@ private int createMapFromFolder(CommandContext<CommandSourceStack> context) thro

int finalHeight = height;
int finalWidth = width;

if (finalHeight > CONFIG.maxSize || finalWidth > CONFIG.maxSize) {
throw new SimpleCommandExceptionType(() -> "Map size exceeds maximum allowed (1024x1024), was " + finalWidth + "x" + finalHeight).create();
}
source.sendSuccess(() -> Component.literal("Converting into maps..."), false);

var mapImage = MapRenderer.render(image, mode, finalWidth, finalHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Image2MapConfig {
public boolean allowLocalFiles = false;

public int minPermLevel = 2;

public int maxSize = 1024;

public static Image2MapConfig loadOrCreateConfig() {
try {
Expand Down Expand Up @@ -54,4 +54,4 @@ public static void saveConfig(Image2MapConfig config) {
e.printStackTrace();
}
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/space/essem/image2map/gui/PreviewGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ private static <T> RequiredArgumentBuilder<PreviewGui, T> argument(String name,
}));

COMMANDS.register(literal("size")
.then(argument("width", IntegerArgumentType.integer(1))
.then(argument("width", IntegerArgumentType.integer(1, Image2Map.CONFIG.maxSize))
.executes(x -> {
var w = IntegerArgumentType.getInteger(x, "width");
x.getSource().setSize(w, x.getSource().sourceImage.getHeight() * w / x.getSource().sourceImage.getWidth());
return 0;
})
.then(argument("height", IntegerArgumentType.integer(1)).executes(x -> {
.then(argument("height", IntegerArgumentType.integer(1, Image2Map.CONFIG.maxSize)).executes(x -> {
x.getSource().setSize(IntegerArgumentType.getInteger(x, "width"), IntegerArgumentType.getInteger(x, "height"));
return 0;
})))
Expand Down