From 3ed64a8b60c2df109f2987b6b62c0ae03b752bb8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 16 Dec 2019 19:37:53 +0100 Subject: [PATCH] Adding SchemDownloadlink-Generator --- .../de/steamwar/sql/DownloadSchematic.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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; } }