Update SchematicCommands.java

This commit is contained in:
Telesphoreo 2024-10-15 18:23:08 -05:00
parent 778517f1ea
commit 41fea185fd
No known key found for this signature in database
GPG Key ID: 9D1991811E093C02

View File

@ -332,48 +332,13 @@ public class SchematicCommands {
if (noExplicitFormat) { if (noExplicitFormat) {
formatName = "fast"; formatName = "fast";
} }
try(final Closer closer = Closer.create()) { try {
URI uri; URI uri;
if (formatName.startsWith("url:")) {
String t = filename;
filename = formatName;
formatName = t;
}
if (filename.startsWith("url:")) {
if (!actor.hasPermission("worldedit.schematic.load.web")) {
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.load.web"));
return;
}
UUID uuid = UUID.fromString(filename.substring(4));
URL webUrl = new URL(Settings.settings().WEB.URL);
if ((format = ClipboardFormats.findByAlias(formatName)) == null) {
actor.print(Caption.of("worldedit.schematic.unknown-format", TextComponent.of(formatName)));
return;
}
// The interface requires the correct schematic extension - otherwise it can't be downloaded
// So it basically only supports .schem files (sponge v2 + v3) - or the correct extensions is specified manually
// Sadly it's not really an API endpoint but spits out the HTML source of the uploader - so no real handling
// can happen
URL url = new URL(webUrl, "uploads/" + uuid + "." + format.getPrimaryFileExtension());
final Path temp = Files.createTempFile("faweremoteschem", null);
final File tempFile = temp.toFile();
// delete temporary file when we're done
closer.register((Closeable) () -> Files.deleteIfExists(temp));
// write schematic into temporary file
try (final InputStream urlIn = new BufferedInputStream(url.openStream());
final OutputStream tempOut = new BufferedOutputStream(new FileOutputStream(tempFile))) {
urlIn.transferTo(tempOut);
}
// No format is specified -> try or fail
if (noExplicitFormat && (format = ClipboardFormats.findByFile(tempFile)) == null) {
actor.print(Caption.of("fawe.worldedit.schematic.schematic.load-failure", TextComponent.of(filename)));
return;
}
in = new FileInputStream(tempFile);
uri = temp.toUri();
} else {
File saveDir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile(); File saveDir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
File dir = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS ? new File(saveDir, actor.getUniqueId().toString()) : saveDir; File dir = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS
? new File(saveDir, actor.getUniqueId().toString())
: saveDir;
File file; File file;
if (filename.startsWith("#")) { if (filename.startsWith("#")) {
format = noExplicitFormat ? null :ClipboardFormats.findByAlias(formatName); format = noExplicitFormat ? null :ClipboardFormats.findByAlias(formatName);
@ -398,7 +363,7 @@ public class SchematicCommands {
} }
if (!noExplicitFormat) { if (!noExplicitFormat) {
format = ClipboardFormats.findByAlias(formatName); format = ClipboardFormats.findByAlias(formatName);
} else if (filename.matches(".*\\.\\w.*")) { } else if ( filename.matches(".*\\.[\\w].*")) {
format = ClipboardFormats format = ClipboardFormats
.findByExplicitExtension(filename.substring(filename.lastIndexOf('.') + 1)); .findByExplicitExtension(filename.substring(filename.lastIndexOf('.') + 1));
} else { } else {
@ -420,19 +385,16 @@ public class SchematicCommands {
} }
if (format == null) { if (format == null) {
format = ClipboardFormats.findByFile(file); format = ClipboardFormats.findByFile(file);
if (format == null) { if (format == null) {if (noExplicitFormat) {
if (noExplicitFormat) {
actor.print(Caption.of("fawe.worldedit.schematic.schematic.load-failure", TextComponent.of(file.getName()))); actor.print(Caption.of("fawe.worldedit.schematic.schematic.load-failure", TextComponent.of(file.getName())));
} else { } else {
actor.print(Caption.of("worldedit.schematic.unknown-format", TextComponent.of(formatName))); actor.print(Caption.of("worldedit.schematic.unknown-format", TextComponent.of(formatName)));}
}
return; return;
} }
} }
in = new FileInputStream(file); in = new FileInputStream(file);
uri = file.toURI(); uri = file.toURI();
}
closer.register(in);
format.hold(actor, uri, in); format.hold(actor, uri, in);
if (randomRotate) { if (randomRotate) {
AffineTransform transform = new AffineTransform(); AffineTransform transform = new AffineTransform();