forked from SteamWar/SteamWar
Fix WorldEditWrapper21
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV3;
|
||||
import com.fastasyncworldedit.core.jnbt.NBTException;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
@@ -71,26 +72,40 @@ public class WorldEditWrapper21 implements WorldEditWrapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat ignored) throws IOException {
|
||||
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat directFormat) throws IOException {
|
||||
ResetableInputStream ris = new ResetableInputStream(is);
|
||||
for (NodeData.SchematicFormat schemFormat : NodeData.SchematicFormat.values()) {
|
||||
try {
|
||||
Clipboard clipboard = switch (schemFormat) {
|
||||
case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(ris)).read();
|
||||
case SPONGE_V2 -> new SpongeSchematicV2Reader(LinBinaryIO.read(new DataInputStream(ris))).read();
|
||||
case SPONGE_V3 -> new FastSchematicReaderV3(ris).read();
|
||||
};
|
||||
ris.close();
|
||||
return clipboard;
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
try {
|
||||
return loadSchematic(ris, directFormat);
|
||||
} catch (Exception e) {
|
||||
ris.reset();
|
||||
}
|
||||
for (NodeData.SchematicFormat schemFormat : NodeData.SchematicFormat.values()) {
|
||||
if (schemFormat == directFormat) continue;
|
||||
try {
|
||||
return loadSchematic(ris, schemFormat);
|
||||
} catch (Exception e) {
|
||||
ris.reset();
|
||||
}
|
||||
}
|
||||
try {
|
||||
return new SpongeSchematicV3Reader(LinBinaryIO.read(new DataInputStream(ris))).read();
|
||||
} catch (Exception e) {
|
||||
ris.close();
|
||||
}
|
||||
throw new IOException("No clipboard found");
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private Clipboard loadSchematic(ResetableInputStream ris, NodeData.SchematicFormat format) throws IOException {
|
||||
Clipboard clipboard = switch (format) {
|
||||
case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(ris)).read();
|
||||
case SPONGE_V2 -> new SpongeSchematicV2Reader(LinBinaryIO.read(new DataInputStream(ris))).read();
|
||||
case SPONGE_V3 -> new FastSchematicReaderV3(ris).read();
|
||||
};
|
||||
ris.close();
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
private class ResetableInputStream extends InputStream {
|
||||
|
||||
private InputStream inputStream;
|
||||
|
||||
Reference in New Issue
Block a user