SteamWar/SpigotCore
Archiviert
13
0

Add more schematic options
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-03-14 10:36:41 +01:00
Ursprung 1eb5a87331
Commit 3fc4c104e2
3 geänderte Dateien mit 79 neuen und 50 gelöschten Zeilen

Datei anzeigen

@ -27,6 +27,7 @@ import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.*; import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
public class SQLProvider implements Provider { public class SQLProvider implements Provider {
@ -370,29 +371,33 @@ public class SQLProvider implements Provider {
deleteConfig.update(id, config); deleteConfig.update(id, config);
} }
private static final String[] nodeSelect = {"NodeId", "NodeName", "NodeOwner", "ParentNode", "NodeType", "NodeItem", "NodeRank", "NodeFormat", "LastUpdate", "ReplaceColor", "AllowReplay"};
private static String nodeSelectCreator(String itemPrefix) {
return "SELECT " + Arrays.stream(nodeSelect).map(s -> itemPrefix + s).collect(Collectors.joining(", ")) + " FROM SchematicNode ";
}
private static final Statement createNode = new Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)"); private static final Statement createNode = new Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)");
private static final Statement getSchematicNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL"); private static final Statement getSchematicNode_Null = new Statement(nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
private static final Statement getSchematicNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?"); private static final Statement getSchematicNode = new Statement(nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
private static final Statement getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL ORDER BY NodeName"); private static final Statement getSchematicsInNode_Null = new Statement(nodeSelectCreator("") + "WHERE ParentNode is NULL ORDER BY NodeName");
private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? ORDER BY NodeName"); private static final Statement getSchematicsInNode = new Statement(nodeSelectCreator("") + "WHERE ParentNode = ? ORDER BY NodeName");
private static final Statement getDirsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName"); private static final Statement getDirsInNode_Null = new Statement(nodeSelectCreator("") + "WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName");
private static final Statement getDirsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName"); private static final Statement getDirsInNode = new Statement(nodeSelectCreator("") + "WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName");
private static final Statement getSchematicDirectory_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName"); private static final Statement getSchematicDirectory_Null = new Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName");
private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName"); private static final Statement getSchematicDirectory = new Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
private static final Statement getSchematicNodeO_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL "); private static final Statement getSchematicNodeO_Null = new Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode is NULL ");
private static final Statement getSchematicNodeO = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName"); private static final Statement getSchematicNodeO = new Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
private static final Statement getSchematicNodeId = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?"); private static final Statement getSchematicNodeId = new Statement(nodeSelectCreator("") + "WHERE NodeId = ?");
private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName"); private static final Statement getAllSchemsOfTypeOwner = new Statement( nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName");
private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ? ORDER BY NodeName"); private static final Statement getAllSchemsOfType = new Statement(nodeSelectCreator("") + "WHERE NodeType = ? ORDER BY NodeName");
private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName"); private static final Statement getAccessibleByUser = new Statement(nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName");
private static final Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName"); private static final Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? UNION " + nodeSelectCreator("SN.") + "AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName");
private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName"); private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? UNION" + nodeSelectCreator("SN.") + "AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName");
private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName"); private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName");
private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName"); private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1"); private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName"); private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode"); private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?"); private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ?, ReplaceColor = ?, AllowReplay = ? WHERE NodeId = ?");
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?"); private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?"); private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?"); private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
@ -411,31 +416,25 @@ public class SQLProvider implements Provider {
return null; return null;
}; };
private static SchematicNode nodeFromResultSet(ResultSet set) throws SQLException { private static SchematicNode nodeFromResultSet(ResultSet rs) throws SQLException {
Integer parent = set.getInt("ParentNode"); Integer parent = rs.getInt("ParentNode");
if(set.wasNull()) { if(rs.wasNull()) {
parent = null; parent = null;
} }
String type = set.getString("NodeType"); String type = rs.getString("NodeType");
boolean isDir = true;
int rank = 0;
boolean schemFormat = false;
if (type != null) {
isDir = false;
rank = set.getInt("NodeRank");
schemFormat = set.getBoolean("NodeFormat");
}
return new SchematicNode( return new SchematicNode(
set.getInt("NodeId"), rs.getInt("NodeId"),
set.getInt("NodeOwner"), rs.getInt("NodeOwner"),
set.getString("NodeName"), rs.getString("NodeName"),
parent, parent,
set.getString("NodeItem"), rs.getString("NodeItem"),
type, type,
isDir, type == null,
rank, rs.getInt("NodeRank"),
set.getTimestamp("LastUpdate"), rs.getTimestamp("LastUpdate"),
schemFormat rs.getBoolean("NodeFormat"),
rs.getBoolean("ReplaceColor"),
rs.getBoolean("AllowReplay")
); );
} }
@ -581,6 +580,8 @@ public class SQLProvider implements Provider {
node.getItem(), node.getItem(),
node.getType(), node.getType(),
node.getRank(), node.getRank(),
node.replaceColor(),
node.allowReplay(),
node.getId() node.getId()
); );
} }

