mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 14:58:35 +00:00
Fix schematic load with no specified format
This commit is contained in:
@ -46,6 +46,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
@ -53,6 +54,8 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.command.binding.Switch;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import com.sk89q.worldedit.util.io.file.FilenameException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@ -184,16 +187,27 @@ public class SchematicCommands extends MethodCommands {
|
||||
player.print(BBC.getPrefix() + "Remapped schematic");
|
||||
}
|
||||
|
||||
|
||||
private File resolve(File dir, String filename, @Nullable ClipboardFormat format) {
|
||||
if (format != null) {
|
||||
if (!filename.matches(".*\\.[\\w].*")) {
|
||||
filename = filename + "." + format.getExtension();
|
||||
}
|
||||
return MainUtil.resolveRelative(new File(dir, filename));
|
||||
}
|
||||
for (ClipboardFormat f : ClipboardFormat.values) {
|
||||
File file = MainUtil.resolveRelative(new File(dir, filename + "." + f.getExtension()));
|
||||
if (file.exists()) return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Command(aliases = {"load"}, usage = "[<format>] <filename>", desc = "Load a schematic into your clipboard")
|
||||
@Deprecated
|
||||
@CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.upload", "worldedit.schematic.load.other"})
|
||||
public void load(final Player player, final LocalSession session, @Optional("schematic") final String formatName, String filename) throws FilenameException {
|
||||
public void load(final Player player, final LocalSession session, @Optional() final String formatName, String filename) throws FilenameException {
|
||||
final LocalConfiguration config = this.worldEdit.getConfiguration();
|
||||
final ClipboardFormat format = ClipboardFormat.findByAlias(formatName);
|
||||
if (format == null) {
|
||||
BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName);
|
||||
return;
|
||||
}
|
||||
ClipboardFormat format = formatName == null ? null : ClipboardFormat.findByAlias(formatName);
|
||||
InputStream in = null;
|
||||
try {
|
||||
URI uri;
|
||||
@ -217,8 +231,14 @@ public class SchematicCommands extends MethodCommands {
|
||||
File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working;
|
||||
File f;
|
||||
if (filename.startsWith("#")) {
|
||||
f = player.openFileOpenDialog(new String[] { format.getExtension() });
|
||||
if (!f.exists()) {
|
||||
String[] extensions;
|
||||
if (format != null) {
|
||||
extensions = format.getFileExtensions().toArray(new String[0]);
|
||||
} else {
|
||||
extensions = ClipboardFormats.getFileExtensionArray();
|
||||
}
|
||||
f = player.openFileOpenDialog(extensions);
|
||||
if (f == null || !f.exists()) {
|
||||
player.printError("Schematic " + filename + " does not exist! (" + f + ")");
|
||||
return;
|
||||
}
|
||||
@ -227,32 +247,30 @@ public class SchematicCommands extends MethodCommands {
|
||||
BBC.NO_PERM.send(player, "worldedit.schematic.load.other");
|
||||
return;
|
||||
}
|
||||
if (!filename.matches(".*\\.[\\w].*")) {
|
||||
filename += "." + format.getExtension();
|
||||
if (format == null && filename.matches(".*\\.[\\w].*")) {
|
||||
String extension = filename.substring(filename.lastIndexOf('.') + 1, filename.length());
|
||||
format = ClipboardFormat.findByExtension(extension);
|
||||
}
|
||||
f = MainUtil.resolveRelative(new File(dir, filename));
|
||||
f = resolve(dir, filename, format);
|
||||
}
|
||||
if (f.getName().replaceAll("." + format.getExtension(), "").isEmpty()) {
|
||||
File directory = f.getParentFile();
|
||||
if (directory.exists()) {
|
||||
int max = MainUtil.getMaxFileId(directory) - 1;
|
||||
f = new File(directory, max + "." + format.getExtension());
|
||||
} else {
|
||||
f = new File(directory, "1." + format.getExtension());
|
||||
}
|
||||
}
|
||||
if (!f.exists()) {
|
||||
if (f == null || !f.exists()) {
|
||||
if (!filename.contains("../")) {
|
||||
dir = this.worldEdit.getWorkingDirectoryFile(config.saveDir);
|
||||
f = this.worldEdit.getSafeSaveFile(player, dir, filename, format.getExtension(), format.getExtension());
|
||||
f = resolve(dir, filename, format);
|
||||
}
|
||||
}
|
||||
if (!f.exists() || !MainUtil.isInSubDirectory(working, f)) {
|
||||
player.printError("Schematic " + filename + " does not exist! (" + f.exists() + "|" + f + "|" + (!MainUtil.isInSubDirectory(working, f)) + ")");
|
||||
if (f == null || !f.exists() || !MainUtil.isInSubDirectory(working, f)) {
|
||||
player.printError("Schematic " + filename + " does not exist! (" + ((f == null) ? false : f.exists()) + "|" + f + "|" + (f == null ? false : !MainUtil.isInSubDirectory(working, f)) + ")");
|
||||
return;
|
||||
}
|
||||
if (format == null) {
|
||||
format = ClipboardFormat.findByFile(f);
|
||||
if (format == null) {
|
||||
BBC.CLIPBOARD_INVALID_FORMAT.send(player, f.getName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
in = new FileInputStream(f);
|
||||
|
||||
uri = f.toURI();
|
||||
}
|
||||
format.hold(player, uri, in);
|
||||
@ -473,7 +491,7 @@ public class SchematicCommands extends MethodCommands {
|
||||
Message m = new Message(BBC.SCHEMATIC_FORMAT).newline();
|
||||
String baseCmd = Commands.getAlias(SchematicCommands.class, "schematic") + " " + Commands.getAlias(SchematicCommands.class, "save");
|
||||
boolean first = true;
|
||||
for (final ClipboardFormat format : ClipboardFormat.values()) {
|
||||
for (final ClipboardFormat format : ClipboardFormat.values) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(format.name()).append(": ");
|
||||
for (final String lookupName : format.getAliases()) {
|
||||
|
Reference in New Issue
Block a user