SteamWar/SpigotCore
Archiviert
13
0

Seperate SchematicData
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Chaoscaot 2023-02-21 13:24:32 +01:00
Ursprung 4f24fe862d
Commit afb7f1c698
2 geänderte Dateien mit 7 neuen und 39 gelöschten Zeilen

@ -1 +1 @@
Subproject commit aa70f423d87e9f6534ad2dd1f20a5122179c423f Subproject commit e52e9c5ccd8ef9b87ce06d4eeeaaa4044afa89b5

Datei anzeigen

@ -36,11 +36,6 @@ import java.util.zip.GZIPInputStream;
public class SchematicData { 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) { public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) {
try { try {
return WorldEditWrapper.impl.getClipboard(is, schemFormat); 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 final NodeData data;
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
private final SchematicNode node;
public SchematicData(SchematicNode node) { public SchematicData(SchematicNode node) {
this.node = node; this.data = NodeData.get(node);
if(node.isDir()) if(node.isDir())
throw new SecurityException("Node is Directory"); 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 { 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 { 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 { 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 { 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 @Deprecated
public void saveFromBytes(byte[] bytes, boolean newFormat) { public void saveFromBytes(byte[] bytes, boolean newFormat) {
saveFromStream(new ByteArrayInputStream(bytes), newFormat); data.saveFromStream(new ByteArrayInputStream(bytes), newFormat);
}
public void saveFromStream(InputStream blob, boolean newFormat) {
updateDatabase.update(blob, newFormat, node.getId());
node.setNodeFormat(newFormat);
} }
} }