From ca5b271f65b0bf2deb5db95ab736401efc179aaf Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Feb 2023 11:03:19 +0100 Subject: [PATCH 1/2] Add Overwrite Warning --- .../src/SchematicSystem.properties | 2 ++ .../src/SchematicSystem_de.properties | 2 ++ .../commands/SchematicCommand.java | 24 ++++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/SchematicSystem_Core/src/SchematicSystem.properties b/SchematicSystem_Core/src/SchematicSystem.properties index 9932bdd..60acc26 100644 --- a/SchematicSystem_Core/src/SchematicSystem.properties +++ b/SchematicSystem_Core/src/SchematicSystem.properties @@ -118,6 +118,8 @@ COMMAND_SAVE_CLIPBOARD_EMPTY=§cYour clipboard is empty COMMAND_SAVE_ERROR=§cError while saving the Schematic COMMAND_SAVE_DONE=Schematic §e{0} §7stored COMMAND_SAVE_OVERWRITE=Schematic §e{0} §7overwritten +COMMAND_SAVE_OVERWRITE_CONFIRM=§cThe Schematic §e{0} §calready exists. Do you want to overwrite it? §e*click* +COMMAND_SAVE_OVERWRITE_CONFIRM_HOVER=§eOverwrite Schematic COMMAND_ADD_PUNISH=§cYou may not add anyone to your schematics: §f§l{0} COMMAND_ADD_USER_PUNISHED=§c{0} must not be added to schematics COMMAND_ADD_OWN=§cSo please: This is your own Schematic! diff --git a/SchematicSystem_Core/src/SchematicSystem_de.properties b/SchematicSystem_Core/src/SchematicSystem_de.properties index 465b0f7..e3c1d9a 100644 --- a/SchematicSystem_Core/src/SchematicSystem_de.properties +++ b/SchematicSystem_Core/src/SchematicSystem_de.properties @@ -103,6 +103,8 @@ COMMAND_SAVE_CLIPBOARD_EMPTY=§cDein Clipboard ist leer COMMAND_SAVE_ERROR=§cFehler beim Speichern der Schematic COMMAND_SAVE_DONE=Schematic §e{0} §7gespeichert COMMAND_SAVE_OVERWRITE=Schematic §e{0} §7überschrieben +COMMAND_SAVE_OVERWRITE_CONFIRM=§cDie Schematic §e{0} §7existiert bereits. Möchtest du sie überschreiben? §e*klick* +COMMAND_SAVE_OVERWRITE_CONFIRM_HOVER=§eSchematic überschreiben COMMAND_ADD_PUNISH=§cDu darfst niemanden auf deine Schematics hinzufügen: §f§l{0} COMMAND_ADD_USER_PUNISHED=§c{0} darf nicht auf Schematics hinzugefügt werden COMMAND_ADD_OWN=§cAlso bitte: Das ist deine eigene Schematic! diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 1d752f2..84e388e 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -148,11 +148,11 @@ public class SchematicCommand extends SWCommand { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); 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))); + anvilInv.setCallback(s -> saveSchem(player, schematicNode==null?s:(schematicNode.generateBreadcrumbs() + s), true)); anvilInv.setItem(Material.CAULDRON); anvilInv.open(); } else { - saveSchem(player, schematicNode.generateBreadcrumbs()); + saveSchem(player, schematicNode.generateBreadcrumbs(), true); } }); selector.setSingleDirOpen(false); @@ -161,7 +161,7 @@ public class SchematicCommand extends SWCommand { @Register("save") @Register("s") - public void saveSchem(Player player, @Mapper("dirStringMapper") String name) { + public void saveSchem(Player player, @Mapper("stringMapper") String name, @OptionalValue("false") boolean overwrite) { SteamwarUser user = getUser(player); if(BauServerInfo.isBauServer() && BauServerInfo.getOwnerId() != user.getId() && (Punishment.isPunished(user, Punishment.PunishmentType.NoSchemReceiving, punishment -> @@ -187,6 +187,9 @@ public class SchematicCommand 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 + " true"), node.generateBreadcrumbs()); + return; } } @@ -759,6 +762,21 @@ public class SchematicCommand extends SWCommand { }; } + @Mapper("stringMapper") + public TypeMapper stringMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + } + + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s; + } + }; + } + @ClassMapper(SchematicType.class) public TypeMapper typeTypeMapper() { return new TypeMapper() { -- 2.39.2 From f6bba7eaea00bdbabab05debab920eb7fd4b14a9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 20 Feb 2023 11:11:42 +0100 Subject: [PATCH 2/2] Fixes --- .../steamwar/schematicsystem/commands/SchematicCommand.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 84e388e..4443853 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -161,7 +161,7 @@ public class SchematicCommand extends SWCommand { @Register("save") @Register("s") - public void saveSchem(Player player, @Mapper("stringMapper") String name, @OptionalValue("false") boolean overwrite) { + public void saveSchem(Player player, @Mapper("stringMapper") String name, @StaticValue(value = {"", "-f"}, allowISE=true) @OptionalValue("") boolean overwrite) { SteamwarUser user = getUser(player); if(BauServerInfo.isBauServer() && BauServerInfo.getOwnerId() != user.getId() && (Punishment.isPunished(user, Punishment.PunishmentType.NoSchemReceiving, punishment -> @@ -767,7 +767,9 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + List list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + list.add(s); + return list; } @Override -- 2.39.2