From 612254296c9e8a39a33c0c36297ab0b31a48a708 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 29 Mar 2026 11:55:16 +0200 Subject: [PATCH] Fix WorldEditWrapper21 --- .../de/steamwar/core/WorldEditWrapper21.java | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java index b8cdba8c..35fda421 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java @@ -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;