From c032baf879bf75dba9a2cbc3bfbb1529c9714271 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 24 Aug 2021 07:50:14 +0200 Subject: [PATCH] Uncompressed schem api --- .../src/de/steamwar/sql/Schematic_14.java | 5 ++--- .../src/de/steamwar/sql/Schematic_8.java | 6 +++--- .../src/de/steamwar/sql/Schematic.java | 18 +++++------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java index 3e3164f..255530f 100644 --- a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java +++ b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java @@ -54,7 +54,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; -import java.util.zip.GZIPInputStream; import static com.google.common.base.Preconditions.checkNotNull; @@ -111,9 +110,9 @@ class Schematic_14 { static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { try { if(schemFormat){ - return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(); + return new SpongeSchematicReader(new NBTInputStream(is)).read(); }else{ - return new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(); + return new MCEditSchematicReader(new NBTInputStream(is)).read(); } } catch (NullPointerException e) { throw new NoClipboardException(); diff --git a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java b/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java index 87afb82..29974ab 100644 --- a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java +++ b/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java @@ -32,6 +32,7 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; +import com.sk89q.worldedit.extent.clipboard.io.SchematicReader; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.registry.WorldData; @@ -47,7 +48,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import java.util.zip.GZIPInputStream; class Schematic_8 { private Schematic_8(){} @@ -88,9 +88,9 @@ class Schematic_8 { static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { if(schemFormat) - return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); else - return ClipboardFormat.SCHEMATIC.getReader(is).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); } private static WorldEditPlugin getWorldEditPlugin() { diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index 417fb1e..a7d8c45 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -32,6 +32,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.zip.GZIPInputStream; public class Schematic { @@ -189,7 +190,7 @@ public class Schematic { Blob schemData = rs.getBlob("SchemData"); if(schemData == null) throw new IOException("SchemData is null"); - return schemData.getBinaryStream(); + return new GZIPInputStream(schemData.getBinaryStream()); } catch (SQLException e) { throw new IOException(e); } @@ -205,18 +206,9 @@ public class Schematic { } public void loadToPlayer(Player player) throws IOException, NoClipboardException { - ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = ?", schemID); - try { - rs.next(); - Blob blob = rs.getBlob("SchemData"); - if(blob == null) - throw new NoClipboardException(); - InputStream is = blob.getBinaryStream(); - VersionedRunnable.call(new VersionedRunnable(() -> Schematic_8.setPlayerClipboard(player, is, schemFormat), 8), - new VersionedRunnable(() -> Schematic_14.setPlayerClipboard(player, is, schemFormat), 14)); - } catch (SQLException e) { - throw new IOException(e); - } + InputStream is = schemData(); + VersionedRunnable.call(new VersionedRunnable(() -> Schematic_8.setPlayerClipboard(player, is, schemFormat), 8), + new VersionedRunnable(() -> Schematic_14.setPlayerClipboard(player, is, schemFormat), 14)); } public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException {