From 2c0c75e6ea28c65635b670eb2121fe03eaa09933 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 19:12:24 +0100 Subject: [PATCH] Change Schematic version dependant calls --- .../src/de/steamwar/sql/Schematic.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index b74a253..ed589a7 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -20,7 +20,6 @@ package de.steamwar.sql; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import de.steamwar.core.Core; import de.steamwar.core.VersionedCallable; import de.steamwar.core.VersionedRunnable; import org.bukkit.entity.Player; @@ -233,26 +232,27 @@ public class Schematic { } private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException { - try{ - Blob blob = SQL.blob(); - switch(Core.getVersion()){ - case 8: - case 9: - case 10: - case 12: - newFormat = false; - blob.setBytes(1, Schematic_8.getPlayerClipboard(player)); - break; - case 14: - case 15: - default: - blob.setBytes(1, Schematic_14.getPlayerClipboard(player, newFormat)); + Blob blob = SQL.blob(); + VersionedRunnable.call(new VersionedRunnable(() -> { + try { + blob.setBytes(1, Schematic_8.getPlayerClipboard(player)); + } catch (IOException | NoClipboardException | SQLException e) { + throw new RuntimeException(e.getMessage(), e); } - SQL.update("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = ?", blob, newFormat, schemID); - schemFormat = newFormat; - }catch(SQLException e){ - throw new IOException(e); - } + updateDatabase(blob, player, false); + }, 8), new VersionedRunnable(() -> { + try { + blob.setBytes(1, Schematic_14.getPlayerClipboard(player, newFormat)); + } catch (IOException | NoClipboardException | SQLException e) { + throw new RuntimeException(e.getMessage(), e); + } + updateDatabase(blob, player, newFormat); + }, 14)); + } + + private void updateDatabase(Blob blob, Player player, boolean newFormat) { + SQL.update("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = ?", blob, newFormat, schemID); + schemFormat = newFormat; } public void remove(){