From 7fa4797a72edc0a983e274642937ce57ca4ff055 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Thu, 26 Dec 2024 00:26:48 +0800 Subject: [PATCH] fix: ensure sizeX|Y|Z is bigger than zero when picking structure using structure command --- .../server/command/defaults/StructureCommand.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/allaymc/server/command/defaults/StructureCommand.java b/server/src/main/java/org/allaymc/server/command/defaults/StructureCommand.java index 5465a9793..2eef1b4a4 100644 --- a/server/src/main/java/org/allaymc/server/command/defaults/StructureCommand.java +++ b/server/src/main/java/org/allaymc/server/command/defaults/StructureCommand.java @@ -38,10 +38,18 @@ public void prepareCommandTree(CommandTree tree) { String fileName = context.getResult(1); Vector3f start = ((Vector3f) context.getResult(2)).floor(); Vector3f end = ((Vector3f) context.getResult(3)).floor(); + var sizeX = (int) (end.x - start.x + 1); + var sizeY = (int) (end.y - start.y + 1); + var sizeZ = (int) (end.z - start.z + 1); + // SizeX|Y|Z should bigger than 0 + if (sizeX <= 0 || sizeY <= 0 || sizeZ <= 0) { + context.addError("Invalid size"); + return context.fail(); + } var structure = Structure.pickStructure( player.getDimension(), (int) start.x, (int) start.y, (int) start.z, - (int) (end.x - start.x), (int) (end.y - start.y), (int) (end.z - start.z), + sizeX, sizeY, sizeZ, true ); var filePath = STRUCTURE_DIR.resolve(fileName + STRUCTURE_FILE_EXT);