diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java index 90cd94ec..2cb2cc7b 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/ClipboardListener.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; @@ -65,7 +66,8 @@ public class ClipboardListener implements Listener { } try { - new SchematicData(schematic).saveFromPlayer(e.getPlayer()); + NodeData.get(schematic).forEach(NodeData::delete); + SchematicData.saveFromPlayer(e.getPlayer(), schematic); } catch (Exception ex) { if (newSchem) { schematic.delete(); diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java index 08179979..cc6f0cc9 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java @@ -23,8 +23,13 @@ import de.steamwar.sql.internal.*; import lombok.AllArgsConstructor; import lombok.Getter; +import javax.swing.plaf.nimbus.State; import java.io.*; import java.sql.PreparedStatement; +import java.sql.Timestamp; +import java.time.Instant; +import java.util.List; +import java.util.Optional; import java.util.zip.GZIPInputStream; @AllArgsConstructor @@ -40,26 +45,47 @@ public class NodeData { private static final Table table = new Table<>(NodeData.class); - private static final Statement updateDatabase = new Statement("INSERT INTO NodeData(NodeId, NodeFormat, SchemData) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE NodeFormat = VALUES(NodeFormat), SchemData = VALUES(SchemData)"); - private static final Statement selSchemData = new Statement("SELECT SchemData FROM NodeData WHERE NodeId = ?"); + private static final Statement updateDatabase = new Statement("INSERT INTO NodeData(NodeId, NodeFormat, SchemData) VALUES (?, ?, ?)", true); + private static final Statement selSchemData = new Statement("SELECT SchemData FROM NodeData WHERE NodeId = ? AND CreatedAt = ?"); + private static final Statement delete = table.delete(Table.PRIMARY); - private static final SelectStatement get = table.select(Table.PRIMARY); + private static final SelectStatement get = new SelectStatement<>(table, "SELECT NodeId, CreatedAt, NodeFormat FROM NodeData WHERE NodeId = ? ORDER BY CreatedAt "); + private static final Statement getRevisions = new Statement("SELECT COUNT(DISTINCT CreatedAt) as CNT FROM NodeData WHERE NodeId = ?"); + private static final SelectStatement getLatest = new SelectStatement<>(table, "SELECT NodeId, CreatedAt, NodeFormat FROM NodeData WHERE NodeId = ? ORDER BY CreatedAt LIMIT 1"); - public static NodeData get(SchematicNode node) { - if(node.isDir()) - throw new IllegalArgumentException("Node is a directory"); - return get.select(rs -> { - if(rs.next()) { - return new NodeData(node.getId(), SchematicFormat.values()[rs.getInt("NodeFormat")]); + public static NodeData getLatest(SchematicNode node) { + if (node.isDir()) throw new IllegalArgumentException("Node is dir"); + return Optional.ofNullable(getLatest.select(node)).orElseGet(() -> new NodeData(node.getId(), Timestamp.from(Instant.now()), SchematicFormat.MCEDIT)); + } + + public static List get(SchematicNode node) { + return get.listSelect(node); + } + + public static NodeData get(SchematicNode node, int revision) { + return get.listSelect(node).get(revision - 1); + } + + public static int getRevisions(SchematicNode node) { + return getRevisions.select(rs -> { + if (rs.next()) { + return rs.getInt("CNT"); } else { - return new NodeData(node.getId(), SchematicFormat.MCEDIT); + return 0; } }, node); } + public static void saveFromStream(SchematicNode node, InputStream blob, SchematicFormat format) { + updateDatabase.update(node.getId(), format, blob); + } + @Field(keys = {Table.PRIMARY}) private final int nodeId; + @Field + private Timestamp createdAt; + @Field private SchematicFormat nodeFormat; @@ -84,15 +110,19 @@ public class NodeData { } catch (IOException e) { throw new SecurityException("SchemData is wrong", e); } - }, nodeId); + }, nodeId, createdAt); } catch (Exception e) { throw new IOException(e); } } + @Deprecated public void saveFromStream(InputStream blob, SchematicFormat newFormat) { - updateDatabase.update(nodeId, newFormat, blob); - nodeFormat = newFormat; + saveFromStream(SchematicNode.getSchematicNode(nodeId), blob, newFormat); + } + + public void delete() { + delete.update(nodeId, createdAt); } @AllArgsConstructor diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java index 87b7cac4..531d70ef 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java @@ -407,7 +407,7 @@ public class SchematicNode { public String getFileEnding() { if (isDir()) throw new SecurityException("Node is Directory"); - return NodeData.get(this).getNodeFormat().getFileEnding(); + return NodeData.getLatest(this).getNodeFormat().getFileEnding(); } public int getRank() { diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 9a0ae4b5..072afaff 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -145,6 +145,6 @@ public class WorldeditWrapper14 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.SPONGE_V2); + SchematicData.saveFromBytes(schem, outputStream.toByteArray(), NodeData.SchematicFormat.SPONGE_V2); } } diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index d0479e46..1fdd34b7 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -140,6 +140,6 @@ public class WorldeditWrapper8 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.MCEDIT); + SchematicData.saveFromBytes(schem, outputStream.toByteArray(), NodeData.SchematicFormat.MCEDIT); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index 29ccc434..2b9548c0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -83,13 +83,7 @@ public class PrepareSchem implements Listener { return; } - if(schemExists(schem)) - return; - - SchematicNode old = schem; - schem = SchematicNode.createSchematicNode(schem.getOwner(), preparedName(schem), schem.getParent(), Config.SchematicType.checkType().toDB(), schem.getItem()); - schem.setReplaceColor(old.replaceColor()); - schem.setAllowReplay(old.allowReplay()); + schem.setSchemtype(Config.SchematicType.checkType()); try{ WorldeditWrapper.impl.saveSchem(schem, region, minY); @@ -119,20 +113,5 @@ public class PrepareSchem implements Listener { FightState.setFightState(FightState.PRE_SCHEM_SETUP); FightState.setFightState(FightState.POST_SCHEM_SETUP); } - - schemExists(SchematicNode.getSchematicNode(Config.PrepareSchemID)); - } - - private boolean schemExists(SchematicNode schem) { - if(SchematicNode.getSchematicNode(schem.getOwner(), preparedName(schem), schem.getParent()) != null) { - FightSystem.getMessage().broadcast("PREPARE_SCHEM_EXISTS"); - Bukkit.shutdown(); - return true; - } - return false; - } - - private String preparedName(SchematicNode schem) { - return schem.getName() + "-prepared"; } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 73821e6f..48cbb378 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -275,7 +275,7 @@ public interface Recorder { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try{ - copy(NodeData.get(SchematicNode.getSchematicNode(schemId)).schemData(), buffer); + copy(NodeData.getLatest(SchematicNode.getSchematicNode(schemId)).schemData(), buffer); }catch (EOFException e) { Bukkit.getLogger().log(Level.INFO, "EOFException ignored"); } catch (IOException e) { diff --git a/LegacyBauSystem/src/de/steamwar/bausystem/world/ClipboardListener.java b/LegacyBauSystem/src/de/steamwar/bausystem/world/ClipboardListener.java index 6ab68478..0ff91d44 100644 --- a/LegacyBauSystem/src/de/steamwar/bausystem/world/ClipboardListener.java +++ b/LegacyBauSystem/src/de/steamwar/bausystem/world/ClipboardListener.java @@ -53,7 +53,7 @@ public class ClipboardListener implements Listener { } try { - new SchematicData(schematic).saveFromPlayer(e.getPlayer()); + SchematicData.saveFromPlayer(e.getPlayer(), schematic); } catch (Exception ex) { if (newSchem) { schematic.delete(); diff --git a/SchematicSystem/SchematicSystem_Core/src/SchematicSystem.properties b/SchematicSystem/SchematicSystem_Core/src/SchematicSystem.properties index 29cb8829..5b8aee8f 100644 --- a/SchematicSystem/SchematicSystem_Core/src/SchematicSystem.properties +++ b/SchematicSystem/SchematicSystem_Core/src/SchematicSystem.properties @@ -26,6 +26,7 @@ CLICK_DRAG_ITEM=§7Click or drag item here CURRENT=§7Current: {0} CONFIRM=§aConfirm CANCEL=§cCancel +BLANK={0} UTIL_NAME_REQUIRED=§cFolder name required UTIL_NAME_TOO_LONG=§cSchematic name too long @@ -49,6 +50,7 @@ UTIL_LIST_NEXT=Page ({0}/{1}) »» UTIL_LIST_NEXT_HOVER=§eNext page UTIL_INFO_SCHEM=§7Schematic: §e{0} UTIL_INFO_NAME=§7Name: §e{0} +UTIL_INFO_REVISIONS=§7Revisions: §e{0} UTIL_INFO_OWNER=§7Owner: §e{0} UTIL_INFO_PARENT=§7Directory: §e{0} UTIL_INFO_UPDATED=§7Last update: §e{0} @@ -70,6 +72,7 @@ UTIL_INFO_ACTION_TYPE_HOVER=§eChange schematic type UTIL_INFO_ACTION_ADD_HOVER=§eAdd member UTIL_INFO_ACTION_REMOVE_HOVER=§eRemove {0} UTIL_INFO_ACTION_MOVE_HOVER=§eMove schematic +UTIL_INFO_ACTION_REVISIONS_HOVER=§eList revisions UTIL_INFO_ACTION_RENAME_HOVER=§eRename schematic UTIL_INFO_ACTION_DELETE=(Delete) UTIL_INFO_ACTION_DELETE_HOVER=§eDelete schematic @@ -79,6 +82,7 @@ UTIL_LOAD_DIR=§cYou cannot load folders UTIL_LOAD_DONE=§7Schematic §e{0} loaded UTIL_LOAD_NO_DATA=§cNo data could be found in the Schematic UTIL_LOAD_ERROR=§cThe schematic could not be loaded +UTIL_LOAD_ILLEGAL_REVISION=§cThe schematic doesn't have {0} revisions UTIL_DOWNLOAD_PUNISHED=§cYou are not allowed to download schematics: §f§l{0} UTIL_DOWNLOAD_NOT_OWN=§cYou may download only your own schematics UTIL_DOWNLOAD_LINK=Your download link: @@ -224,6 +228,9 @@ GUI_DELETE_MEMBER_TITLE=Remove {0} GUI_DELETE_MEMBER_DONE=Access to Schematic §e{0} §7removed GUI_DELETE_MEMBERS_TITLE=Remove members GUI_CHANGE_ITEM=Change item +GUI_LOAD_LATEST=§eLeft §7Click → §eLoad latest +GUI_LOAD_REVISION=§eRight §7Click → §eList Revisions +GUI_LOAD_REVISION_TITLE=Select Revision AUTO_CHECK_RESULT_NOT_LOAD=The schematic could not be loaded AUTO_CHECK_RESULT_TOO_WIDE=The schematic is too wide ({0} > {1}) @@ -263,4 +270,8 @@ AUTO_CHECKER_RESULT_RECORD=§7Record: §c[{0}, {1}, {2}] AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS=§7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7items, Max: §e{4} AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT=§7Forbidden Item NBT: [{0}, {1}, {2}] -> §c{3} AUTO_CHECKER_RESULT_TELEPORT_HERE=§7Teleport to block -AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cThe deadline has expired: {0} \ No newline at end of file +AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cThe deadline has expired: {0} + +REVISIONS_TITLE=§7Revisions: +REVISIONS_REVISION_NUMBER=§7#{0}: §e{1} +REVISIONS_EMPTY=§cNo Revisions \ No newline at end of file diff --git a/SchematicSystem/SchematicSystem_Core/src/SchematicSystem_de.properties b/SchematicSystem/SchematicSystem_Core/src/SchematicSystem_de.properties index 5e85d346..20205eee 100644 --- a/SchematicSystem/SchematicSystem_Core/src/SchematicSystem_de.properties +++ b/SchematicSystem/SchematicSystem_Core/src/SchematicSystem_de.properties @@ -90,6 +90,9 @@ UTIL_SUBMIT_DIRECT=§eDirekt einsenden UTIL_SUBMIT_DIRECT_DONE=§aDie Schematic wird zeitnah überprüft UTIL_SUBMIT_EXTEND=§eSchematic ausfahren UTIL_SUBMIT_EXTEND_DONE=§aDer Vorbereitungsserver wird gestartet +UTIL_INFO_ACTION_REVISIONS_HOVER=§eVersionen anzeigen +UTIL_LOAD_ILLEGAL_REVISION=§cDie schematic hat nicht {0} Versionen +UTIL_INFO_REVISIONS=§7Versionen: §e{0} COMMAND_INVALID_NODE=§cDie Schematic konnte nicht gefunden werden COMMAND_NOT_OWN=§cDas darfst du nur bei deinen eigenen Schematics machen @@ -204,6 +207,9 @@ GUI_DELETE_MEMBER_TITLE={0} entfernen GUI_DELETE_MEMBER_DONE=Zugriff zu Schematic §e{0} §7entfernt GUI_DELETE_MEMBERS_TITLE=Mitglieder entfernen GUI_CHANGE_ITEM=Item ändern +GUI_LOAD_LATEST=§eLinks §7Klick → §eLetzte Laden +GUI_LOAD_REVISION=§eRechts §7Klick → §eVersionen anzeigen +GUI_LOAD_REVISION_TITLE=Version Laden AUTO_CHECK_RESULT_NOT_LOAD=Die Schematic konnte nicht geladen werden AUTO_CHECK_RESULT_TOO_WIDE=Die Schematic ist zu breit ({0} > {1}) @@ -242,4 +248,7 @@ AUTO_CHECKER_RESULT_RECORD=§7Schallplatte: §c[{0}, {1}, {2}] AUTO_CHECKER_RESULT_TOO_MANY_DISPENSER_ITEMS=§7Dispenser: §c[{0}, {1}, {2}]§7, §c{3} §7gegenstände, Max: §e{4} AUTO_CHECKER_RESULT_FORBIDDEN_ITEM_NBT=§7Verbotene NBT-Daten: [{0}, {1}, {2}] -> §c{3} AUTO_CHECKER_RESULT_TELEPORT_HERE=§7Zum block teleportieren -AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cDer einsendeschluss ist bereits vorbei: {0} \ No newline at end of file +AUTO_CHECKER_RESULT_AFTER_DEADLINE=§cDer einsendeschluss ist bereits vorbei: {0} + +REVISIONS_TITLE=§7Versionen: +REVISIONS_EMPTY=§cKeine Versionen \ No newline at end of file diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java index 31c29bd0..3e2f009d 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/DownloadCommand.java @@ -43,7 +43,7 @@ public class DownloadCommand extends SWCommand { } try { - new SchematicData(copyNode).saveFromPlayer(player); + SchematicData.saveFromPlayer(player, copyNode); } catch (IOException e) { SchematicSystem.MESSAGE.send("DOWNLOAD_ERROR", player); if (newSchem) { diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java index 4160ad05..ec59b16d 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/GUI.java @@ -95,9 +95,28 @@ public class GUI { SteamwarUser user = getUser(player); SWInventory inv = new SWInventory(player, 9 * 2, node.generateBreadcrumbs()); if(!node.isDir()) { - inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), SchematicSystem.MESSAGE.parse("GUI_INFO_LOAD", player), click -> { - player.closeInventory(); - SchematicCommandUtils.loadSchem(player, node); + inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), SchematicSystem.MESSAGE.parse("GUI_INFO_LOAD", player), Arrays.asList( + SchematicSystem.MESSAGE.parse("GUI_LOAD_LATEST", player), + SchematicSystem.MESSAGE.parse("GUI_LOAD_REVISION", player) + ), false, click -> { + if (click.isLeftClick()) { + player.closeInventory(); + SchematicCommandUtils.loadSchem(player, node, -1); + } else if (click.isRightClick()) { + List> entries = new ArrayList<>(); + List datas = NodeData.get(node); + for (int i = 0; i < datas.size(); i++) { + entries.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial(node.getItem()), "§e" + SchematicSystem.MESSAGE.parse("BLANK", player, datas.get(i).getCreatedAt())), i)); + } + + SWListInv listInv = new SWListInv<>(player, SchematicSystem.MESSAGE.parse("GUI_LOAD_REVISION_TITLE", player, node.generateBreadcrumbs()), entries, (clickType, revision) -> { + if(revision == null) return; + player.closeInventory(); + SchematicCommandUtils.loadSchem(player, node, revision); + }); + listInv.setCallback(-999, click2 -> player.closeInventory()); + listInv.open(); + } }); } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index f92c7224..39fbd137 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -223,6 +223,11 @@ public class SchematicCommandUtils { } else { SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_PARENT", player, node.getParent() == null ? "/" : node.getParentNode().generateBreadcrumbs()); } + player.spigot().sendMessage( + new ComponentBuilder(SchematicSystem.MESSAGE.parseToComponent("UTIL_INFO_REVISIONS", false, player, NodeData.getRevisions(node))) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[] {SchematicSystem.MESSAGE.parseToComponent("UTIL_INFO_ACTION_REVISIONS_HOVER", false, player)})) + .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem revisions " + node.generateBreadcrumbs())) + .create()); SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_UPDATED", player, node.getLastUpdate()); if (!node.isDir()) { if(node.getOwner() == user.getId()) { @@ -357,7 +362,7 @@ public class SchematicCommandUtils { PUBLIC_TOGGLED.remove(player); } - public static void loadSchem(Player player, SchematicNode node) { + public static void loadSchem(Player player, SchematicNode node, int revision) { SteamwarUser user = getUser(player); if(BauServerInfo.isBauServer() && BauServerInfo.getOwnerId() != user.getId() && (Punishment.isPunished(user, Punishment.PunishmentType.NoSchemSharing, punishment -> @@ -372,11 +377,13 @@ public class SchematicCommandUtils { } try { - new SchematicData(node).loadToPlayer(player); + new SchematicData(node, revision).loadToPlayer(player); SchematicSystem.MESSAGE.send("UTIL_LOAD_DONE", player, node.getName()); Bukkit.getLogger().log(Level.INFO, "{0} has loaded Schematic {1} {2}", new Object[]{player.getName(), node.getId(), node.getName()}); } catch (NoClipboardException e) { SchematicSystem.MESSAGE.send("UTIL_LOAD_NO_DATA", player); + } catch (IllegalArgumentException e) { + SchematicSystem.MESSAGE.send("UTIL_LOAD_ILLEGAL_REVISION", player, revision); } catch (Exception e) { SchematicSystem.MESSAGE.send("UTIL_LOAD_ERROR", player); Bukkit.getLogger().log(Level.INFO, e.getMessage(), e); diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SavePart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SavePart.java index 31695f73..3ae0dd6c 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SavePart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/SavePart.java @@ -49,11 +49,11 @@ public class SavePart extends SWCommand { SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematicNode(), schematicNode -> { if(schematicNode == null || schematicNode.isDir()) { SWAnvilInv anvilInv = new SWAnvilInv(player, SchematicSystem.MESSAGE.parse("COMMAND_ENTER_NAME", player)); - anvilInv.setCallback(s -> saveSchem(player, schematicNode==null?s:(schematicNode.generateBreadcrumbs() + s), true)); + anvilInv.setCallback(s -> saveSchem(player, schematicNode==null?s:(schematicNode.generateBreadcrumbs() + s))); anvilInv.setItem(Material.CAULDRON); anvilInv.open(); } else { - saveSchem(player, schematicNode.generateBreadcrumbs(), true); + saveSchem(player, schematicNode.generateBreadcrumbs()); } }); selector.setSingleDirOpen(false); @@ -62,7 +62,7 @@ public class SavePart extends SWCommand { @Register("save") @Register("s") - public void saveSchem(Player player, @AbstractSWCommand.Mapper("stringMapper") String name, @AbstractSWCommand.StaticValue(value = {"", "-f"}, allowISE=true) @AbstractSWCommand.OptionalValue("") boolean overwrite) { + public void saveSchem(Player player, @AbstractSWCommand.Mapper("stringMapper") String name) { SteamwarUser user = getUser(player); if(BauServerInfo.isBauServer() && BauServerInfo.getOwnerId() != user.getId() && (Punishment.isPunished(user, Punishment.PunishmentType.NoSchemReceiving, punishment -> @@ -88,9 +88,6 @@ public class SavePart extends SWCommand { } else if (!node.getSchemtype().writeable() || node.getOwner() != user.getId()) { SchematicSystem.MESSAGE.send("COMMAND_SAVE_NO_OVERWRITE", player); return; - } else if(!overwrite) { - SchematicSystem.MESSAGE.send("COMMAND_SAVE_OVERWRITE_CONFIRM", player, SchematicSystem.MESSAGE.parse("COMMAND_SAVE_OVERWRITE_CONFIRM_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem s " + name + " -f"), node.generateBreadcrumbs()); - return; } } @@ -101,7 +98,7 @@ public class SavePart extends SWCommand { } try { - new SchematicData(node).saveFromPlayer(player); + SchematicData.saveFromPlayer(player, node); } catch (NoClipboardException e) { SchematicSystem.MESSAGE.send("COMMAND_SAVE_CLIPBOARD_EMPTY", player); if (newSchem) diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java index 60146d4e..c1894696 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/parts/ViewPart.java @@ -21,13 +21,23 @@ package de.steamwar.schematicsystem.commands.schematiccommand.parts; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; +import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.commands.schematiccommand.GUI; import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils; import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.List; + import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*; @AbstractSWCommand.PartOf(SchematicCommand.class) @@ -69,6 +79,25 @@ public class ViewPart extends SWCommand { printSchemInfo(player, node); } + @Register("revisions") + public void revisions(Player player, @Validator("isSchemValidator") SchematicNode node) { + List revisions = NodeData.get(node); + if(revisions.isEmpty()) { + SchematicSystem.MESSAGE.send("REVISIONS_EMPTY", player); + return; + } + + SchematicSystem.MESSAGE.send("REVISIONS_TITLE", player); + for (int j = Math.max(0, revisions.size() - 10); j < revisions.size(); j++) { + player.spigot().sendMessage( + new ComponentBuilder(SchematicSystem.MESSAGE.parseToComponent("REVISIONS_REVISION_NUMBER", false, player, j + 1, revisions.get(j).getCreatedAt())) + .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem load " + (node.getOwner() == 0 ? "public " : "") + node.generateBreadcrumbs() + " " + (j + 1))) + .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{SchematicSystem.MESSAGE.parseToComponent("UTIL_INFO_ACTION_LOAD_HOVER", false, player)})) + .create() + ); + } + } + @Register(value = "page", noTabComplete = true) public void pageCommand(Player player, int page) { cachedSchemList(player, page); @@ -76,14 +105,14 @@ public class ViewPart extends SWCommand { @Register({"l", "public"}) @Register({"load", "public"}) - public void loadSchemPublic(Player player, @Validator("isSchemValidator") @Mapper("publicMapper") SchematicNode node) { - loadSchem(player, node); + public void loadSchemPublic(Player player, @Validator("isSchemValidator") @Mapper("publicMapper") SchematicNode node, @OptionalValue("-1") int revision) { + loadSchem(player, node, revision); } @Register("l") @Register("load") - public void loadSchem(Player player, @Validator("isSchemValidator") SchematicNode node) { - SchematicCommandUtils.loadSchem(player, node); + public void loadSchem(Player player, @Validator("isSchemValidator") SchematicNode node, @OptionalValue("-1") int revision) { + SchematicCommandUtils.loadSchem(player, node, revision); } @Register("gui") diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java index 5ab944dc..53cb261d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java @@ -47,11 +47,25 @@ public class SchematicData { private final NodeData data; public SchematicData(SchematicNode node) { - this.data = NodeData.get(node); + this.data = NodeData.getLatest(node); if(node.isDir()) throw new SecurityException("Node is Directory"); } + public SchematicData(SchematicNode node, int revision) { + if(node.isDir()) + throw new SecurityException("Node is Directory"); + + if (revision < 1) { + this.data = NodeData.getLatest(node); + } else { + if (NodeData.getRevisions(node) < revision) { + throw new IllegalArgumentException("Revision " + revision + " does not exist"); + } + this.data = NodeData.get(node, revision); + } + } + public Clipboard load() throws IOException, NoClipboardException { return WorldEditWrapper.impl.getClipboard(data.schemData(), data.getNodeFormat()); } @@ -60,12 +74,12 @@ public class SchematicData { WorldEditWrapper.impl.setPlayerClipboard(player, data.schemData(), data.getNodeFormat()); } - public void saveFromPlayer(Player player) throws IOException, NoClipboardException { - data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.impl.getNativeFormat()); + public static void saveFromPlayer(Player player, SchematicNode node) throws IOException, NoClipboardException { + NodeData.saveFromStream(node, WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.impl.getNativeFormat()); } @Deprecated - public void saveFromBytes(byte[] bytes, NodeData.SchematicFormat newFormat) { - data.saveFromStream(new ByteArrayInputStream(bytes), newFormat); + public static void saveFromBytes(SchematicNode node, byte[] bytes, NodeData.SchematicFormat newFormat) { + NodeData.saveFromStream(node, new ByteArrayInputStream(bytes), newFormat); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java index 4a202368..f798d3ce 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java @@ -94,7 +94,7 @@ public class DiscordSchemUpload extends ListenerAdapter { version = NodeData.SchematicFormat.MCEDIT; } - NodeData.get(node).saveFromStream(new ByteArrayInputStream(bytes), version); + NodeData.saveFromStream(node, new ByteArrayInputStream(bytes), version); sender.system("DC_SCHEMUPLOAD_SUCCESS", name); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index ec3b54fb..7024a657 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -89,7 +89,7 @@ fun Route.configureSchematic() { return@get } - val data = NodeData.get(node) ?: run { + val data = NodeData.getLatest(node) ?: run { call.respond(HttpStatusCode.InternalServerError) return@get } @@ -166,8 +166,7 @@ fun Route.configureSchematic() { } catch (_: Exception) {} } - val data = NodeData(node.id, version) - data.saveFromStream(content.inputStream(), version) + NodeData.saveFromStream(node, content.inputStream(), version) call.respond(ResponseSchematic(node)) } catch (e: Exception) {