From 23136219ddb44e0e73d1a6a35514a94e874dfe74 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 11 Oct 2021 11:25:10 +0200 Subject: [PATCH] Fix schematic Loading --- .../src/de/steamwar/sql/SchematicNode.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 74af8af..c32ae3e 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -34,6 +34,7 @@ import java.sql.Timestamp; import java.time.Instant; import java.util.*; import java.util.function.Predicate; +import java.util.zip.GZIPInputStream; public class SchematicNode { @@ -435,36 +436,29 @@ public class SchematicNode { SQL.update("DELETE FROM SchematicNode WHERE NodeId = ?", id); } - public Clipboard load() throws IOException, NoClipboardException { - if(isDir) - throw new SecurityException("Node is Directory"); + public InputStream schemData() throws IOException { ResultSet rs = SQL.select("SELECT NodeData FROM SchematicNode WHERE NodeId = ?", id); try { rs.next(); Blob schemData = rs.getBlob("NodeData"); if(schemData == null) - throw new IOException("NodeData is null"); - InputStream is = schemData.getBinaryStream(); - return WorldEditWrapper.impl.getClipboard(is, schemFormat); + throw new IOException("SchemData is null"); + return new GZIPInputStream(schemData.getBinaryStream()); } catch (SQLException e) { throw new IOException(e); } } + public Clipboard load() throws IOException, NoClipboardException { + if(isDir) + throw new SecurityException("Node is Directory"); + return WorldEditWrapper.impl.getClipboard(schemData(), schemFormat); + } + public void loadToPlayer(Player player) throws IOException, NoClipboardException { if(isDir) throw new SecurityException("Node is Directory"); - ResultSet rs = SQL.select("SELECT NodeData FROM SchematicNode WHERE NodeId = ?", id); - try { - rs.next(); - Blob blob = rs.getBlob("NodeData"); - if(blob == null) - throw new NoClipboardException(); - InputStream is = blob.getBinaryStream(); - WorldEditWrapper.impl.setPlayerClipboard(player, is, schemFormat); - } catch (SQLException e) { - throw new IOException(e); - } + WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), schemFormat); } public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException {