diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java index 9957695..5e15684 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java @@ -1,10 +1,10 @@ package de.steamwar.schematicsystem; -import de.steamwar.schematicsystem.commands.SchematicCommandUtils; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +import lombok.AllArgsConstructor; import lombok.NonNull; -import org.bukkit.Material; +import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; @@ -13,6 +13,9 @@ import java.util.List; public class SafeSchematicNode { public static Result setParent(@NonNull SteamwarUser user, @NonNull SchematicNode node, SchematicNode newParent) { + if(user.getId() != node.getId()) { + return Result.NOT_OWNER; + } if(newParent == null) { if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0) .stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { @@ -36,6 +39,10 @@ public class SafeSchematicNode { } public static Result setName(@NonNull SteamwarUser user, @NonNull SchematicNode node, @NonNull String name) { + if(user.getId() != node.getId()) { + return Result.NOT_OWNER; + } + if(invalidSchemName(name)) { return Result.INVALID_NAME; } @@ -48,10 +55,6 @@ public class SafeSchematicNode { return Result.DONE; } - public static Result setItem(@NonNull SteamwarUser user, @NonNull SchematicNode node, @NonNull Material material) { - - } - private static final List FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public")); public static boolean invalidSchemName(String name) { if (name.isEmpty()) { @@ -74,11 +77,19 @@ public class SafeSchematicNode { return FORBIDDEN_NAMES.contains(name.toLowerCase()); } + @AllArgsConstructor public enum Result { - DONE, - NOT_A_DIR, - ALREADY_IN_DIRECTORY, - INVALID_NAME; + DONE("No"), + NOT_A_DIR(SchematicSystem.PREFIX + "§cDie ausgewählte Schematic ist kein Ordner"), + ALREADY_IN_DIRECTORY(SchematicSystem.PREFIX + "§cDie Schematic gibt es bereits in diesem Ordner"), + INVALID_NAME(SchematicSystem.PREFIX + "§cDieser Name ist unzulässig"), + NOT_OWNER(SchematicSystem.PREFIX + "§cDu bist nicht der Besitzer dieser Schematic"); + + private String errorMessage; + + public void sendError(Player player) { + player.sendMessage(errorMessage); + } public boolean isSuccessful() { return this == DONE; diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java index ea47d1b..fbabed5 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java @@ -20,6 +20,7 @@ package de.steamwar.schematicsystem.commands; import de.steamwar.inventory.*; +import de.steamwar.schematicsystem.SafeSchematicNode; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; import org.bukkit.Material; @@ -102,8 +103,12 @@ public class GUI { inv.setItem(5, skull); inv.setItem(6, Material.ARROW, "§eVerschieben", clickType -> { SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> { - node.setParent(npar==null?null:npar.getId()); - info(player, SchematicNode.getSchematicNode(node.getId())); + SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, npar); + if(result.isSuccessful()) { + info(player, SchematicNode.getSchematicNode(node.getId())); + } else { + result.sendError(player); + } }); selector.open(); }); @@ -112,10 +117,12 @@ public class GUI { SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen", node.getName()); anvilInv.setItem(finalMat); anvilInv.setCallback(s -> { - if (!invalidSchemName(player, new String[]{s})) { - node.setName(s); + SafeSchematicNode.Result result = SafeSchematicNode.setName(user, node, s); + if(result.isSuccessful()) { + info(player, node); + } else { + result.sendError(player); } - info(player, node); }); anvilInv.open(); });