From 4fa02974808618c9cd4daacf4ce8271cdfb9f68b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 11 Dec 2019 22:34:46 +0100 Subject: [PATCH] Fixing Schematic RAM leak and 1.14 support --- .../src/de/steamwar/sql/Schematic_14.java | 3 +- .../src/de/steamwar/sql/Schematic.java | 32 ++++--------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java index 8320c36..3dbf695 100644 --- a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java +++ b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java @@ -1,6 +1,5 @@ package de.steamwar.sql; -import com.boydti.fawe.FaweAPI; import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extension.platform.Actor; @@ -23,7 +22,7 @@ class Schematic_14 { static byte[] getPlayerClipboard(Player player, boolean schemFormat) throws IOException, NoClipboardException { ClipboardHolder clipboardHolder; try { - clipboardHolder = FaweAPI.wrapPlayer(player).getSession().getClipboard(); + clipboardHolder = WorldEditPlugin.getInstance().getSession(player).getClipboard(); } catch (EmptyClipboardException e) { throw new NoClipboardException(); } diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index 92565fc..255d5e2 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -2,17 +2,17 @@ package de.steamwar.sql; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import java.util.logging.Level; public class Schematic { @@ -55,7 +55,7 @@ public class Schematic { public static Schematic getSchemFromDB(String schemName, int schemOwner){ schemName = SQL.disarmString(schemName); - ResultSet schematic = SQL.select("SELECT * FROM Schematic WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'"); + ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'"); try { if(schematic == null || !schematic.next()){ SchematicMember member = SchematicMember.getMemberBySchematic(schemName, schemOwner); @@ -70,33 +70,13 @@ public class Schematic { } } - public static void convertAllSchematics(){ - try{ - PreparedStatement ps = SQL.getCon().prepareStatement("SELECT SchemName, SchemOwner FROM Schematic"); - ResultSet allSchems = ps.executeQuery(); - while(allSchems.next()){ - int schemOwner = allSchems.getInt("SchemOwner"); - String schemName = allSchems.getString("SchemName"); - try{ - PreparedStatement st = SQL.getCon().prepareStatement("UPDATE Schematic SET SchemData = ? WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "'"); - st.setBlob(1, new FileInputStream("/home/minecraft/schematics/" + SteamwarUser.get(schemOwner).getUUID().toString() + "/" + schemName + ".schematic")); - st.executeUpdate(); - }catch(FileNotFoundException e){ - Bukkit.getLogger().log(Level.WARNING, "Could not convert Schematic " + schemOwner + " " + schemName + " due to missing file."); - } - } - }catch(SQLException e){ - throw new SecurityException("Schematic Conversation failed", e); - } - } - public static List getSchemsAccessibleByUser(UUID schemOwner){ return getSchemsAccessibleByUser(SteamwarUser.get(schemOwner).getId()); } public static List getSchemsAccessibleByUser(int schemOwner){ try{ - ResultSet schematic = SQL.select("SELECT * FROM Schematic WHERE SchemOwner = '" + schemOwner + "'"); + ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemOwner = '" + schemOwner + "'"); List schematics = new ArrayList<>(); while(schematic.next()){ schematics.add(new Schematic(schematic)); @@ -126,7 +106,7 @@ public class Schematic { public static List getAllSchemsOfType(SchematicType schemType){ try{ - ResultSet schematic = SQL.select("SELECT * FROM Schematic WHERE SchemType = '" + schemType.toDB() + "'"); + ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemType = '" + schemType.toDB() + "'"); List schematics = new ArrayList<>(); while(schematic.next()){ schematics.add(new Schematic(schematic));