Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-07 12:00:07 +01:00
Few tweaks to schematic loading and error fixes.
* Not all EntityTypes in Bukkit have the correct enum name. * Don't read entire schematic files to list. Go off file extension only. (Reading in files is more accurate, but slow.) * Enforce extensions. (Due to the above, while you can technically make a schematic called 'test.txt', it's better that we save it as 'test.txt.schem'.) * Fix a few minor warnings.
Dieser Commit ist enthalten in:
Ursprung
eebba8e324
Commit
7c89ece96e
@ -160,7 +160,10 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
||||
}
|
||||
// Entity
|
||||
for (org.bukkit.entity.EntityType entityType : org.bukkit.entity.EntityType.values()) {
|
||||
EntityType.REGISTRY.register("minecraft:" + entityType.name().toLowerCase(), new EntityType("minecraft:" + entityType.name().toLowerCase()));
|
||||
String mcid = entityType.getName();
|
||||
if (mcid != null) {
|
||||
EntityType.REGISTRY.register("minecraft:" + mcid.toLowerCase(), new EntityType("minecraft:" + mcid.toLowerCase()));
|
||||
}
|
||||
}
|
||||
// Tags
|
||||
try {
|
||||
|
@ -67,6 +67,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -90,11 +91,11 @@ import javax.script.ScriptException;
|
||||
* method {@link WorldEdit#getInstance()}, which is shared among all
|
||||
* platforms within the same classloader hierarchy.</p>
|
||||
*/
|
||||
public class WorldEdit {
|
||||
public final class WorldEdit {
|
||||
|
||||
public static final Logger logger = Logger.getLogger(WorldEdit.class.getCanonicalName());
|
||||
|
||||
private final static WorldEdit instance = new WorldEdit();
|
||||
private static final WorldEdit instance = new WorldEdit();
|
||||
private static String version;
|
||||
|
||||
private final EventBus eventBus = new EventBus();
|
||||
@ -274,14 +275,15 @@ public class WorldEdit {
|
||||
}
|
||||
} else {
|
||||
List<String> exts = extensions == null ? ImmutableList.of(defaultExt) : Lists.asList(defaultExt, extensions);
|
||||
return getSafeFileWithExtensions(dir, filename, exts, isSave);
|
||||
f = getSafeFileWithExtensions(dir, filename, exts, isSave);
|
||||
}
|
||||
|
||||
try {
|
||||
String filePath = f.getCanonicalPath();
|
||||
String dirPath = dir.getCanonicalPath();
|
||||
|
||||
if (!filePath.substring(0, dirPath.length()).equals(dirPath) && !getConfiguration().allowSymlinks) {
|
||||
if ((filePath.length() < dirPath.length() || !filePath.substring(0, dirPath.length()).equals(dirPath))
|
||||
&& !getConfiguration().allowSymlinks) {
|
||||
throw new FilenameResolutionException(filename,
|
||||
"Path is outside allowable root");
|
||||
}
|
||||
@ -301,7 +303,7 @@ public class WorldEdit {
|
||||
}
|
||||
}
|
||||
File result = null;
|
||||
for (Iterator<String> iter = exts.iterator(); iter.hasNext() && (result == null || !result.exists());) {
|
||||
for (Iterator<String> iter = exts.iterator(); iter.hasNext() && (result == null || (!isSave && !result.exists()));) {
|
||||
result = getSafeFileWithExtension(dir, filename, iter.next());
|
||||
}
|
||||
if (result == null) {
|
||||
@ -311,8 +313,12 @@ public class WorldEdit {
|
||||
}
|
||||
|
||||
private File getSafeFileWithExtension(File dir, String filename, String extension) {
|
||||
if (extension != null && filename.lastIndexOf('.') == -1) {
|
||||
filename += "." + extension;
|
||||
if (extension != null) {
|
||||
int dot = filename.lastIndexOf('.');
|
||||
if (dot < 0 || !filename.substring(dot).equalsIgnoreCase(extension))
|
||||
{
|
||||
filename += "." + extension;
|
||||
}
|
||||
}
|
||||
|
||||
if (!checkFilename(filename)) {
|
||||
@ -618,7 +624,7 @@ public class WorldEdit {
|
||||
byte[] data = new byte[in.available()];
|
||||
in.readFully(data);
|
||||
in.close();
|
||||
script = new String(data, 0, data.length, "utf-8");
|
||||
script = new String(data, 0, data.length, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
player.printError("Script read error: " + e.getMessage());
|
||||
return;
|
||||
|
@ -21,6 +21,8 @@ package com.sk89q.worldedit.command;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.Files;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
@ -196,7 +198,7 @@ public class SchematicCommands {
|
||||
String filename = args.getString(0);
|
||||
|
||||
File dir = worldEdit.getWorkingDirectoryFile(config.saveDir);
|
||||
File f = worldEdit.getSafeSaveFile(player, dir, filename, "schematic", "schematic");
|
||||
File f = worldEdit.getSafeOpenFile(player, dir, filename, "schematic", ClipboardFormats.getFileExtensionArray());
|
||||
|
||||
if (!f.exists()) {
|
||||
player.printError("Schematic " + filename + " does not exist!");
|
||||
@ -209,6 +211,11 @@ public class SchematicCommands {
|
||||
}
|
||||
|
||||
player.print(filename + " has been deleted.");
|
||||
try {
|
||||
log.info(player.getName() + " deleted " + f.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
log.info(player.getName() + " deleted " + f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -245,7 +252,8 @@ public class SchematicCommands {
|
||||
help = "List all schematics in the schematics directory\n" +
|
||||
" -d sorts by date, oldest first\n" +
|
||||
" -n sorts by date, newest first\n" +
|
||||
" -p <page> prints the requested page\n"
|
||||
" -p <page> prints the requested page\n" +
|
||||
"Note: Format is not thoroughly verified until loading."
|
||||
)
|
||||
@CommandPermissions("worldedit.schematic.list")
|
||||
public void list(Actor actor, CommandContext args, @Switch('p') @Optional("1") int page) throws WorldEditException {
|
||||
@ -328,10 +336,13 @@ public class SchematicCommands {
|
||||
StringBuilder build = new StringBuilder();
|
||||
|
||||
build.append("\u00a72");
|
||||
ClipboardFormat format = ClipboardFormats.findByFile(file);
|
||||
//ClipboardFormat format = ClipboardFormats.findByFile(file);
|
||||
Multimap<String, ClipboardFormat> exts = ClipboardFormats.getFileExtensionMap();
|
||||
ClipboardFormat format = exts.get(Files.getFileExtension(file.getName()))
|
||||
.stream().findFirst().orElse(null);
|
||||
boolean inRoot = file.getParentFile().getName().equals(prefix);
|
||||
build.append(inRoot ? file.getName() : file.getPath().split(Pattern.quote(prefix + File.separator))[1])
|
||||
.append(": ").append(format == null ? "Unknown" : format.getName());
|
||||
.append(": ").append(format == null ? "Unknown" : format.getName() + "*");
|
||||
result.add(build.toString());
|
||||
}
|
||||
return result;
|
||||
|
@ -46,9 +46,7 @@ public abstract class NBTSchematicReader implements ClipboardReader {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static <T extends Tag> T getTag(CompoundTag tag, Class<T> expected, String key) {
|
||||
Map<String, Tag> items = tag.getValue();
|
||||
|
||||
protected static <T extends Tag> T getTag(Map<String, Tag> items, String key, Class<T> expected) {
|
||||
if (!items.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -88,16 +88,16 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
int version = requireTag(schematic, "Version", IntTag.class).getValue();
|
||||
switch (version) {
|
||||
case 1:
|
||||
return readVersion1(schematic);
|
||||
return readVersion1(schematicTag);
|
||||
default:
|
||||
throw new IOException("This schematic version is currently not supported");
|
||||
}
|
||||
}
|
||||
|
||||
private Clipboard readVersion1(Map<String, Tag> schematic) throws IOException {
|
||||
private Clipboard readVersion1(CompoundTag schematicTag) throws IOException {
|
||||
BlockVector3 origin;
|
||||
Region region;
|
||||
|
||||
Map<String, Tag> schematic = schematicTag.getValue();
|
||||
Map<String, Tag> metadata = requireTag(schematic, "Metadata", CompoundTag.class).getValue();
|
||||
|
||||
int width = requireTag(schematic, "Width", ShortTag.class).getValue();
|
||||
@ -143,7 +143,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
try {
|
||||
state = WorldEdit.getInstance().getBlockFactory().parseFromInput(palettePart, parserContext).toImmutableState();
|
||||
} catch (InputParseException e) {
|
||||
throw new IOException("Invalid BlockState in schematic: " + palettePart + ". Are you missing a mod of using a schematic made in a newer version of Minecraft?");
|
||||
throw new IOException("Invalid BlockState in schematic: " + palettePart + ". Are you missing a mod or using a schematic made in a newer version of Minecraft?");
|
||||
}
|
||||
palette.put(id, state);
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren