diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 58ff88d..12f0c90 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -30,6 +30,7 @@ import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; +import java.util.function.Predicate; public class SchematicNode { @@ -184,7 +185,8 @@ public class SchematicNode { } public static List getSchematicsOfType(int owner, String schemType, Integer parent) { - List schems = getAllSchematicsOfType(owner, schemType); + List schems = getAllSchematicsAccessibleByUser(owner); + schems.removeIf(node -> !node.getType().equals(schemType)); Map nodesInParent = new LinkedHashMap<>(); for (SchematicNode schematicNode : schems) { SchematicNode currentNode = schematicNode; @@ -222,7 +224,7 @@ public class SchematicNode { throw new SecurityException("Failed listing schematics", e); } } - return null; + return Collections.emptyList(); } public static List getAllSchematicsAccessibleByUser(int user) { @@ -237,15 +239,29 @@ public class SchematicNode { } } + public static List deepGet(Integer parent, Predicate filter) { + List finalList = new ArrayList<>(); + List nodes = SchematicNode.getSchematicNodeInNode(parent); + nodes.forEach(node -> { + if(node.isDir()) { + finalList.addAll(deepGet(node.getId(), filter)); + }else { + if(filter.test(node)) + finalList.add(node); + } + }); + return finalList; + } + private final int id; private final int owner; private String name; - private int parent; + private Integer parent; private String item; private String type; private boolean schemFormat; private int rank; - private boolean isDir; + private final boolean isDir; private SchematicNode(ResultSet set) throws SQLException { id = set.getInt("NodeId"); @@ -353,7 +369,7 @@ public class SchematicNode { private void updateDB() { SQL.update("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?", - name, owner, parent, item, type, rank, id); + name, owner, parent == 0?null:parent, item, type, rank, id); } public void delete() {