From 704f87da2378a941d04722f87a2112e19d0a9392 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 23 Jun 2022 09:23:22 +0100 Subject: [PATCH] Re-implement incremental schematic names in a folder (#1833) * Re-implement incremental schematic names in a folder - Fixes #1545 * Move fawe end comment * Slight cleanup --- .../sk89q/worldedit/command/SchematicCommands.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index af3235205..03d19e72c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -470,9 +470,16 @@ public class SchematicCommands { } } - //FAWE end File f = worldEdit.getSafeSaveFile(actor, dir, filename, format.getPrimaryFileExtension()); - + int i = f.getName().lastIndexOf('.'); + if (i == -1 && f.getName().isEmpty() || i == 0) { + File directory = f.getParentFile(); + int fileNumber = directory.exists() ? MainUtil.getMaxFileId(directory) : 0; + String extension = i == 0 ? f.getName().substring(i + 1) : format.getPrimaryFileExtension(); + String name = String.format("%s.%s", fileNumber, extension); + f = new File(directory, name); + filename += name; + } boolean overwrite = f.exists(); if (overwrite) { if (!actor.hasPermission("worldedit.schematic.delete")) { @@ -489,6 +496,7 @@ public class SchematicCommands { return; } } + //FAWE end // Create parent directories File parent = f.getParentFile();