Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 02:50:06 +01:00
Fix schematic load with no specified format
Dieser Commit ist enthalten in:
Ursprung
c2a1fbf7cc
Commit
20feefcab2
@ -91,18 +91,20 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
|
|||||||
Map<String, Tag> map = compound.getValue();
|
Map<String, Tag> map = compound.getValue();
|
||||||
String name = ((StringTag) map.get("Name")).getValue();
|
String name = ((StringTag) map.get("Name")).getValue();
|
||||||
BlockType type = BlockTypes.get(name);
|
BlockType type = BlockTypes.get(name);
|
||||||
BlockState state = BlockState.get(type.getInternalId());
|
BlockState state = type.getDefaultState();
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
Fawe.debug("Unknown block: " + name);
|
Fawe.debug("Unknown block: " + name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CompoundTag properties = (CompoundTag) map.get("Properties");
|
CompoundTag properties = (CompoundTag) map.get("Properties");
|
||||||
|
if (properties != null) {
|
||||||
for (Map.Entry<String, Tag> entry : properties.getValue().entrySet()) {
|
for (Map.Entry<String, Tag> entry : properties.getValue().entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
String value = ((StringTag) entry.getValue()).getValue();
|
String value = ((StringTag) entry.getValue()).getValue();
|
||||||
Property property = type.getProperty(key);
|
Property property = type.getProperty(key);
|
||||||
state = state.with(property, property.getValueFor(value));
|
state = state.with(property, property.getValueFor(value));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
combinedArray[i] = state;
|
combinedArray[i] = state;
|
||||||
}
|
}
|
||||||
// Populate blocks
|
// Populate blocks
|
||||||
@ -140,7 +142,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
|
|||||||
Map<String, Tag> entityEntryMap = entityEntry.getValue();
|
Map<String, Tag> entityEntryMap = entityEntry.getValue();
|
||||||
ListTag posTag = (ListTag) entityEntryMap.get("pos");
|
ListTag posTag = (ListTag) entityEntryMap.get("pos");
|
||||||
CompoundTag nbtTag = (CompoundTag) entityEntryMap.get("nbt");
|
CompoundTag nbtTag = (CompoundTag) entityEntryMap.get("nbt");
|
||||||
String id = ((StringTag) entityEntryMap.get("Id")).getValue();
|
String id = nbtTag.getString("Id");
|
||||||
Location location = NBTConversions.toLocation(clipboard, posTag, nbtTag.getListTag("Rotation"));
|
Location location = NBTConversions.toLocation(clipboard, posTag, nbtTag.getListTag("Rotation"));
|
||||||
if (!id.isEmpty()) {
|
if (!id.isEmpty()) {
|
||||||
BaseEntity state = new BaseEntity(EntityTypes.get(id), nbtTag);
|
BaseEntity state = new BaseEntity(EntityTypes.get(id), nbtTag);
|
||||||
|
@ -46,6 +46,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
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.extent.clipboard.io.ClipboardWriter;
|
||||||
import com.sk89q.worldedit.function.operation.Operations;
|
import com.sk89q.worldedit.function.operation.Operations;
|
||||||
import com.sk89q.worldedit.math.transform.Transform;
|
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.binding.Switch;
|
||||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||||
import com.sk89q.worldedit.util.io.file.FilenameException;
|
import com.sk89q.worldedit.util.io.file.FilenameException;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@ -184,16 +187,27 @@ public class SchematicCommands extends MethodCommands {
|
|||||||
player.print(BBC.getPrefix() + "Remapped schematic");
|
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")
|
@Command(aliases = {"load"}, usage = "[<format>] <filename>", desc = "Load a schematic into your clipboard")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.upload", "worldedit.schematic.load.other"})
|
@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 LocalConfiguration config = this.worldEdit.getConfiguration();
|
||||||
final ClipboardFormat format = ClipboardFormat.findByAlias(formatName);
|
ClipboardFormat format = formatName == null ? null : ClipboardFormat.findByAlias(formatName);
|
||||||
if (format == null) {
|
|
||||||
BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
try {
|
try {
|
||||||
URI uri;
|
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 dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working;
|
||||||
File f;
|
File f;
|
||||||
if (filename.startsWith("#")) {
|
if (filename.startsWith("#")) {
|
||||||
f = player.openFileOpenDialog(new String[] { format.getExtension() });
|
String[] extensions;
|
||||||
if (!f.exists()) {
|
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 + ")");
|
player.printError("Schematic " + filename + " does not exist! (" + f + ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -227,32 +247,30 @@ public class SchematicCommands extends MethodCommands {
|
|||||||
BBC.NO_PERM.send(player, "worldedit.schematic.load.other");
|
BBC.NO_PERM.send(player, "worldedit.schematic.load.other");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!filename.matches(".*\\.[\\w].*")) {
|
if (format == null && filename.matches(".*\\.[\\w].*")) {
|
||||||
filename += "." + format.getExtension();
|
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()) {
|
if (f == null || !f.exists()) {
|
||||||
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 (!filename.contains("../")) {
|
if (!filename.contains("../")) {
|
||||||
dir = this.worldEdit.getWorkingDirectoryFile(config.saveDir);
|
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)) {
|
if (f == null || !f.exists() || !MainUtil.isInSubDirectory(working, f)) {
|
||||||
player.printError("Schematic " + filename + " does not exist! (" + f.exists() + "|" + f + "|" + (!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;
|
return;
|
||||||
}
|
}
|
||||||
|
if (format == null) {
|
||||||
|
format = ClipboardFormat.findByFile(f);
|
||||||
|
if (format == null) {
|
||||||
|
BBC.CLIPBOARD_INVALID_FORMAT.send(player, f.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
in = new FileInputStream(f);
|
in = new FileInputStream(f);
|
||||||
|
|
||||||
uri = f.toURI();
|
uri = f.toURI();
|
||||||
}
|
}
|
||||||
format.hold(player, uri, in);
|
format.hold(player, uri, in);
|
||||||
@ -473,7 +491,7 @@ public class SchematicCommands extends MethodCommands {
|
|||||||
Message m = new Message(BBC.SCHEMATIC_FORMAT).newline();
|
Message m = new Message(BBC.SCHEMATIC_FORMAT).newline();
|
||||||
String baseCmd = Commands.getAlias(SchematicCommands.class, "schematic") + " " + Commands.getAlias(SchematicCommands.class, "save");
|
String baseCmd = Commands.getAlias(SchematicCommands.class, "schematic") + " " + Commands.getAlias(SchematicCommands.class, "save");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (final ClipboardFormat format : ClipboardFormat.values()) {
|
for (final ClipboardFormat format : ClipboardFormat.values) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(format.name()).append(": ");
|
builder.append(format.name()).append(": ");
|
||||||
for (final String lookupName : format.getAliases()) {
|
for (final String lookupName : format.getAliases()) {
|
||||||
|
@ -31,7 +31,7 @@ public class BuiltInClipboardFormat {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static final ClipboardFormat[] values() {
|
public static final ClipboardFormat[] values() {
|
||||||
return ClipboardFormat.values();
|
return ClipboardFormat.values;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -48,6 +48,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
|||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -243,6 +244,8 @@ public enum ClipboardFormat {
|
|||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
public static final ClipboardFormat[] values;
|
||||||
|
|
||||||
private static final Map<String, ClipboardFormat> aliasMap;
|
private static final Map<String, ClipboardFormat> aliasMap;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -252,6 +255,7 @@ public enum ClipboardFormat {
|
|||||||
aliasMap.put(alias, emum);
|
aliasMap.put(alias, emum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
values = values();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IClipboardFormat format;
|
private IClipboardFormat format;
|
||||||
@ -560,6 +564,18 @@ public enum ClipboardFormat {
|
|||||||
return aliasMap.get(alias.toLowerCase(Locale.ENGLISH).trim());
|
return aliasMap.get(alias.toLowerCase(Locale.ENGLISH).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static ClipboardFormat findByExtension(String extension) {
|
||||||
|
checkNotNull(extension);
|
||||||
|
extension = extension.toLowerCase();
|
||||||
|
for (ClipboardFormat format : values) {
|
||||||
|
if (format.getFileExtensions().contains(extension)) {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect the format given a file.
|
* Detect the format given a file.
|
||||||
*
|
*
|
||||||
@ -584,6 +600,17 @@ public enum ClipboardFormat {
|
|||||||
for (String alias : newEnum.getAliases()) {
|
for (String alias : newEnum.getAliases()) {
|
||||||
aliasMap.put(alias, newEnum);
|
aliasMap.put(alias, newEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayList<ClipboardFormat> newValues = new ArrayList<>(Arrays.asList(values));
|
||||||
|
newValues.add(newEnum);
|
||||||
|
ClipboardFormat[] newValuesArray = newValues.toArray(new ClipboardFormat[newValues.size()]);
|
||||||
|
try {
|
||||||
|
ReflectionUtils.setFailsafeFieldValue(ClipboardFormat.class.getDeclaredField("values"), null, newValuesArray);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return newEnum;
|
return newEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class ClipboardFormats {
|
|||||||
public static ClipboardFormat findByFile(File file) {
|
public static ClipboardFormat findByFile(File file) {
|
||||||
checkNotNull(file);
|
checkNotNull(file);
|
||||||
|
|
||||||
for (ClipboardFormat format : ClipboardFormat.values()) {
|
for (ClipboardFormat format : ClipboardFormat.values) {
|
||||||
if (format.isFormat(file)) {
|
if (format.isFormat(file)) {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ public class ClipboardFormats {
|
|||||||
*/
|
*/
|
||||||
public static Multimap<String, ClipboardFormat> getFileExtensionMap() {
|
public static Multimap<String, ClipboardFormat> getFileExtensionMap() {
|
||||||
HashMultimap<String, ClipboardFormat> map = HashMultimap.create();
|
HashMultimap<String, ClipboardFormat> map = HashMultimap.create();
|
||||||
for (ClipboardFormat format : ClipboardFormat.values()) {
|
for (ClipboardFormat format : ClipboardFormat.values) {
|
||||||
for (String ext : format.getFileExtensions()) {
|
for (String ext : format.getFileExtensions()) {
|
||||||
map.put(ext, format);
|
map.put(ext, format);
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ public class ClipboardFormats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<ClipboardFormat> getAll() {
|
public static Collection<ClipboardFormat> getAll() {
|
||||||
return Arrays.asList(ClipboardFormat.values());
|
return Arrays.asList(ClipboardFormat.values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,7 +86,7 @@ public class ClipboardFormats {
|
|||||||
public static String[] getFileExtensionArray() {
|
public static String[] getFileExtensionArray() {
|
||||||
List<String> exts = new ArrayList<>();
|
List<String> exts = new ArrayList<>();
|
||||||
HashMultimap<String, ClipboardFormat> map = HashMultimap.create();
|
HashMultimap<String, ClipboardFormat> map = HashMultimap.create();
|
||||||
for (ClipboardFormat format : ClipboardFormat.values()) {
|
for (ClipboardFormat format : ClipboardFormat.values) {
|
||||||
exts.addAll(format.getFileExtensions());
|
exts.addAll(format.getFileExtensions());
|
||||||
}
|
}
|
||||||
return exts.toArray(new String[exts.size()]);
|
return exts.toArray(new String[exts.size()]);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren