diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index 7fd5946..cccb5a3 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.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; 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 { @@ -70,6 +70,26 @@ 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()); }