From 75c9c6bb1e4632bd8e9b178f978cbf4b45545c97 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 11:23:12 +0100 Subject: [PATCH 1/3] Add Deprecation and NodePathParser Signed-off-by: Chaoscaot --- .../src/de/steamwar/sql/SchematicNode.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 1054b90..56dfcff 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -37,6 +37,7 @@ import java.time.Instant; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; +import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; public class SchematicNode { @@ -309,6 +310,45 @@ public class SchematicNode { }, node); } + public static SchematicNode getNodeFromPath(SteamwarUser user, String s) { + if (s.startsWith("/")) { + s = s.substring(1); + } + if (s.isEmpty()) { + return null; + } + if (s.contains("/")) { + String[] layers = s.split("/"); + SchematicNode currentNode = null; + for (int i = 0; i < layers.length; i++) { + int finalI = i; + Optional node; + if (currentNode == null) { + node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny(); + } else { + node = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny(); + } + if (!node.isPresent()) { + return null; + } else { + currentNode = node.get(); + if (!currentNode.isDir() && i != layers.length - 1) { + return null; + } + } + } + return currentNode; + } else { + String finalS = s; + List nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(finalS)).collect(Collectors.toList()); + if (nodes.isEmpty()) { + return null; + } else { + return nodes.get(0); + } + } + } + private final int id; private final int owner; private String name; @@ -378,12 +418,14 @@ public class SchematicNode { updateDB(); } + @Deprecated public String getType() { if(isDir) throw new SecurityException("Node is Directory"); return type; } + @Deprecated public void setType(String type) { if(isDir) throw new SecurityException("Node is Directory"); @@ -419,6 +461,13 @@ public class SchematicNode { return SchematicType.fromDB(type); } + public void setSchemtype(SchematicType type) { + if(isDir()) + throw new RuntimeException("Is Directory"); + this.type = type.toDB(); + updateDB(); + } + public SchematicNode getParentNode() { if(parent == null) return null; return SchematicNode.getSchematicNode(parent); From 42b4ccad2257f3a080eca82e4968be78b3914760 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 11:23:57 +0100 Subject: [PATCH 2/3] Remove Unused Imports Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 56dfcff..1ed2e94 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -21,8 +21,6 @@ package de.steamwar.sql; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; -import de.steamwar.core.VersionedRunnable; import de.steamwar.core.WorldEditWrapper; import org.bukkit.entity.Player; @@ -35,7 +33,6 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.time.Instant; import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; From 802cd6c862c145e48f8682bcbdf8d94927dd29fa Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 11:25:22 +0100 Subject: [PATCH 3/3] Remove Unused Imports Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 1ed2e94..82f1ad1 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -34,7 +34,6 @@ import java.sql.Timestamp; import java.time.Instant; import java.util.*; import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; public class SchematicNode { @@ -337,12 +336,7 @@ public class SchematicNode { return currentNode; } else { String finalS = s; - List nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(finalS)).collect(Collectors.toList()); - if (nodes.isEmpty()) { - return null; - } else { - return nodes.get(0); - } + return SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(finalS)).findAny().orElse(null); } }