diff --git a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java index 545825a..5849886 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/DownloadSchematic.java @@ -1,7 +1,27 @@ package de.steamwar.sql; +import org.bukkit.craftbukkit.libs.org.apache.commons.codec.digest.DigestUtils; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.time.Instant; + public class DownloadSchematic { - public DownloadSchematic(Schematic schem){ - SQL.update(""); + private DownloadSchematic(){} + + private static final String BASE = "https://steamwar.de/download.php?schem="; + + public static String getLink(Schematic schem){ + ResultSet rs = SQL.select("SELECT * FROM SchemDownload WHERE SchemID = " + schem.getSchemID()); + try { + if(rs.next()) + return BASE + rs.getString("Link"); + } catch (SQLException e) { + throw new SecurityException("Could not check schematic for existance", e); + } + + String hash = DigestUtils.sha1Hex(Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()); + SQL.update("INSERT INTO SchemDownload (SchemID, Link) VALUES (" + schem.getSchemID() + ", '" + hash + "')"); + return BASE + hash; } }