From 68155e228a23678bdbca398905968f6020942e85 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Dec 2020 21:01:03 +0100 Subject: [PATCH] Change Schematic version dependant calls --- .../src/de/steamwar/sql/Schematic_14.java | 21 ++++++++++++------- .../src/de/steamwar/sql/Schematic_8.java | 21 +++++++++++++------ .../src/de/steamwar/sql/Schematic.java | 21 +++++-------------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java index b383998..675da6e 100644 --- a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java +++ b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java @@ -64,17 +64,17 @@ class Schematic_14 { private static final ClipboardFormat SCHEMATIC = BuiltInClipboardFormat.MCEDIT_SCHEMATIC; private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC; - static byte[] getPlayerClipboard(Player player, boolean schemFormat) throws IOException, NoClipboardException { + static byte[] getPlayerClipboard(Player player, boolean schemFormat) { ClipboardHolder clipboardHolder; try { clipboardHolder = getWorldEditPlugin().getSession(player).getClipboard(); } catch (EmptyClipboardException e) { - throw new NoClipboardException(); + throw new RuntimeException(e.getMessage(), new NoClipboardException()); } Clipboard clipboard = clipboardHolder.getClipboard(); if(clipboard == null) - throw new NoClipboardException(); + throw new RuntimeException("Clipboard was null", new NoClipboardException()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try{ @@ -86,16 +86,23 @@ class Schematic_14 { SCHEMATIC.getWriter(outputStream).write(clipboard); } }catch(NullPointerException e){ - throw new IOException(e); + throw new RuntimeException(e.getMessage(), new IOException(e)); + } catch (IOException e) { + throw new RuntimeException(e.getMessage(), e); } return outputStream.toByteArray(); } - static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) throws IOException, NoClipboardException { - Clipboard clipboard = getClipboard(is, schemFormat); + static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) { + Clipboard clipboard = null; + try { + clipboard = getClipboard(is, schemFormat); + } catch (IOException | NoClipboardException e) { + throw new RuntimeException(e.getMessage(), e); + } if (clipboard == null) - throw new NoClipboardException(); + throw new RuntimeException("clipboard was null", new NoClipboardException()); Actor actor = getWorldEditPlugin().wrapCommandSender(player); getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard)); diff --git a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java b/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java index 1ae9881..8578007 100644 --- a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java +++ b/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java @@ -52,26 +52,35 @@ import java.util.zip.GZIPInputStream; class Schematic_8 { private Schematic_8(){} - static byte[] getPlayerClipboard(Player player) throws IOException, NoClipboardException { + static byte[] getPlayerClipboard(Player player) { ClipboardHolder clipboardHolder; try { clipboardHolder = getWorldEditPlugin().getSession(player).getClipboard(); } catch (EmptyClipboardException e) { - throw new NoClipboardException(); + throw new RuntimeException(e.getMessage(), e); } Clipboard clipboard = clipboardHolder.getClipboard(); if(clipboard == null) - throw new NoClipboardException(); + throw new RuntimeException("clipboard was null", new NoClipboardException()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData()); + try { + ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData()); + } catch (IOException e) { + throw new RuntimeException(e.getMessage(), e); + } return outputStream.toByteArray(); } - static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) throws IOException { + static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) { WorldData world = new BukkitWorld(player.getWorld()).getWorldData(); - Clipboard clipboard = getClipboard(is, schemFormat); + Clipboard clipboard; + try { + clipboard = getClipboard(is, schemFormat); + } catch (IOException e) { + throw new RuntimeException(e); + } Actor actor = getWorldEditPlugin().wrapCommandSender(player); getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard, world)); diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index ed589a7..4be00c8 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -205,19 +205,8 @@ public class Schematic { if(blob == null) throw new NoClipboardException(); InputStream is = blob.getBinaryStream(); - VersionedRunnable.call(new VersionedRunnable(() -> { - try { - Schematic_8.setPlayerClipboard(player, is, schemFormat); - } catch (IOException exception) { - throw new RuntimeException(exception.getMessage(), exception); - } - }, 8), new VersionedRunnable(() -> { - try { - Schematic_14.setPlayerClipboard(player, is, schemFormat); - } catch (IOException | NoClipboardException exception) { - throw new RuntimeException(exception.getMessage(), exception); - } - }, 14)); + 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); } @@ -236,15 +225,15 @@ public class Schematic { VersionedRunnable.call(new VersionedRunnable(() -> { try { blob.setBytes(1, Schematic_8.getPlayerClipboard(player)); - } catch (IOException | NoClipboardException | SQLException e) { + } catch (SQLException e) { throw new RuntimeException(e.getMessage(), 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); + } catch (SQLException exception) { + throw new RuntimeException(exception.getMessage(), exception); } updateDatabase(blob, player, newFormat); }, 14));