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
This commit is contained in:
Jordan 2022-06-23 09:23:22 +01:00 committed by GitHub
parent 100288ada5
commit 704f87da23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -470,9 +470,16 @@ public class SchematicCommands {
} }
} }
//FAWE end
File f = worldEdit.getSafeSaveFile(actor, dir, filename, format.getPrimaryFileExtension()); 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(); boolean overwrite = f.exists();
if (overwrite) { if (overwrite) {
if (!actor.hasPermission("worldedit.schematic.delete")) { if (!actor.hasPermission("worldedit.schematic.delete")) {
@ -489,6 +496,7 @@ public class SchematicCommands {
return; return;
} }
} }
//FAWE end
// Create parent directories // Create parent directories
File parent = f.getParentFile(); File parent = f.getParentFile();