From 097f23d59f88b24930f9226e38cedef6402e5e9a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 24 Sep 2022 20:24:41 +0200 Subject: [PATCH] Adapt to CommonDB Signed-off-by: Lixfel --- .../fightsystem/utils/WorldeditWrapper14.java | 3 ++- .../fightsystem/utils/WorldeditWrapper8.java | 3 ++- .../fightsystem/fight/FightSchematic.java | 3 ++- .../fightsystem/record/FileSource.java | 20 +++++-------------- .../fightsystem/record/PacketProcessor.java | 3 ++- .../steamwar/fightsystem/record/Recorder.java | 3 ++- .../fightsystem/utils/FightStatistics.java | 7 +++---- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 4ee7a4d..288b89e 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -42,6 +42,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -143,6 +144,6 @@ public class WorldeditWrapper14 implements WorldeditWrapper { throw new SecurityException(e); } - schem.saveFromBytes(outputStream.toByteArray(), true); + new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), true); } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index c8588f4..19854db 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -39,6 +39,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -141,6 +142,6 @@ public class WorldeditWrapper8 implements WorldeditWrapper { throw new SecurityException(e); } - schem.saveFromBytes(outputStream.toByteArray(), false); + new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), false); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 0d3398c..6dfae63 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -31,6 +31,7 @@ import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.WorldeditWrapper; +import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.*; import org.bukkit.block.Block; @@ -70,7 +71,7 @@ public class FightSchematic extends StateDependent { public void setSchematic(SchematicNode schem) { schematic = schem.getId(); try { - clipboard = schem.load(); + clipboard = new SchematicData(schem).load(); if(schem.replaceColor()) replaceTeamColor(clipboard); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java index 6d75d2b..0536b01 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java @@ -20,10 +20,11 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; +import de.steamwar.sql.Replay; -import java.io.*; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.util.zip.GZIPInputStream; public class FileSource extends PacketSource { @@ -39,19 +40,8 @@ public class FileSource extends PacketSource { } if(Config.ReplayID > 0) { - de.steamwar.sql.Fight.getReplay(Config.ReplayID, input -> { - try { - Files.copy( - input, - FileRecorder.getFile().toPath(), - StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new SecurityException("Could not start replay", e); - } - }); - try { - new FileSource(FileRecorder.getFile()); + new FileSource(Replay.get(Config.ReplayID).getReplay()); } catch (IOException e) { throw new SecurityException("Could not start replay", e); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 734883e..007fb1a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -31,6 +31,7 @@ import de.steamwar.fightsystem.fight.FreezeWorld; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.*; +import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.Team; import de.steamwar.techhider.BlockIds; @@ -410,7 +411,7 @@ public class PacketProcessor { private void pasteEmbeddedSchem(FightTeam team) throws IOException { int schemId = source.readInt(); - Clipboard clipboard = SchematicNode.clipboardFromStream(source, Core.getVersion() > 12); + Clipboard clipboard = SchematicData.clipboardFromStream(source, Core.getVersion() > 12); execSync(() -> team.pasteSchem(schemId, clipboard)); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index eb31336..fa50526 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -29,6 +29,7 @@ import de.steamwar.fightsystem.utils.BlockIdWrapper; import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; +import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; @@ -274,7 +275,7 @@ public interface Recorder { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try{ - copy(SchematicNode.getSchematicNode(schemId).schemData(), buffer); + copy(new SchematicData(SchematicNode.getSchematicNode(schemId)).schemData(), buffer); }catch (EOFException e) { Bukkit.getLogger().log(Level.INFO, "EOFException ignored"); } catch (IOException e) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index fa61303..e15d91d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -32,18 +32,17 @@ import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.common.FightEndsPacket; +import de.steamwar.sql.Replay; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; -import java.io.FileInputStream; import java.sql.Timestamp; import java.time.Instant; import java.util.logging.Level; import java.util.stream.Collectors; import static de.steamwar.sql.Fight.create; -import static de.steamwar.sql.Fight.setReplay; public class FightStatistics { @@ -123,7 +122,7 @@ public class FightStatistics { } try { - setReplay(fightId, new FileInputStream(FileRecorder.getFile())); + Replay.save(fightId, FileRecorder.getFile()); } catch (Exception e) { Bukkit.getLogger().log(Level.INFO, "Failed to save replay", e); } @@ -132,7 +131,7 @@ public class FightStatistics { } if (!Bukkit.getOnlinePlayers().isEmpty() && !unranked) { - NetworkSender.send(new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()), gameMode)); + NetworkSender.send(new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(p -> SteamwarUser.get(p.getUniqueId())).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(p -> SteamwarUser.get(p.getUniqueId())).map(SteamwarUser::getId).collect(Collectors.toList()), gameMode)); } unranked = false;