SteamWar/SpigotCore
Archiviert
13
0

Change Schematic version dependant calls

Dieser Commit ist enthalten in:
jojo 2020-12-25 21:01:03 +01:00
Ursprung 2c0c75e6ea
Commit 68155e228a
3 geänderte Dateien mit 34 neuen und 29 gelöschten Zeilen

Datei anzeigen

@ -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));

Datei anzeigen

@ -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));

Datei anzeigen

@ -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));