SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Add interfaces added by commondb for seamless transition' (#217) from commonDBBridge into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #217
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2022-10-29 12:21:50 +02:00
Commit d50398ca25
3 geänderte Dateien mit 167 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,65 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.sql;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.sql.SQLException;
@AllArgsConstructor
public class Replay {
private static final Statement get = new Statement("SELECT Replay FROM Replay WHERE FightID = ?");
private static final Statement insert = new Statement("INSERT INTO Replay (FightID, Replay) VALUES (?, ?)");
public static Replay get(int fightID) {
return get.select(rs -> {
rs.next();
File file;
try {
file = File.createTempFile("replay", "replay");
file.deleteOnExit();
Files.copy(rs.getBinaryStream("Replay"), file.toPath());
} catch (IOException e) {
throw new SQLException(e);
}
return new Replay(fightID, file);
}, fightID);
}
public static void save(int fightID, File file) {
try {
insert.update(fightID, new FileInputStream(file));
} catch (FileNotFoundException e) {
throw new SecurityException("Could not save replay", e);
}
}
private final int fightID;
@Getter
private final File replay;
}

Datei anzeigen

@ -0,0 +1,98 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.sql;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core;
import de.steamwar.core.WorldEditWrapper;
import org.bukkit.entity.Player;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.util.zip.GZIPInputStream;
public class SchematicData {
public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) {
try {
return WorldEditWrapper.impl.getClipboard(is, schemFormat);
} catch (IOException e) {
throw new SecurityException("Could not read schem", e);
}
}
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;
public SchematicData(SchematicNode node) {
this.node = 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());
}
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), node.getSchemFormat());
}
public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
saveFromPlayer(player, Core.getVersion() > 12);
}
public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
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);
}
}

Datei anzeigen

@ -310,6 +310,10 @@ public class SchematicNode {
return schemFormat; return schemFormat;
} }
public void setNodeFormat(boolean format) {
schemFormat = format;
}
public int getRank() { public int getRank() {
if(isDir) if(isDir)
throw new SecurityException("Node is Directory"); throw new SecurityException("Node is Directory");