mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-01 10:27:11 +00:00
Update SchematicCommands.java
This commit is contained in:
parent
778517f1ea
commit
41fea185fd
@ -332,107 +332,69 @@ 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;
|
File saveDir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
|
||||||
filename = formatName;
|
File dir = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS
|
||||||
formatName = t;
|
? new File(saveDir, actor.getUniqueId().toString())
|
||||||
}
|
: saveDir;
|
||||||
if (filename.startsWith("url:")) {
|
File file;
|
||||||
if (!actor.hasPermission("worldedit.schematic.load.web")) {
|
if (filename.startsWith("#")) {
|
||||||
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.load.web"));
|
format = noExplicitFormat ? null :ClipboardFormats.findByAlias(formatName);
|
||||||
return;
|
String[] extensions;
|
||||||
}
|
if (format != null) {
|
||||||
UUID uuid = UUID.fromString(filename.substring(4));
|
extensions = format.getFileExtensions().toArray(new String[0]);
|
||||||
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 dir = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS ? new File(saveDir, actor.getUniqueId().toString()) : saveDir;
|
|
||||||
File file;
|
|
||||||
if (filename.startsWith("#")) {
|
|
||||||
format = noExplicitFormat ? null : ClipboardFormats.findByAlias(formatName);
|
|
||||||
String[] extensions;
|
|
||||||
if (format != null) {
|
|
||||||
extensions = format.getFileExtensions().toArray(new String[0]);
|
|
||||||
} else {
|
|
||||||
extensions = ClipboardFormats.getFileExtensionArray();
|
|
||||||
}
|
|
||||||
file = actor.openFileOpenDialog(extensions);
|
|
||||||
if (file == null || !file.exists()) {
|
|
||||||
actor.print(Caption.of("worldedit.schematic.load.does-not-exist", TextComponent.of(filename)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && !actor.hasPermission("worldedit.schematic.load.other") && Pattern
|
extensions = ClipboardFormats.getFileExtensionArray();
|
||||||
.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
}
|
||||||
.matcher(filename)
|
file = actor.openFileOpenDialog(extensions);
|
||||||
.find()) {
|
if (file == null || !file.exists()) {
|
||||||
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.load.other"));
|
actor.print(Caption.of("worldedit.schematic.load.does-not-exist", TextComponent.of(filename)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!noExplicitFormat) {
|
} else {
|
||||||
|
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && !actor.hasPermission("worldedit.schematic.load.other") && Pattern
|
||||||
|
.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
||||||
|
.matcher(filename)
|
||||||
|
.find()) {
|
||||||
|
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.load.other"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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 {
|
||||||
format = null;
|
format = null;
|
||||||
}
|
}
|
||||||
|
file = MainUtil.resolve(dir, filename, format, false);
|
||||||
|
}
|
||||||
|
if (file == null || !file.exists()) {
|
||||||
|
if (!filename.contains("../")) {
|
||||||
|
dir = this.worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
|
||||||
file = MainUtil.resolve(dir, filename, format, false);
|
file = MainUtil.resolve(dir, filename, format, false);
|
||||||
}
|
}
|
||||||
if (file == null || !file.exists()) {
|
}
|
||||||
if (!filename.contains("../")) {
|
if (file == null || !file.exists() || !MainUtil.isInSubDirectory(saveDir, file)) {
|
||||||
dir = this.worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
|
actor.printError(TextComponent.of("Schematic " + filename + " does not exist! (" + (file != null && file.exists()) +
|
||||||
file = MainUtil.resolve(dir, filename, format, false);
|
"|" + file + "|" + (file != null && !MainUtil
|
||||||
}
|
.isInSubDirectory(saveDir, file)) + ")"));
|
||||||
}
|
return;
|
||||||
if (file == null || !file.exists() || !MainUtil.isInSubDirectory(saveDir, file)) {
|
}
|
||||||
actor.printError(TextComponent.of("Schematic " + filename + " does not exist! (" + (file != null && file.exists()) +
|
if (format == null) {
|
||||||
"|" + file + "|" + (file != null && !MainUtil
|
format = ClipboardFormats.findByFile(file);
|
||||||
.isInSubDirectory(saveDir, file)) + ")"));
|
if (format == null) {if (noExplicitFormat) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (format == null) {
|
|
||||||
format = ClipboardFormats.findByFile(file);
|
|
||||||
if (format == null) {
|
|
||||||
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);
|
|
||||||
uri = file.toURI();
|
|
||||||
}
|
}
|
||||||
closer.register(in);
|
|
||||||
|
in = new FileInputStream(file);
|
||||||
|
uri = file.toURI();
|
||||||
format.hold(actor, uri, in);
|
format.hold(actor, uri, in);
|
||||||
if (randomRotate) {
|
if (randomRotate) {
|
||||||
AffineTransform transform = new AffineTransform();
|
AffineTransform transform = new AffineTransform();
|
||||||
|
Loading…
Reference in New Issue
Block a user