Minor upstream changes

This commit is contained in:
MattBDev 2019-05-31 11:20:02 -04:00
parent 3eb7200ea0
commit c73fc28847
4 changed files with 28 additions and 59 deletions

View File

@ -56,7 +56,6 @@ public class SnapshotUtilCommands {
aliases = { "restore", "/restore" }, aliases = { "restore", "/restore" },
usage = "[snapshot]", usage = "[snapshot]",
desc = "Restore the selection from a snapshot", desc = "Restore the selection from a snapshot",
min = 0,
max = 1 max = 1
) )
@Logging(REGION) @Logging(REGION)
@ -112,23 +111,14 @@ public class SnapshotUtilCommands {
} }
} }
ChunkStore chunkStore = null;
// Load chunk store // Load chunk store
try { SnapshotRestore restore;
chunkStore = snapshot.getChunkStore(); try (ChunkStore chunkStore = snapshot.getChunkStore()) {
BBC.SNAPSHOT_LOADED.send(player, snapshot.getName()); BBC.SNAPSHOT_LOADED.send(player, snapshot.getName());
} catch (DataException e) {
player.printError(BBC.getPrefix() + "Failed to load snapshot: " + e.getMessage());
return;
} catch (IOException e) {
player.printError(BBC.getPrefix() + "Failed to load snapshot: " + e.getMessage());
return;
}
try {
// Restore snapshot // Restore snapshot
SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region); restore = new SnapshotRestore(chunkStore, editSession, region);
//player.print(restore.getChunksAffected() + " chunk(s) will be loaded."); //player.print(restore.getChunksAffected() + " chunk(s) will be loaded.");
restore.restore(); restore.restore();
@ -137,21 +127,18 @@ public class SnapshotUtilCommands {
String error = restore.getLastErrorMessage(); String error = restore.getLastErrorMessage();
if (error != null) { if (error != null) {
BBC.SNAPSHOT_ERROR_RESTORE.send(player); BBC.SNAPSHOT_ERROR_RESTORE.send(player);
player.printError(BBC.getPrefix() + "Last error: " + error); player.printError("Last error: " + error);
} else { } else {
BBC.SNAPSHOT_ERROR_RESTORE_CHUNKS.send(player); BBC.SNAPSHOT_ERROR_RESTORE_CHUNKS.send(player);
} }
} else { } else {
player.print(BBC.getPrefix() + String.format("Restored; %d " player.print(String.format("Restored; %d "
+ "missing chunks and %d other errors.", + "missing chunks and %d other errors.",
restore.getMissingChunks().size(), restore.getMissingChunks().size(),
restore.getErrorChunks().size())); restore.getErrorChunks().size()));
} }
} finally { } catch (DataException | IOException e) {
try { player.printError("Failed to load snapshot: " + e.getMessage());
chunkStore.close();
} catch (IOException ignored) {
}
} }
} }
} }

View File

