From 1f9d04c8ae7fa8bc95094b964170ac7ba3b4d4e0 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 5 Aug 2022 12:58:24 +0200 Subject: [PATCH] Download Command --- .../src/SchematicSystem.properties | 3 + .../src/SchematicSystem_de.properties | 3 + .../schematicsystem/SchematicSystem.java | 3 +- .../commands/DownloadCommand.java | 65 +++++++++++++++++++ .../commands/SchematicCommandHelp.java | 3 +- 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java diff --git a/SchematicSystem_Core/src/SchematicSystem.properties b/SchematicSystem_Core/src/SchematicSystem.properties index 23e437a..c5bb454 100644 --- a/SchematicSystem_Core/src/SchematicSystem.properties +++ b/SchematicSystem_Core/src/SchematicSystem.properties @@ -144,6 +144,7 @@ HELP_VIEW_3=§8/§7schem §elist public §8- §7Shows all public schematics HELP_VIEW_4=§8/§7schem §esearch §8[§7keyword§8] - §7Searches for matching schematics HELP_VIEW_5=§8/§7schem §eload §8[§7schematic§8] - §7Loads a schematic HELP_VIEW_6=§8/§7schem §edownload §8[§7schematic§8] - §7Gives you a download link (valid for 1 min) +HELP_VIEW_7=§8/§7download §8- §7Gives you a download link for your current Clipboard (valid for 1 min) HELP_EDIT=Save & Edit HELP_EDIT_HOVER=Modification of schematics and folders HELP_EDIT_1=§8/§7schem §esave §8[§7schematic§8] - §7Saves your clipboard as a schematic @@ -210,3 +211,5 @@ SAFE_NODE_NOT_A_DIR=§cThe selected Schematic is not a folder SAFE_NODE_ALREADY_IN_DIRECTORY=§cThe schematic is already available in this folder SAFE_NODE_INVALID_NAME=§cThis name is illegal SAFE_NODE_NOT_OWNER=§cYou are not the owner of this schematic + +DOWNLOAD_ERROR=§cAn error occurred while uploading the schematic diff --git a/SchematicSystem_Core/src/SchematicSystem_de.properties b/SchematicSystem_Core/src/SchematicSystem_de.properties index 7f7e534..9846864 100644 --- a/SchematicSystem_Core/src/SchematicSystem_de.properties +++ b/SchematicSystem_Core/src/SchematicSystem_de.properties @@ -131,6 +131,7 @@ HELP_VIEW_3=§8/§7schem §elist public §8- §7Zeigt alle Public-Schematics HELP_VIEW_4=§8/§7schem §esearch §8[§7Stichwort§8] - §7Sucht nach passenden Schematics HELP_VIEW_5=§8/§7schem §eload §8[§7Schematic§8] - §7Lädt eine Schematic HELP_VIEW_6=§8/§7schem §edownload §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig) +HELP_VIEW_7=§8/§7download §8- §7Gibt dir einen Downloadlink von deinem Clipboard (1 min gültig) HELP_EDIT=Speichern & Bearbeiten HELP_EDIT_HOVER=Modifizierung von Schematics und Ordnern HELP_EDIT_1=§8/§7schem §esave §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic @@ -193,3 +194,5 @@ SAFE_NODE_NOT_A_DIR=§cDie ausgewählte Schematic ist kein Ordner SAFE_NODE_ALREADY_IN_DIRECTORY=§cDie Schematic gibt es bereits in diesem Ordner SAFE_NODE_INVALID_NAME=§cDieser Name ist unzulässig SAFE_NODE_NOT_OWNER=§cDu bist nicht der Besitzer dieser Schematic + +DOWNLOAD_ERROR=§cFehler beim Hochladen deines Clipboards diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java index 8cec6d8..844fc99 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -19,8 +19,8 @@ package de.steamwar.schematicsystem; -import de.steamwar.core.Core; import de.steamwar.message.Message; +import de.steamwar.schematicsystem.commands.DownloadCommand; import de.steamwar.schematicsystem.commands.SchematicCommand; import org.bukkit.plugin.java.JavaPlugin; @@ -34,6 +34,7 @@ public class SchematicSystem extends JavaPlugin { instance = this; new SchematicCommand(); + new DownloadCommand(); } public static SchematicSystem getInstance() { diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java new file mode 100644 index 0000000..62ca934 --- /dev/null +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java @@ -0,0 +1,65 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.schematicsystem.commands; + +import de.steamwar.command.SWCommand; +import de.steamwar.schematicsystem.SchematicSystem; +import de.steamwar.sql.NoClipboardException; +import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SchematicType; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.entity.Player; + +import java.io.IOException; + +public class DownloadCommand extends SWCommand { + public DownloadCommand() { + super("download", "/download"); + } + + @Register(help = true) + public void genericCommand(Player player, String... args) { + SteamwarUser user = SteamwarUser.get(player); + SchematicNode copyNode = SchematicNode.getSchematicNode(user.getId(), "/copy", 0); + boolean newSchem = false; + if(copyNode == null) { + copyNode = SchematicNode.createSchematicNode(user.getId(), "/copy", 0, SchematicType.Normal.toDB(), ""); + newSchem = true; + } + + try { + copyNode.saveFromPlayer(player); + } catch (IOException e) { + SchematicSystem.MESSAGE.send("DOWNLOAD_ERROR", player); + if(newSchem) { + copyNode.delete(); + } + throw new SecurityException(e); + } catch (NoClipboardException e) { + SchematicSystem.MESSAGE.send("COMMAND_SAVE_CLIPBOARD_EMPTY", player); + if(newSchem) { + copyNode.delete(); + } + return; + } + + SchematicCommandUtils.download(player, copyNode); + } +} diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java index fc2dc0d..f843dfc 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java @@ -55,7 +55,8 @@ public class SchematicCommandHelp { "HELP_VIEW_3", "HELP_VIEW_4", "HELP_VIEW_5", - "HELP_VIEW_6" + "HELP_VIEW_6", + "HELP_VIEW_7" }), BEARBEITUNG("HELP_EDIT", "HELP_EDIT_HOVER", new String[]{ "HELP_EDIT_1",