From afb7f1c69841e7b1e44d388e090bd8193ac2203a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 21 Feb 2023 13:24:32 +0100 Subject: [PATCH] Seperate SchematicData --- CommonCore | 2 +- .../src/de/steamwar/sql/SchematicData.java | 44 +++---------------- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/CommonCore b/CommonCore index aa70f42..e52e9c5 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit aa70f423d87e9f6534ad2dd1f20a5122179c423f +Subproject commit e52e9c5ccd8ef9b87ce06d4eeeaaa4044afa89b5 diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java index 87b6708..ecbf86a 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java @@ -36,11 +36,6 @@ import java.util.zip.GZIPInputStream; public class SchematicData { - static { - new SqlTypeMapper<>(PipedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("PipedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); - new SqlTypeMapper<>(ByteArrayInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("ByteArrayInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); - } - public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) { try { return WorldEditWrapper.impl.getClipboard(is, schemFormat); @@ -49,42 +44,20 @@ public class SchematicData { } } - private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?"); - private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?"); - - private final SchematicNode node; + private final NodeData data; public SchematicData(SchematicNode node) { - this.node = node; + this.data = NodeData.get(node); if(node.isDir()) throw new SecurityException("Node is Directory"); } - public InputStream schemData() throws IOException { - try { - return selSchemData.select(rs -> { - rs.next(); - Blob schemData = rs.getBlob("NodeData"); - if(schemData == null) { - throw new SecurityException("SchemData is null"); - } - try { - return new GZIPInputStream(schemData.getBinaryStream()); - } catch (IOException e) { - throw new SecurityException("SchemData is wrong", e); - } - }, node.getId()); - } catch (Exception e) { - throw new IOException(e); - } - } - public Clipboard load() throws IOException, NoClipboardException { - return WorldEditWrapper.impl.getClipboard(schemData(), node.getSchemFormat()); + return WorldEditWrapper.impl.getClipboard(data.schemData(), data.getNodeFormat()); } public void loadToPlayer(Player player) throws IOException, NoClipboardException { - WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), node.getSchemFormat()); + WorldEditWrapper.impl.setPlayerClipboard(player, data.schemData(), data.getNodeFormat()); } public void saveFromPlayer(Player player) throws IOException, NoClipboardException { @@ -92,16 +65,11 @@ public class SchematicData { } public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException { - saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat); + data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat); } @Deprecated public void saveFromBytes(byte[] bytes, boolean newFormat) { - saveFromStream(new ByteArrayInputStream(bytes), newFormat); - } - - public void saveFromStream(InputStream blob, boolean newFormat) { - updateDatabase.update(blob, newFormat, node.getId()); - node.setNodeFormat(newFormat); + data.saveFromStream(new ByteArrayInputStream(bytes), newFormat); } }