Datei anzeigen

@ -28,15 +28,11 @@ import org.bukkit.entity.Player;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.zip.GZIPInputStream;
public class SchematicNode { public class SchematicNode {
@ -69,7 +65,9 @@ public class SchematicNode {
boolean isDir, boolean isDir,
int rank, int rank,
Timestamp lastUpdate, Timestamp lastUpdate,
boolean schemFormat boolean schemFormat,
boolean replaceColor,
boolean allowReplay
) { ) {
this.id = id; this.id = id;
this.owner = owner; this.owner = owner;
@ -82,6 +80,8 @@ public class SchematicNode {
if (!isDir) { if (!isDir) {
this.schemFormat = schemFormat; this.schemFormat = schemFormat;
this.rank = rank; this.rank = rank;
this.replaceColor = replaceColor;
this.allowReplay = allowReplay;
} }
} }
@ -223,6 +223,8 @@ public class SchematicNode {
private Integer parent; private Integer parent;
private String item; private String item;
private String type; private String type;
private boolean replaceColor;
private boolean allowReplay;
private boolean schemFormat; private boolean schemFormat;
private int rank; private int rank;
private Timestamp lastUpdate; private Timestamp lastUpdate;
@ -322,13 +324,13 @@ public class SchematicNode {
public SchematicType getSchemtype() { public SchematicType getSchemtype() {
if(isDir()) if(isDir())
throw new RuntimeException("Is Directory"); throw new SecurityException("Is Directory");
return SchematicType.fromDB(type); return SchematicType.fromDB(type);
} }
public void setSchemtype(SchematicType type) { public void setSchemtype(SchematicType type) {
if(isDir()) if(isDir())
throw new RuntimeException("Is Directory"); throw new SecurityException("Is Directory");
this.type = type.toDB(); this.type = type.toDB();
updateDB(); updateDB();
} }
@ -492,4 +494,26 @@ public class SchematicNode {
} }
return false; return false;
} }
public boolean replaceColor() {
return replaceColor;
}
public void setReplaceColor(boolean replaceColor) {
if(isDir())
throw new SecurityException("Is Directory");
this.replaceColor = replaceColor;
updateDB();
}
public boolean allowReplay() {
return allowReplay;
}
public void setAllowReplay(boolean allowReplay) {
if(isDir())
throw new SecurityException("Is Directory");
this.allowReplay = allowReplay;
updateDB();
}
} }

Datei anzeigen

@ -230,7 +230,9 @@ public class StandaloneProvider implements Provider {
file.isDirectory(), file.isDirectory(),
0, 0,
Timestamp.from(Instant.now()), Timestamp.from(Instant.now()),
file.getName().endsWith(".schem") file.getName().endsWith(".schem"),
false,
false
); );
nodesToPath.put(node.getId(), path); nodesToPath.put(node.getId(), path);
nodeById.put(node.getId(), node); nodeById.put(node.getId(), node);
@ -270,7 +272,9 @@ public class StandaloneProvider implements Provider {
file.isDirectory(), file.isDirectory(),
0, 0,
Timestamp.from(Instant.now()), Timestamp.from(Instant.now()),
file.getName().endsWith(".schem") file.getName().endsWith(".schem"),
true,
true
); );
nodeById.put(id, node); nodeById.put(id, node);
nodesByParent.get(parent == null?-1:parent).add(node); nodesByParent.get(parent == null?-1:parent).add(node);