@ -35,12 +35,11 @@ import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.storage.InvalidFormatException; import com.sk89q.worldedit.world.storage.InvalidFormatException;
import javax.annotation.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable;
/** /**
* The chunk format for Minecraft 1.13 and newer * The chunk format for Minecraft 1.13 and newer
*/ */
@ -160,11 +159,13 @@ public class AnvilChunk13 implements Chunk {
* @throws DataException * @throws DataException
*/ */
private void populateTileEntities() throws DataException { private void populateTileEntities() throws DataException {
tileEntities = new HashMap<>();
if (!rootTag.getValue().containsKey("TileEntities")) {
return;
}
List<Tag> tags = NBTUtils.getChildTag(rootTag.getValue(), List<Tag> tags = NBTUtils.getChildTag(rootTag.getValue(),
"TileEntities", ListTag.class).getValue(); "TileEntities", ListTag.class).getValue();
tileEntities = new HashMap<>();
for (Tag tag : tags) { for (Tag tag : tags) {
if (!(tag instanceof CompoundTag)) { if (!(tag instanceof CompoundTag)) {
throw new InvalidFormatException("CompoundTag expected in TileEntities"); throw new InvalidFormatException("CompoundTag expected in TileEntities");
@ -172,33 +173,10 @@ public class AnvilChunk13 implements Chunk {
CompoundTag t = (CompoundTag) tag; CompoundTag t = (CompoundTag) tag;
int x = 0; Map<String, Tag> values = new HashMap<>(t.getValue());
int y = 0; int x = ((IntTag) values.get("x")).getValue();
int z = 0; int y = ((IntTag) values.get("y")).getValue();
int z = ((IntTag) values.get("z")).getValue();
Map<String, Tag> values = new HashMap<>();
for (Map.Entry<String, Tag> entry : t.getValue().entrySet()) {
switch (entry.getKey()) {
case "x":
if (entry.getValue() instanceof IntTag) {
x = ((IntTag) entry.getValue()).getValue();
}
break;
case "y":
if (entry.getValue() instanceof IntTag) {
y = ((IntTag) entry.getValue()).getValue();
}
break;
case "z":
if (entry.getValue() instanceof IntTag) {
z = ((IntTag) entry.getValue()).getValue();
}
break;
}
values.put(entry.getKey(), entry.getValue());
}
BlockVector3 vec = BlockVector3.at(x, y, z); BlockVector3 vec = BlockVector3.at(x, y, z);
tileEntities.put(vec, values); tileEntities.put(vec, values);

View File

@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar; import java.util.Calendar;
import java.util.Locale;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
/** /**
@ -83,7 +84,8 @@ public class Snapshot implements Comparable<Snapshot> {
* @throws DataException * @throws DataException
*/ */
private ChunkStore internalGetChunkStore() throws IOException, DataException { private ChunkStore internalGetChunkStore() throws IOException, DataException {
if (file.getName().toLowerCase().endsWith(".zip")) { String lowerCaseFileName = file.getName().toLowerCase(Locale.ROOT);
if (lowerCaseFileName.endsWith(".zip")) {
try { try {
ChunkStore chunkStore = new TrueZipMcRegionChunkStore(file); ChunkStore chunkStore = new TrueZipMcRegionChunkStore(file);
@ -101,9 +103,9 @@ public class Snapshot implements Comparable<Snapshot> {
return chunkStore; return chunkStore;
} }
} else if (file.getName().toLowerCase().endsWith(".tar.bz2") } else if (lowerCaseFileName.endsWith(".tar.bz2")
|| file.getName().toLowerCase().endsWith(".tar.gz") || lowerCaseFileName.endsWith(".tar.gz")
|| file.getName().toLowerCase().endsWith(".tar")) { || lowerCaseFileName.endsWith(".tar")) {
try { try {
ChunkStore chunkStore = new TrueZipMcRegionChunkStore(file); ChunkStore chunkStore = new TrueZipMcRegionChunkStore(file);
@ -133,14 +135,15 @@ public class Snapshot implements Comparable<Snapshot> {
*/ */
public boolean containsWorld(String worldname) { public boolean containsWorld(String worldname) {
try { try {
if (file.getName().toLowerCase().endsWith(".zip")) { String lowerCaseFileName = file.getName().toLowerCase(Locale.ROOT);
if (lowerCaseFileName.endsWith(".zip")) {
try (ZipFile entry = new ZipFile(file)) { try (ZipFile entry = new ZipFile(file)) {
return (entry.getEntry(worldname) != null return (entry.getEntry(worldname) != null
|| entry.getEntry(worldname + "/level.dat") != null); || entry.getEntry(worldname + "/level.dat") != null);
} }
} else if (file.getName().toLowerCase().endsWith(".tar.bz2") } else if (lowerCaseFileName.endsWith(".tar.bz2")
|| file.getName().toLowerCase().endsWith(".tar.gz") || lowerCaseFileName.endsWith(".tar.gz")
|| file.getName().toLowerCase().endsWith(".tar")) { || lowerCaseFileName.endsWith(".tar")) {
try { try {
de.schlichtherle.util.zip.ZipFile entry = new de.schlichtherle.util.zip.ZipFile(file); de.schlichtherle.util.zip.ZipFile entry = new de.schlichtherle.util.zip.ZipFile(file);

View File

@ -114,6 +114,7 @@ public abstract class ChunkStore implements Closeable {
return new OldChunk(world, tag); return new OldChunk(world, tag);
} }
@Override
public void close() throws IOException { public void close() throws IOException {
} }