From 4496cd8b0a4a4aba70b1363156a2317f63248aa9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 4 Mar 2021 03:06:34 +0100 Subject: [PATCH 1/6] Changing to Schemnodes --- .../bungeecore/commands/CheckCommand.java | 74 ++-- .../bungeecore/inventory/SWListInv.java | 23 -- .../bungeecore/listeners/CheckListener.java | 6 +- .../bungeecore/sql/CheckedSchematic.java | 20 +- .../steamwar/bungeecore/sql/NodeMember.java | 87 +++++ src/de/steamwar/bungeecore/sql/Schematic.java | 141 ------- .../bungeecore/sql/SchematicMember.java | 134 ------- .../bungeecore/sql/SchematicNode.java | 359 ++++++++++++++++++ 8 files changed, 497 insertions(+), 347 deletions(-) create mode 100644 src/de/steamwar/bungeecore/sql/NodeMember.java delete mode 100644 src/de/steamwar/bungeecore/sql/Schematic.java delete mode 100644 src/de/steamwar/bungeecore/sql/SchematicMember.java create mode 100644 src/de/steamwar/bungeecore/sql/SchematicNode.java diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 9aaed515..bd268ec5 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.sql.CheckedSchematic; -import de.steamwar.bungeecore.sql.Schematic; +import de.steamwar.bungeecore.sql.SchematicNode; import de.steamwar.bungeecore.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ChatColor; @@ -66,7 +66,7 @@ public class CheckCommand extends BasicCommand { super("check", ConnectionListener.CHECK_PERMISSION); ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { - List schematics = getSchemsToCheck(); + List schematics = getSchemsToCheck(); if(schematics.size() != currentCheckers.size()) Message.team("CHECK_REMINDER", schematics.size() - currentCheckers.size()); }, 10, 10, TimeUnit.MINUTES); @@ -105,33 +105,33 @@ public class CheckCommand extends BasicCommand { } } - private static List getSchemsToCheck(){ - List schematicList = new LinkedList<>(); + private static List getSchemsToCheck(){ + List schematicList = new LinkedList<>(); for (SchematicType type : SchematicType.values()) { if (type.check()) - schematicList.addAll(Schematic.getAllSchemsOfType(type)); + schematicList.addAll(SchematicNode.getAllSchematicsOfType(type.toDB())); } return schematicList; } private void list(ProxiedPlayer player) { - List schematicList = getSchemsToCheck(); + List schematicList = getSchemsToCheck(); Message.sendPrefixless("CHECK_LIST_HEADER", player, schematicList.size()); - for (Schematic schematic : schematicList) { - CheckSession current = currentSchems.get(schematic.getSchemID()); + for (SchematicNode schematic : schematicList) { + CheckSession current = currentSchems.get(schematic.getId()); if (current == null) { Message.sendPrefixless("CHECK_LIST_TO_CHECK", player, Message.parse("CHECK_LIST_TO_CHECK_HOVER", player), - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getSchemID()), - schematic.getSchemType().getKuerzel(), SteamwarUser.get(schematic.getSchemOwner()).getUserName(), schematic.getSchemName()); + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getId()), + schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName()); } else { Message.sendPrefixless("CHECK_LIST_CHECKING", player, Message.parse("CHECK_LIST_CHECKING_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()), - schematic.getSchemType().getKuerzel(), SteamwarUser.get(schematic.getSchemOwner()).getUserName(), schematic.getSchemName(), current.checker.getName()); + schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.getName()); } } } @@ -142,11 +142,11 @@ public class CheckCommand extends BasicCommand { return; } - Schematic schem = Schematic.getSchemFromDB(Integer.parseInt(schemID)); - if(!schem.getSchemType().check()){ + SchematicNode schem = SchematicNode.getSchematicNode(Integer.parseInt(schemID)); + if(!schem.getSchemtype().check()){ ProxyServer.getInstance().getLogger().log(Level.SEVERE, player.getName() + " tried to check an uncheckable schematic!"); return; - }else if(schem.getSchemOwner() == SteamwarUser.get(player.getUniqueId()).getId()) { + }else if(schem.getOwner() == SteamwarUser.get(player.getUniqueId()).getId()) { Message.send("CHECK_SCHEMATIC_OWN", player); return; } @@ -212,15 +212,15 @@ public class CheckCommand extends BasicCommand { private static class CheckSession{ private final ProxiedPlayer checker; - private final Schematic schematic; + private final SchematicNode schematic; private final Timestamp startTime; private final ListIterator checkList; - private CheckSession(ProxiedPlayer checker, Schematic schematic){ + private CheckSession(ProxiedPlayer checker, SchematicNode schematic){ this.checker = checker; this.schematic = schematic; this.startTime = Timestamp.from(Instant.now()); - this.checkList = checkQuestions.get(schematic.getSchemType()).listIterator(); + this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator(); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { for (Subserver subserver : Subserver.getServerList()) { @@ -230,11 +230,11 @@ public class CheckCommand extends BasicCommand { } } - ArenaMode mode = ArenaMode.getByCheckSchemType(schematic.getSchemType().toDB()); - SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID()); + //ArenaMode mode = ArenaMode.getByCheckSchemType(schematic.getSchemtype().toDB()); + //SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getId()); currentCheckers.put(checker.getUniqueId(), this); - currentSchems.put(schematic.getSchemID(), this); - for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getSchemName(), schematic.getSchemOwner())) + currentSchems.put(schematic.getId(), this); + for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getId())) Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getReason()); next(0); }); @@ -253,8 +253,8 @@ public class CheckCommand extends BasicCommand { if(checkList.hasNext()){ next.setText(Message.parse("CHECK_NEXT", checker)); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next")); - }else if(ranks.containsKey(schematic.getSchemType())){ - List r = ranks.get(schematic.getSchemType()); + }else if(ranks.containsKey(schematic.getSchemtype())){ + List r = ranks.get(schematic.getSchemtype()); for(int i = 0; i < r.size(); i++){ Message.sendPrefixless("CHECK_RANK", checker, Message.parse("CHECK_RANK_HOVER", checker), @@ -276,43 +276,43 @@ public class CheckCommand extends BasicCommand { } private void accept(int rank){ - if(ranks.containsKey(schematic.getSchemType())){ - if(rank <= 0 || ranks.get(schematic.getSchemType()).size() < rank){ + if(ranks.containsKey(schematic.getSchemtype())){ + if(rank <= 0 || ranks.get(schematic.getSchemtype()).size() < rank){ Message.send("CHECK_INVALID_RANK", checker); return; } schematic.setRank(rank); } - schematic.setSchemType(schematic.getSchemType().fightType()); - CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); - SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner()); + schematic.setType(schematic.getSchemtype().fightType().toDB()); + CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); + SteamwarUser user = SteamwarUser.get(schematic.getOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); if(player != null) - Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName()); - Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName()); + Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName()); + Message.team("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName()); stop(); } private void decline(String reason){ - schematic.setSchemType(SchematicType.Normal); - CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); - SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner()); + schematic.setType(SchematicType.Normal.toDB()); + CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); + SteamwarUser user = SteamwarUser.get(schematic.getOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); if(player != null) - Message.send("CHECK_DECLINED", player, schematic.getSchemType().name(), schematic.getSchemName(), reason); - Message.team("CHECK_DECLINED_TEAM", schematic.getSchemName(), user.getUserName(), reason); + Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason); + Message.team("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason); stop(); } private void abort(){ - CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "Prüfvorgang abgebrochen"); + CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "Prüfvorgang abgebrochen"); stop(); } private void stop(){ currentCheckers.remove(checker.getUniqueId()); - currentSchems.remove(schematic.getSchemID()); + currentSchems.remove(schematic.getId()); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { for (Subserver subserver : Subserver.getServerList()) { if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(checker.getUniqueId())) { diff --git a/src/de/steamwar/bungeecore/inventory/SWListInv.java b/src/de/steamwar/bungeecore/inventory/SWListInv.java index 1161260c..8636054d 100644 --- a/src/de/steamwar/bungeecore/inventory/SWListInv.java +++ b/src/de/steamwar/bungeecore/inventory/SWListInv.java @@ -19,8 +19,6 @@ package de.steamwar.bungeecore.inventory; -import de.steamwar.bungeecore.sql.Schematic; -import de.steamwar.bungeecore.sql.SchematicType; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -103,27 +101,6 @@ public class SWListInv extends SWInventory { return onlinePlayers; } - public static List> getSchemList(SchematicType type, int steamwarUserId){ - List> schemList = new ArrayList<>(); - - List schems; - if(type == null) - schems = Schematic.getSchemsAccessibleByUser(steamwarUserId); - else - schems = Schematic.getSchemsOfType(steamwarUserId, type); - - for(Schematic s : schems){ - String m; - if(s.getSchemItem().isEmpty()) - m = "CAULDRON_ITEM"; - else - m = s.getSchemItem(); - SWItem item = new SWItem(m, "§e" + s.getSchemName()); - schemList.add(new SWListEntry<>(item, s)); - } - return schemList; - } - public static class SWListEntry{ final SWItem item; final T object; diff --git a/src/de/steamwar/bungeecore/listeners/CheckListener.java b/src/de/steamwar/bungeecore/listeners/CheckListener.java index f4aec741..1370a0db 100644 --- a/src/de/steamwar/bungeecore/listeners/CheckListener.java +++ b/src/de/steamwar/bungeecore/listeners/CheckListener.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.commands.CheckCommand; -import de.steamwar.bungeecore.sql.Schematic; +import de.steamwar.bungeecore.sql.SchematicNode; import de.steamwar.bungeecore.sql.SchematicType; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -40,10 +40,10 @@ public class CheckListener extends BasicListener { ProxiedPlayer player = e.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - List uncheckedSchematics = new LinkedList<>(); + List uncheckedSchematics = new LinkedList<>(); for(SchematicType type : SchematicType.values()){ if(type.check()) - uncheckedSchematics.addAll(Schematic.getSchemsOfType(user.getId(), type)); + uncheckedSchematics.addAll(SchematicNode.getAllSchematicsOfType(user.getId(), type.toDB())); } if(!uncheckedSchematics.isEmpty()) diff --git a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java index 0424e4aa..ed2160cb 100644 --- a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java +++ b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java @@ -27,8 +27,7 @@ import java.util.List; public class CheckedSchematic { - private final String schemName; - private final int schemOwner; + private final int nodeId; private final int validator; private final Timestamp startTime; @@ -36,21 +35,20 @@ public class CheckedSchematic { private final String reason; private CheckedSchematic(ResultSet rs) throws SQLException { - schemName = rs.getString("SchemName"); - schemOwner = rs.getInt("SchemOwner"); + nodeId = rs.getInt("NodeId"); validator = rs.getInt("Validator"); startTime = rs.getTimestamp("StartTime"); endTime = rs.getTimestamp("EndTime"); reason = rs.getString("DeclineReason"); } - public static void create(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String reason){ - SQL.update("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)", - schemName, schemOwner, validator, startTime, endTime, reason); + public static void create(int nodeId, int validator, Timestamp startTime, Timestamp endTime, String reason){ + SQL.update("INSERT INTO CheckedSchematic (NodeId, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?)", + nodeId, validator, startTime, endTime, reason); } - public static List previousChecks(String schemName, int schemOwner){ - ResultSet rs = SQL.select("SELECT * FROM CheckedSchematic WHERE SchemName = ? AND SchemOwner = ? ORDER BY EndTime ASC", schemName, schemOwner); + public static List previousChecks(int nodeId){ + ResultSet rs = SQL.select("SELECT * FROM CheckedSchematic WHERE NodeId = ? ORDER BY EndTime ASC", nodeId); List schematics = new ArrayList<>(); try { while(rs.next()) @@ -72,4 +70,8 @@ public class CheckedSchematic { public String getReason() { return reason; } + + public int getNodeId() { + return nodeId; + } } diff --git a/src/de/steamwar/bungeecore/sql/NodeMember.java b/src/de/steamwar/bungeecore/sql/NodeMember.java new file mode 100644 index 00000000..76c91e4b --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/NodeMember.java @@ -0,0 +1,87 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.bungeecore.sql; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashSet; +import java.util.Set; + +public class NodeMember { + public static NodeMember getNodeMember(int node, int member) { + ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?", node, member); + try { + if(!set.next()) + return null; + return new NodeMember(set); + } catch (SQLException e) { + throw new SecurityException("Could not load NodeMember", e); + } + } + + public static Set getNodeMembers(int node) { + ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE NodeId = ?", node); + try { + Set members = new HashSet<>(); + while (set.next()) + members.add(new NodeMember(set)); + return members; + } catch (SQLException e) { + throw new SecurityException("Could not load NodeMember", e); + } + } + + public static Set getSchematics(int member) { + ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE UserId = ?", member); + try { + Set members = new HashSet<>(); + while (set.next()) + members.add(new NodeMember(set)); + return members; + } catch (SQLException e) { + throw new SecurityException("Could not load NodeMember", e); + } + } + + public static NodeMember createNodeMember(int node, int member) { + SQL.update("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)", node, member); + return getNodeMember(node, member); + } + + final int node; + final int member; + + private NodeMember(ResultSet set) throws SQLException { + node = set.getInt("NodeId"); + member = set.getInt("UserId"); + } + + public int getNode() { + return node; + } + + public int getMember() { + return member; + } + + public void delete() { + SQL.update("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?", node, member); + } +} diff --git a/src/de/steamwar/bungeecore/sql/Schematic.java b/src/de/steamwar/bungeecore/sql/Schematic.java deleted file mode 100644 index 9d25a384..00000000 --- a/src/de/steamwar/bungeecore/sql/Schematic.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class Schematic { - private final int schemID; - private final String schemName; - private final int schemOwner; - private SchematicType schemType; - private String schemItem; - - private Schematic(ResultSet rs) throws SQLException { - this.schemID = rs.getInt("SchemID"); - this.schemName = rs.getString("SchemName"); - this.schemOwner = rs.getInt("SchemOwner"); - this.schemType = SchematicType.fromDB(rs.getString("SchemType")); - this.schemItem = rs.getString("Item"); - } - - public static Schematic getSchemFromDB(String schemName, UUID schemOwner){ - return getSchemFromDB(schemName, SteamwarUser.get(schemOwner).getId()); - } - - public static Schematic getSchemFromDB(String schemName, int schemOwner){ - ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner); - try { - if(schematic == null || !schematic.next()){ - return null; - } - return new Schematic(schematic); - } catch (SQLException e) { - throw new SecurityException("Failed loading schematic", e); - } - } - - public static Schematic getSchemFromDB(int schemID){ - ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemID = ?", schemID); - try { - if(!schematic.next()) - throw new SecurityException("Failed loading schematic " + schemID); - return new Schematic(schematic); - } catch (SQLException e) { - throw new SecurityException("Failed loading schematic", e); - } - } - - public static List getAllSchemsOfType(SchematicType schemType){ - try{ - ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemType = ?", schemType.toDB()); - List schematics = new ArrayList<>(); - while(schematic.next()){ - schematics.add(new Schematic(schematic)); - } - return schematics; - }catch(SQLException e){ - throw new SecurityException("Failed loading all schems of type", e); - } - } - - public static List getSchemsOfType(int userId, SchematicType schemType){ - try{ - ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemType = ? AND SchemOwner = ?", schemType.toDB(), userId); - List schematics = new ArrayList<>(); - while(schematic.next()){ - schematics.add(new Schematic(schematic)); - } - return schematics; - }catch(SQLException e){ - throw new SecurityException("Failed loading schems of type", e); - } - } - - public static List getSchemsAccessibleByUser(int schemOwner){ - try{ - ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, Rank, SchemFormat, Item FROM Schematic WHERE SchemOwner = ? ORDER BY SchemName", schemOwner); - List schematics = new ArrayList<>(); - while(schematic.next()){ - schematics.add(new Schematic(schematic)); - } - List addedSchems = SchematicMember.getAccessibleSchems(schemOwner); - for(SchematicMember schem : addedSchems){ - schematics.add(getSchemFromDB(schem.getSchemName(), schem.getSchemOwner())); - } - return schematics; - }catch(SQLException e){ - throw new SecurityException("Failed listing schematics", e); - } - } - - public int getSchemID() { - return schemID; - } - - public String getSchemName() { - return schemName; - } - - public int getSchemOwner() { - return schemOwner; - } - - public String getSchemItem() { - return schemItem; - } - - public SchematicType getSchemType() { - return schemType; - } - - public void setSchemType(SchematicType schemType) { - this.schemType = schemType; - SQL.update("UPDATE Schematic SET SchemType = ? WHERE SchemID = ?", schemType.toDB(), schemID); - } - - public void setRank(int rank) { - SQL.update("UPDATE Schematic SET Rank = ? WHERE SchemID = ?", rank, schemID); - } -} diff --git a/src/de/steamwar/bungeecore/sql/SchematicMember.java b/src/de/steamwar/bungeecore/sql/SchematicMember.java deleted file mode 100644 index 85b84855..00000000 --- a/src/de/steamwar/bungeecore/sql/SchematicMember.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bungeecore.sql; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class SchematicMember { - private final int schemOwner; - private final String schemName; - private final int member; - - private SchematicMember(String schemName, int schemOwner, int schemMember, boolean updateDB){ - this.schemOwner = schemOwner; - member = schemMember; - this.schemName = schemName; - if(updateDB) - updateDB(); - } - - public SchematicMember(String schemName, int schemOwner, int schemMember){ - this(schemName, schemOwner, schemMember, true); - } - - public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){ - this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId(), true); - } - - private void updateDB(){ - SQL.update("INSERT INTO SchemMember (SchemName, SchemOwner, Member) VALUES (?, ?, ?)", schemName, schemOwner, member); - } - - public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){ - return getSchemMemberFromDB(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId()); - } - - public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember){ - ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ? AND Member = ?", schemName, schemOwner, schemMember); - try { - if(schematicMember == null || !schematicMember.next()){ - return null; - } - return new SchematicMember(schemName, schemOwner, schemMember, false); - } catch (SQLException e) { - throw new SecurityException("Could not get schemmember", e); - } - } - - public static SchematicMember getMemberBySchematic(String schemName, int schemMember){ - ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND Member = ?", schemName, schemMember); - try { - if(schematicMember == null || !schematicMember.next()){ - return null; - } - int schemOwner = schematicMember.getInt("SchemOwner"); - return new SchematicMember(schemName, schemOwner, schemMember, false); - } catch (SQLException e) { - throw new SecurityException("Could not get member", e); - } - } - - public static List getSchemMembers(String schemName, UUID schemOwner){ - return getSchemMembers(schemName, SteamwarUser.get(schemOwner).getId()); - } - - public static List getSchemMembers(String schemName, int schemOwner){ - ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner); - try { - List schematicMembers = new ArrayList<>(); - while(schematicMember.next()){ - int schemMember = schematicMember.getInt("Member"); - schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false)); - } - return schematicMembers; - } catch (SQLException e) { - throw new SecurityException("Could not get schemmembers", e); - } - } - - public static List getAccessibleSchems(UUID schemMember){ - return getAccessibleSchems(SteamwarUser.get(schemMember).getId()); - } - - public static List getAccessibleSchems(int schemMember){ - ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE Member = ?", schemMember); - try { - List schematicMembers = new ArrayList<>(); - while(schematicMember.next()){ - String schemName = schematicMember.getString("SchemName"); - int schemOwner = schematicMember.getInt("SchemOwner"); - schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false)); - } - return schematicMembers; - } catch (SQLException e) { - throw new SecurityException("Could not get accessible schems", e); - } - } - - public int getSchemOwner() { - return schemOwner; - } - - public String getSchemName() { - return schemName; - } - - public int getMember() { - return member; - } - - public void remove(){ - SQL.update("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ? AND Member = ?", schemOwner, schemName, member); - } -} diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java new file mode 100644 index 00000000..85c0bf66 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/SchematicNode.java @@ -0,0 +1,359 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.bungeecore.sql; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; + +public class SchematicNode { + + public static SchematicNode createSchematic(int owner, String name, Integer parent) { + return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), ""); + } + + public static SchematicNode createSchematicDirectory(int owner, String name, Integer parent) { + return createSchematicNode(owner, name, parent, null, ""); + } + + public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) { + if(parent == 0) + parent = null; + SQL.update("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)", + name, owner, parent, type, item); + return getSchematicNode(owner, name, parent); + } + + public static SchematicNode getSchematicNode(int owner, String name, Integer parent) { + if(parent != null && parent == 0) + parent = null; + ResultSet set; + if(parent == null) { + set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name); + }else { + set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent); + } + try { + while (set.next()) { + SchematicNode node = new SchematicNode(set); + if(!node.isDir()) + return node; + } + List nodes = getSchematicNodeInNode(parent); + for (SchematicNode node:nodes) { + if(!node.isDir() && node.name.equals(name) && NodeMember.getNodeMember(node.getId(), owner) != null) + return node; + } + return null; + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) { + return getSchematicNode(owner, name, parent.getId()); + } + + public static List getSchematicNodeInNode(Integer parent) { + if(parent != null && parent == 0) + parent = null; + ResultSet set; + if(parent == null) { + set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode is NULL"); + }else { + set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode = ?", parent); + } + try { + List nodes = new ArrayList<>(); + while (set.next()) + nodes.add(new SchematicNode(set)); + return nodes; + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static List getSchematicNodeInNode(SchematicNode parent) { + return getSchematicNodeInNode(parent.getId()); + } + + public static SchematicNode getSchematicDirectory(String name, SchematicNode parent) { + return getSchematicDirectory(name, parent.getId()); + } + + public static SchematicNode getSchematicDirectory(String name, Integer parent) { + if(parent != null && parent == 0) + parent = null; + ResultSet set; + if(parent == null) { + set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent); + }else { + set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent); + } + try { + while (set.next()) { + SchematicNode node = new SchematicNode(set); + if(node.isDir()) + return node; + } + return null; + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static SchematicNode getSchematicInParent(String name, Integer parent) { + if(parent != null && parent == 0) + parent = null; + ResultSet set; + if(parent == null) { + set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent); + }else { + set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent); + } + try { + while (set.next()) { + SchematicNode node = new SchematicNode(set); + if(!node.isDir()) + return node; + } + return null; + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static SchematicNode getSchematicNode(int id) { + ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeId = ?", id); + try { + if(!set.next()) + return null; + return new SchematicNode(set); + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static List getAllSchematicsOfType(int owner, String schemType) { + ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType); + try { + List nodes = new ArrayList<>(); + while (set.next()) + nodes.add(new SchematicNode(set)); + return nodes; + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static List getAllSchematicsOfType(String schemType) { + ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeType = ?", schemType); + try { + List nodes = new ArrayList<>(); + while (set.next()) + nodes.add(new SchematicNode(set)); + return nodes; + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static List getSchematicsOfType(int owner, String schemType, Integer parent) { + if(parent != null && parent == 0) + parent = null; + List schems = getAllSchematicsOfType(owner, schemType); + Map nodesInParent = new LinkedHashMap<>(); + for (SchematicNode schematicNode : schems) { + SchematicNode currentNode = schematicNode; + while (currentNode.getParent() != parent) { + currentNode = currentNode.getParentNode(); + } + nodesInParent.putIfAbsent(currentNode.getId(), currentNode); + } + return new ArrayList<>(nodesInParent.values()); + } + + public static List getSchematicsAccessibleByUser(int user, Integer parent) { + if(parent != null && parent != 0) { + SchematicNode node = SchematicNode.getSchematicNode(parent); + boolean isAdded = false; + while (node.getId() != 0) { + for (NodeMember member:node.getMembers()) { + if (member.getMember() == user) { + isAdded = true; + break; + } + } + node = SchematicNode.getSchematicNode(node.getParent()); + } + if(isAdded) + return getSchematicNodeInNode(parent); + } else { + ResultSet set = SQL.select("SELECT * FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND s.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName", user, user); + try{ + List nodes = new ArrayList<>(); + while(set.next()) + nodes.add(new SchematicNode(set)); + return nodes; + }catch(SQLException e){ + throw new SecurityException("Failed listing schematics", e); + } + } + return null; + } + + public static List getAllSchematicsAccessibleByUser(int user) { + ResultSet set = SQL.select("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode FROM SchematicNode s LEFT JOIN NodeMember nm ON nm.NodeId = s.NodeId WHERE s.NodeOwner = ? OR nm.UserId = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user); + try{ + List nodes = new ArrayList<>(); + while(set.next()) + nodes.add(new SchematicNode(set)); + return nodes; + }catch(SQLException e){ + throw new SecurityException("Failed listing schematics", e); + } + } + + private final int id; + private final int owner; + private String name; + private int parent; + private String item; + private String type; + private boolean schemFormat; + private int rank; + private boolean isDir; + + private SchematicNode(ResultSet set) throws SQLException { + id = set.getInt("NodeId"); + owner = set.getInt("NodeOwner"); + name = set.getString("NodeName"); + parent = set.getInt("ParentNode"); + item = set.getString("NodeItem"); + type = set.getString("NodeType"); + if(type != null) { + isDir = false; + rank = set.getInt("NodeRank"); + schemFormat = set.getBoolean("NodeFormat"); + }else { + isDir = true; + } + } + + public int getId() { + return id; + } + + public int getOwner() { + return owner; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + updateDB(); + } + + public int getParent() { + return parent; + } + + public void setParent(int parent) { + this.parent = parent; + updateDB(); + } + + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + updateDB(); + } + + public String getType() { + if(isDir) + throw new SecurityException("Node is Directory"); + return type; + } + + public void setType(String type) { + if(isDir) + throw new SecurityException("Node is Directory"); + this.type = type; + updateDB(); + } + + public boolean isDir() { + return isDir; + } + + public boolean getSchemFormat() { + if(isDir) + throw new SecurityException("Node is Directory"); + return schemFormat; + } + + public int getRank() { + if(isDir) + throw new SecurityException("Node is Directory"); + return rank; + } + + public void setRank(int rank) { + if(isDir) + throw new SecurityException("Node is Directory"); + this.rank = rank; + } + + public SchematicType getSchemtype() { + if(isDir()) + throw new RuntimeException("Is Directory"); + return SchematicType.fromDB(type); + } + + public SchematicNode getParentNode() { + return SchematicNode.getSchematicNode(parent); + } + + public boolean accessibleByUser(int user) { + return NodeMember.getNodeMember(id, user) != null; + } + + public Set getMembers() { + return NodeMember.getNodeMembers(id); + } + + private void updateDB() { + SQL.update("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?", + name, owner, parent, item, type, rank, id); + } + + public void delete() { + if(isDir()) { + getSchematicNodeInNode(getId()).forEach(SchematicNode::delete); + } + SQL.update("DELETE FROM SchematicNode WHERE NodeId = ?", id); + } +} From 5576d1e3ca295f0a402943f5acdbc05fc5e5821e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 18 Jul 2021 19:40:53 +0200 Subject: [PATCH 2/6] Update! --- .../bungeecore/commands/CheckCommand.java | 6 +- .../bungeecore/sql/SchematicNode.java | 301 +++++++++++------- 2 files changed, 190 insertions(+), 117 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index fe8b40e2..63671c09 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -72,7 +72,7 @@ public class CheckCommand extends BasicCommand { }, 10, 10, TimeUnit.MINUTES); } public static void sendReminder(ProxiedPlayer player) { - List schematics = getSchemsToCheck(); + List schematics = getSchemsToCheck(); if(schematics.size() != currentCheckers.size()) Message.send("CHECK_REMINDER", player, "CHECK_REMINDER_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size()); } @@ -230,8 +230,8 @@ public class CheckCommand extends BasicCommand { ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { BauCommand.stopBauserver(checker); - ArenaMode mode = ArenaMode.getByCheckSchemType(schematic.getSchemType().toDB()); - SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID()); + ArenaMode mode = ArenaMode.getBySchemType(schematic.getSchemtype()); + SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getId(), 0); currentCheckers.put(checker.getUniqueId(), this); currentSchems.put(schematic.getId(), this); for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getId())) diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java index 85c0bf66..c419c099 100644 --- a/src/de/steamwar/bungeecore/sql/SchematicNode.java +++ b/src/de/steamwar/bungeecore/sql/SchematicNode.java @@ -1,27 +1,31 @@ /* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package de.steamwar.bungeecore.sql; +import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.Instant; import java.util.*; +import java.util.function.Predicate; public class SchematicNode { @@ -34,59 +38,33 @@ public class SchematicNode { } public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) { - if(parent == 0) + if (parent == 0) parent = null; SQL.update("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)", name, owner, parent, type, item); return getSchematicNode(owner, name, parent); } - public static SchematicNode getSchematicNode(int owner, String name, Integer parent) { - if(parent != null && parent == 0) - parent = null; - ResultSet set; - if(parent == null) { - set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name); - }else { - set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent); - } - try { - while (set.next()) { - SchematicNode node = new SchematicNode(set); - if(!node.isDir()) - return node; - } - List nodes = getSchematicNodeInNode(parent); - for (SchematicNode node:nodes) { - if(!node.isDir() && node.name.equals(name) && NodeMember.getNodeMember(node.getId(), owner) != null) - return node; - } - return null; - }catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); - } - } + private Timestamp lastUpdate; public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) { return getSchematicNode(owner, name, parent.getId()); } - public static List getSchematicNodeInNode(Integer parent) { - if(parent != null && parent == 0) - parent = null; - ResultSet set; - if(parent == null) { - set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode is NULL"); - }else { - set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode = ?", parent); - } - try { - List nodes = new ArrayList<>(); - while (set.next()) - nodes.add(new SchematicNode(set)); - return nodes; - }catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); + private SchematicNode(ResultSet set) throws SQLException { + id = set.getInt("NodeId"); + owner = set.getInt("NodeOwner"); + name = set.getString("NodeName"); + parent = set.getInt("ParentNode"); + item = set.getString("NodeItem"); + type = set.getString("NodeType"); + lastUpdate = set.getTimestamp("LastUpdate"); + if (type != null) { + isDir = false; + rank = set.getInt("NodeRank"); + schemFormat = set.getBoolean("NodeFormat"); + } else { + isDir = true; } } @@ -98,14 +76,58 @@ public class SchematicNode { return getSchematicDirectory(name, parent.getId()); } + public static SchematicNode getSchematicNode(int owner, String name, Integer parent) { + if (parent != null && parent == 0) + parent = null; + ResultSet set; + if (parent == null) { + set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name); + } else { + set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent); + } + try { + while (set.next()) { + SchematicNode node = new SchematicNode(set); + return node; + } + List nodes = getSchematicNodeInNode(parent); + for (SchematicNode node:nodes) { + if (node.name.equals(name) && NodeMember.getNodeMember(node.getId(), owner) != null) + return node; + } + return null; + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static List getSchematicNodeInNode(Integer parent) { + if(parent != null && parent == 0) + parent = null; + ResultSet set; + if(parent == null) { + set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL"); + }else { + set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?", parent); + } + try { + List nodes = new ArrayList<>(); + while (set.next()) + nodes.add(new SchematicNode(set)); + return nodes; + }catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + public static SchematicNode getSchematicDirectory(String name, Integer parent) { if(parent != null && parent == 0) parent = null; ResultSet set; if(parent == null) { - set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent); + set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent); }else { - set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent); + set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent); } try { while (set.next()) { @@ -124,9 +146,9 @@ public class SchematicNode { parent = null; ResultSet set; if(parent == null) { - set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent); + set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name); }else { - set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent); + set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent); } try { while (set.next()) { @@ -141,44 +163,19 @@ public class SchematicNode { } public static SchematicNode getSchematicNode(int id) { - ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeId = ?", id); + ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?", id); try { - if(!set.next()) + if (!set.next()) return null; return new SchematicNode(set); - }catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); - } - } - - public static List getAllSchematicsOfType(int owner, String schemType) { - ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType); - try { - List nodes = new ArrayList<>(); - while (set.next()) - nodes.add(new SchematicNode(set)); - return nodes; - }catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); - } - } - - public static List getAllSchematicsOfType(String schemType) { - ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeType = ?", schemType); - try { - List nodes = new ArrayList<>(); - while (set.next()) - nodes.add(new SchematicNode(set)); - return nodes; - }catch (SQLException e) { + } catch (SQLException e) { throw new SecurityException("Failed to load Schemnodes", e); } } public static List getSchematicsOfType(int owner, String schemType, Integer parent) { - if(parent != null && parent == 0) - parent = null; - 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; @@ -190,8 +187,46 @@ public class SchematicNode { return new ArrayList<>(nodesInParent.values()); } + public static List getAllSchematicsOfType(int owner, String schemType) { + ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType); + try { + List nodes = new ArrayList<>(); + while (set.next()) + nodes.add(new SchematicNode(set)); + return nodes; + } catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + public static List getAllSchematicsOfType(String schemType) { + ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?", schemType); + try { + List nodes = new ArrayList<>(); + while (set.next()) + nodes.add(new SchematicNode(set)); + return nodes; + } catch (SQLException e) { + throw new SecurityException("Failed to load Schemnodes", e); + } + } + + 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; + } + public static List getSchematicsAccessibleByUser(int user, Integer parent) { - if(parent != null && parent != 0) { + if (parent != null && parent != 0) { SchematicNode node = SchematicNode.getSchematicNode(parent); boolean isAdded = false; while (node.getId() != 0) { @@ -206,7 +241,7 @@ public class SchematicNode { if(isAdded) return getSchematicNodeInNode(parent); } else { - ResultSet set = SQL.select("SELECT * FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND s.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName", user, user); + ResultSet set = SQL.select("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.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName", user, user); try{ List nodes = new ArrayList<>(); while(set.next()) @@ -216,11 +251,11 @@ public class SchematicNode { throw new SecurityException("Failed listing schematics", e); } } - return null; + return Collections.emptyList(); } public static List getAllSchematicsAccessibleByUser(int user) { - ResultSet set = SQL.select("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode FROM SchematicNode s LEFT JOIN NodeMember nm ON nm.NodeId = s.NodeId WHERE s.NodeOwner = ? OR nm.UserId = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user); + ResultSet set = SQL.select("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 nm ON nm.NodeId = s.NodeId WHERE s.NodeOwner = ? OR nm.UserId = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user); try{ List nodes = new ArrayList<>(); while(set.next()) @@ -234,26 +269,35 @@ public class SchematicNode { 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"); - owner = set.getInt("NodeOwner"); - name = set.getString("NodeName"); - parent = set.getInt("ParentNode"); - item = set.getString("NodeItem"); - type = set.getString("NodeType"); - if(type != null) { - isDir = false; - rank = set.getInt("NodeRank"); - schemFormat = set.getBoolean("NodeFormat"); - }else { - isDir = true; + public static List filterSchems(int user, Predicate filter) { + List finalList = new ArrayList<>(); + List nodes = SchematicNode.getSchematicsAccessibleByUser(user, null); + nodes.forEach(node -> { + if (node.isDir()) { + finalList.addAll(deepGet(node.getId(), filter)); + } else { + if (filter.test(node)) + finalList.add(node); + } + }); + return finalList; + } + + public static Integer countNodes() { + ResultSet set = SQL.select("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode"); + try { + if (set.next()) + return set.getInt("count"); + return 0; + } catch (SQLException e) { + throw new SecurityException("Failed listing schematics", e); } } @@ -274,7 +318,7 @@ public class SchematicNode { updateDB(); } - public int getParent() { + public Integer getParent() { return parent; } @@ -345,15 +389,44 @@ public class SchematicNode { return NodeMember.getNodeMembers(id); } + public Timestamp getLastUpdate() { + return lastUpdate; + } + + public String generateBreadcrumbs(SteamwarUser user) { + return generateBreadcrumbs("/", user); + } + + public String generateBreadcrumbs(String split, SteamwarUser user) { + StringBuilder builder = new StringBuilder(getName()); + SchematicNode currentNode = this; + if (currentNode.isDir()) builder.append("/"); + while (currentNode.getParentNode() != null) { + currentNode = currentNode.getParentNode(); + builder.insert(0, split) + .insert(0, currentNode.getName()); + if (currentNode.getMembers().stream().anyMatch(member -> member.getMember() == user.getId())) { + break; + } + } + return builder.toString(); + } + 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); + this.lastUpdate = Timestamp.from(Instant.now()); } public void delete() { - if(isDir()) { + if (isDir()) { getSchematicNodeInNode(getId()).forEach(SchematicNode::delete); } SQL.update("DELETE FROM SchematicNode WHERE NodeId = ?", id); } + + private void updateDatabase(Blob blob, boolean newFormat) { + SQL.update("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?", blob, newFormat, id); + schemFormat = newFormat; + } } From cf436006448e7d2788cbdbbf2449adbf7935e8ce Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 27 Aug 2021 18:59:54 +0200 Subject: [PATCH 3/6] Fixing Signed-off-by: Chaoscaot --- .../bungeecore/bot/util/DiscordSchemAlert.java | 10 +++++----- .../steamwar/bungeecore/commands/CheckCommand.java | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java index b4b4261e..f0d9d7b6 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.bot.util; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; -import de.steamwar.bungeecore.sql.Schematic; +import de.steamwar.bungeecore.sql.SchematicNode; import de.steamwar.bungeecore.sql.SteamwarUser; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.EmbedBuilder; @@ -36,14 +36,14 @@ import java.time.Instant; @UtilityClass public class DiscordSchemAlert { - public void sendDecline(Schematic schematic, SteamwarUser user, String reason) { + public void sendDecline(SchematicNode schematic, SteamwarUser user, String reason) { if(user.getDiscordId() != null) { User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete(); EmbedBuilder builder = new EmbedBuilder(); builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png"); builder.setColor(Color.RED); builder.setTitle("SteamWar-Schematic Info"); - builder.setDescription("Deine Schematic **" + schematic.getSchemName() + "** wurde abgelehnt. **Grund:** \n" + reason); + builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde abgelehnt. **Grund:** \n" + reason); builder.setTimestamp(Instant.now()); MessageBuilder messageBuilder = new MessageBuilder(); @@ -56,14 +56,14 @@ public class DiscordSchemAlert { } } - public void sendAccept(Schematic schematic, SteamwarUser user) { + public void sendAccept(SchematicNode schematic, SteamwarUser user) { if(user.getDiscordId() != null) { User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete(); EmbedBuilder builder = new EmbedBuilder(); builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png"); builder.setColor(Color.GREEN); builder.setTitle("SteamWar-Schematic Info"); - builder.setDescription("Deine Schematic **" + schematic.getSchemName() + "** wurde angenommen."); + builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde angenommen."); builder.setTimestamp(Instant.now()); MessageBuilder messageBuilder = new MessageBuilder(); diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 3144161b..dde381bf 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -121,9 +121,9 @@ public class CheckCommand extends BasicCommand { return schematicList; } - public static String getChecker(Schematic schematic) { - if (currentSchems.get(schematic.getSchemID()) == null) return null; - return currentSchems.get(schematic.getSchemID()).checker.getName(); + public static String getChecker(SchematicNode schematic) { + if (currentSchems.get(schematic.getId()) == null) return null; + return currentSchems.get(schematic.getId()).checker.getName(); } private void list(ProxiedPlayer player) { @@ -295,11 +295,11 @@ public class CheckCommand extends BasicCommand { SteamwarUser user = SteamwarUser.get(schematic.getOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); if(player != null) { - Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName()); + Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName()); } else { DiscordSchemAlert.sendAccept(schematic, user); } - Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName()); + Message.team("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName()); stop(); } @@ -309,11 +309,11 @@ public class CheckCommand extends BasicCommand { SteamwarUser user = SteamwarUser.get(schematic.getOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); if(player != null) { - Message.send("CHECK_DECLINED", player, schematic.getSchemType().name(), schematic.getSchemName(), reason); + Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason); } else { DiscordSchemAlert.sendDecline(schematic, user, reason); } - Message.team("CHECK_DECLINED_TEAM", schematic.getSchemName(), user.getUserName(), reason); + Message.team("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason); stop(); } From 3ac81810c43274b5f1f82314e1cdf31d8e81c338 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 12 Nov 2021 15:52:15 +0100 Subject: [PATCH 4/6] Fixing Merge Conflicts & Updating! --- .../bot/events/SchematicsManager.java | 6 +- .../bungeecore/commands/CheckCommand.java | 16 +- .../bungeecore/sql/CheckedSchematic.java | 87 ++++++-- .../steamwar/bungeecore/sql/NodeMember.java | 43 ++-- .../bungeecore/sql/SchematicNode.java | 204 +++++++++--------- 5 files changed, 194 insertions(+), 162 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java index 82a83705..e407cf98 100644 --- a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java +++ b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java @@ -53,13 +53,13 @@ public class SchematicsManager { CheckCommand.getSchemsToCheck().forEach(schematic -> { StringBuilder st = new StringBuilder(); - st.append("Typ: ").append(schematic.getSchemType().getKuerzel()); - st.append("\nVon: ").append(SteamwarUser.get(schematic.getSchemOwner()).getUserName()); + st.append("Typ: ").append(schematic.getSchemtype().getKuerzel()); + st.append("\nVon: ").append(SteamwarUser.get(schematic.getOwner()).getUserName()); String checker = CheckCommand.getChecker(schematic); if (checker != null) { st.append("\nWird Geprüft von: ").append(checker); } - embedBuilder.addField(schematic.getSchemName(), st.toString(), true); + embedBuilder.addField(schematic.getName(), st.toString(), true); }); MessageBuilder messageBuilder = new MessageBuilder(); diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index bbfd55f2..3ae16263 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -111,7 +111,7 @@ public class CheckCommand extends BasicCommand { } } - private static List getSchemsToCheck(){ + public static List getSchemsToCheck(){ List schematicList = new LinkedList<>(); for (SchematicType type : SchematicType.values()) { @@ -243,8 +243,8 @@ public class CheckCommand extends BasicCommand { SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getId(), 0); currentCheckers.put(checker.getUniqueId(), this); currentSchems.put(schematic.getId(), this); - for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getId())) - Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getReason()); + for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic)) + Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason()); next(0); }); } @@ -294,7 +294,7 @@ public class CheckCommand extends BasicCommand { } schematic.setType(schematic.getSchemtype().fightType().toDB()); - CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); + CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); SteamwarUser user = SteamwarUser.get(schematic.getOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); if(player != null) { @@ -308,7 +308,7 @@ public class CheckCommand extends BasicCommand { private void decline(String reason){ schematic.setType(SchematicType.Normal.toDB()); - CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); + CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); SteamwarUser user = SteamwarUser.get(schematic.getOwner()); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid()); if(player != null) { @@ -321,13 +321,13 @@ public class CheckCommand extends BasicCommand { } private void abort(){ - CheckedSchematic.create(schematic.getId(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "Prüfvorgang abgebrochen"); + CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "Prüfvorgang abgebrochen"); stop(); } private void stop(){ currentCheckers.remove(checker.getUniqueId()); - currentSchems.remove(schematic.getSchemID()); + currentSchems.remove(schematic.getId()); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { for (Subserver subserver : Subserver.getServerList()) { if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(checker.getUniqueId())) { @@ -340,7 +340,7 @@ public class CheckCommand extends BasicCommand { private void remove() { currentCheckers.remove(checker.getUniqueId()); - currentSchems.remove(schematic.getSchemID()); + currentSchems.remove(schematic.getId()); } } } diff --git a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java index 499a2f0e..82b71333 100644 --- a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java +++ b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java @@ -24,56 +24,97 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class CheckedSchematic { - private static final Statement create = new Statement("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)"); - private static final Statement previous = new Statement("SELECT * FROM CheckedSchematic WHERE SchemName = ? AND SchemOwner = ? ORDER BY EndTime ASC"); - - private final String schemName; - private final int schemOwner; + private static final Statement checkHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' AND NodeId is not NULL ORDER BY EndTime DESC"); + private static final Statement nodeHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC"); + private static final Statement insert = new Statement("INSERT INTO CheckedSchematic (NodeId, NodeName, NodeOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?)"); + private final Integer node; private final int validator; private final Timestamp startTime; private final Timestamp endTime; - private final String reason; + private final String declineReason; private CheckedSchematic(ResultSet rs) throws SQLException { - nodeId = rs.getInt("NodeId"); - validator = rs.getInt("Validator"); - startTime = rs.getTimestamp("StartTime"); - endTime = rs.getTimestamp("EndTime"); - reason = rs.getString("DeclineReason"); + this.node = rs.getInt("NodeId"); + this.validator = rs.getInt("Validator"); + this.startTime = rs.getTimestamp("StartTime"); + this.endTime = rs.getTimestamp("EndTime"); + this.declineReason = rs.getString("DeclineReason"); } - public static void create(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String reason){ - SQL.update("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)", - schemName, schemOwner, validator, startTime, endTime, reason); + public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason){ + insert.update(nodeId, name, owner, validator, startTime, endTime, reason); } - public static List previousChecks(String schemName, int schemOwner){ - ResultSet rs = SQL.select("SELECT * FROM CheckedSchematic WHERE SchemName = ? AND SchemOwner = ? ORDER BY EndTime ASC", schemName, schemOwner); - List schematics = new ArrayList<>(); - try { + public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason){ + create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason); + } + + public static List previousChecks(SchematicNode node){ + return nodeHistory.select(rs -> { + List schematics = new ArrayList<>(); while(rs.next()) schematics.add(new CheckedSchematic(rs)); return schematics; - }, schemName, schemOwner); + }, node.getId()); + } + + public static List getLastDeclinedOfNode(SchematicNode node){ + return getLastDeclinedOfNode(node.getId()); + } + + public static List getLastDeclinedOfNode(int node){ + return nodeHistory.select(rs -> { + List lastDeclined = new ArrayList<>(); + while(rs.next()){ + lastDeclined.add(new CheckedSchematic(rs)); + } + return lastDeclined; + }, node); + } + + public static List getLastDeclined(UUID uuid){ + return getLastDelined(SteamwarUser.get(uuid).getId()); + } + + public static List getLastDelined(int schemOwner){ + return checkHistory.select(rs -> { + List history = new ArrayList<>(); + while(rs.next()) + history.add(new CheckedSchematic(rs)); + return history; + }, schemOwner); } public int getValidator() { return validator; } + public Timestamp getStartTime() { + return startTime; + } + public Timestamp getEndTime() { return endTime; } - public String getReason() { - return reason; + public String getDeclineReason() { + return declineReason; } - public int getNodeId() { - return nodeId; + public int getNode() { + return node; + } + + public String getSchemName() { + return SchematicNode.getSchematicNode(node).getName(); + } + + public int getSchemOwner() { + return SchematicNode.getSchematicNode(node).getId(); } } diff --git a/src/de/steamwar/bungeecore/sql/NodeMember.java b/src/de/steamwar/bungeecore/sql/NodeMember.java index 76c91e4b..063dd487 100644 --- a/src/de/steamwar/bungeecore/sql/NodeMember.java +++ b/src/de/steamwar/bungeecore/sql/NodeMember.java @@ -25,43 +25,40 @@ import java.util.HashSet; import java.util.Set; public class NodeMember { + private static final Statement getNodeMember = new Statement("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?"); + private static final Statement getNodeMembers = new Statement("SELECT * FROM NodeMember WHERE NodeId = ?"); + private static final Statement getSchematics = new Statement("SELECT * FROM NodeMember WHERE UserId = ?"); + private static final Statement createNodeMember = new Statement("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)"); + private static final Statement deleteNodeMember = new Statement("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?"); + public static NodeMember getNodeMember(int node, int member) { - ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?", node, member); - try { - if(!set.next()) + return getNodeMember.select(rs -> { + if(!rs.next()) return null; - return new NodeMember(set); - } catch (SQLException e) { - throw new SecurityException("Could not load NodeMember", e); - } + return new NodeMember(rs); + }, node, member); } public static Set getNodeMembers(int node) { - ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE NodeId = ?", node); - try { + return getNodeMembers.select(rs -> { Set members = new HashSet<>(); - while (set.next()) - members.add(new NodeMember(set)); + while (rs.next()) + members.add(new NodeMember(rs)); return members; - } catch (SQLException e) { - throw new SecurityException("Could not load NodeMember", e); - } + }, node); } public static Set getSchematics(int member) { - ResultSet set = SQL.select("SELECT * FROM NodeMember WHERE UserId = ?", member); - try { + return getSchematics.select(rs -> { Set members = new HashSet<>(); - while (set.next()) - members.add(new NodeMember(set)); + while (rs.next()) + members.add(new NodeMember(rs)); return members; - } catch (SQLException e) { - throw new SecurityException("Could not load NodeMember", e); - } + }, member); } public static NodeMember createNodeMember(int node, int member) { - SQL.update("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)", node, member); + createNodeMember.update(node, member); return getNodeMember(node, member); } @@ -82,6 +79,6 @@ public class NodeMember { } public void delete() { - SQL.update("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?", node, member); + deleteNodeMember.update(node, member); } } diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java index c419c099..b111a2db 100644 --- a/src/de/steamwar/bungeecore/sql/SchematicNode.java +++ b/src/de/steamwar/bungeecore/sql/SchematicNode.java @@ -29,6 +29,23 @@ import java.util.function.Predicate; public class 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 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 = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode 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"); + private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?"); + 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"); + private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?"); + 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 = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?"); + 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 getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?"); + private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?"); + 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.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName"); + 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 deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?"); + public static SchematicNode createSchematic(int owner, String name, Integer parent) { return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), ""); } @@ -40,8 +57,7 @@ public class SchematicNode { public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) { if (parent == 0) parent = null; - SQL.update("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)", - name, owner, parent, type, item); + createNode.update(name, owner, parent, type, item); return getSchematicNode(owner, name, parent); } @@ -77,105 +93,85 @@ public class SchematicNode { } public static SchematicNode getSchematicNode(int owner, String name, Integer parent) { - if (parent != null && parent == 0) + if (parent != null && parent == 0) { parent = null; - ResultSet set; - if (parent == null) { - set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name); - } else { - set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent); } - try { - while (set.next()) { - SchematicNode node = new SchematicNode(set); + Statement.ResultSetUser user = rs -> { + while (rs.next()) { + SchematicNode node = new SchematicNode(rs); return node; } - List nodes = getSchematicNodeInNode(parent); - for (SchematicNode node:nodes) { - if (node.name.equals(name) && NodeMember.getNodeMember(node.getId(), owner) != null) - return node; - } return null; - }catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); + }; + if(parent == null) { + return getSchematicNode_Null.select(user, owner, name); + } else { + return getSchematicNode.select(user, owner, name, parent); } } public static List getSchematicNodeInNode(Integer parent) { if(parent != null && parent == 0) parent = null; - ResultSet set; - if(parent == null) { - set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL"); - }else { - set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?", parent); - } - try { + Statement.ResultSetUser> user = rs -> { List nodes = new ArrayList<>(); - while (set.next()) - nodes.add(new SchematicNode(set)); + while (rs.next()) + nodes.add(new SchematicNode(rs)); return nodes; - }catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); + }; + if(parent == null) { + return getSchematicsInNode_Null.select(user); + }else { + return getSchematicsInNode.select(user, parent); } } public static SchematicNode getSchematicDirectory(String name, Integer parent) { if(parent != null && parent == 0) parent = null; - ResultSet set; - if(parent == null) { - set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent); - }else { - set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent); - } - try { - while (set.next()) { - SchematicNode node = new SchematicNode(set); + Statement.ResultSetUser user = rs -> { + while (rs.next()) { + SchematicNode node = new SchematicNode(rs); if(node.isDir()) return node; } return null; - }catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); + }; + + if(parent == null) { + return getSchematicDirectory_Null.select(user, name); + }else { + return getSchematicDirectory.select(user, name, parent); } } - public static SchematicNode getSchematicInParent(String name, Integer parent) { + public static SchematicNode getSchematicNode(String name, Integer parent) { if(parent != null && parent == 0) parent = null; - ResultSet set; - if(parent == null) { - set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name); - }else { - set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent); - } - try { - while (set.next()) { - SchematicNode node = new SchematicNode(set); - if(!node.isDir()) - return node; + Statement.ResultSetUser user = rs -> { + while (rs.next()) { + return new SchematicNode(rs); } return null; - }catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); + }; + if(parent == null) { + return getSchematicNodeO_Null.select(user, name); + }else { + return getSchematicNodeO.select(user, name, parent); } } public static SchematicNode getSchematicNode(int id) { - ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?", id); - try { - if (!set.next()) + return getSchematicNodeId.select(rs -> { + if (!rs.next()) return null; - return new SchematicNode(set); - } catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); - } + return new SchematicNode(rs); + }); } public static List getSchematicsOfType(int owner, String schemType, Integer parent) { List schems = getAllSchematicsAccessibleByUser(owner); - schems.removeIf(node -> !node.getType().equals(schemType)); + schems.removeIf(node -> node.isDir() || !node.getType().equals(schemType)); Map nodesInParent = new LinkedHashMap<>(); for (SchematicNode schematicNode : schems) { SchematicNode currentNode = schematicNode; @@ -188,27 +184,22 @@ public class SchematicNode { } public static List getAllSchematicsOfType(int owner, String schemType) { - ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType); - try { + return getAllSchemsOfTypeOwner.select(rs -> { List nodes = new ArrayList<>(); - while (set.next()) - nodes.add(new SchematicNode(set)); + while (rs.next()) + nodes.add(new SchematicNode(rs)); return nodes; - } catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); - } + }, owner, schemType); } + public static List getAllSchematicsOfType(String schemType) { - ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?", schemType); - try { + return getAllSchemsOfType.select(rs -> { List nodes = new ArrayList<>(); - while (set.next()) - nodes.add(new SchematicNode(set)); + while (rs.next()) + nodes.add(new SchematicNode(rs)); return nodes; - } catch (SQLException e) { - throw new SecurityException("Failed to load Schemnodes", e); - } + }, schemType); } public static List deepGet(Integer parent, Predicate filter) { @@ -241,29 +232,29 @@ public class SchematicNode { if(isAdded) return getSchematicNodeInNode(parent); } else { - ResultSet set = SQL.select("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.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName", user, user); - try{ + return getAccessibleByUser.select(rs -> { List nodes = new ArrayList<>(); - while(set.next()) - nodes.add(new SchematicNode(set)); + while(rs.next()) + nodes.add(new SchematicNode(rs)); return nodes; - }catch(SQLException e){ - throw new SecurityException("Failed listing schematics", e); - } + }, user, user); } return Collections.emptyList(); } public static List getAllSchematicsAccessibleByUser(int user) { - ResultSet set = SQL.select("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 nm ON nm.NodeId = s.NodeId WHERE s.NodeOwner = ? OR nm.UserId = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user); - try{ + return getAccessibleByUser.select(rs -> { List nodes = new ArrayList<>(); - while(set.next()) - nodes.add(new SchematicNode(set)); + while(rs.next()) { + SchematicNode node = new SchematicNode(rs); + if(node.isDir()) { + nodes.addAll(deepGet(node.getId(), node1 -> true)); + } else { + nodes.add(node); + } + } return nodes; - }catch(SQLException e){ - throw new SecurityException("Failed listing schematics", e); - } + }, user, user); } private final int id; @@ -275,6 +266,7 @@ public class SchematicNode { private boolean schemFormat; private int rank; private final boolean isDir; + private Map brCache = new HashMap<>(); public static List filterSchems(int user, Predicate filter) { List finalList = new ArrayList<>(); @@ -291,14 +283,12 @@ public class SchematicNode { } public static Integer countNodes() { - ResultSet set = SQL.select("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode"); - try { - if (set.next()) - return set.getInt("count"); + return countNodes.select(rs -> { + if (rs.next()) { + return rs.getInt("count"); + } return 0; - } catch (SQLException e) { - throw new SecurityException("Failed listing schematics", e); - } + }); } public int getId() { @@ -322,7 +312,7 @@ public class SchematicNode { return parent; } - public void setParent(int parent) { + public void setParent(Integer parent) { this.parent = parent; updateDB(); } @@ -394,7 +384,7 @@ public class SchematicNode { } public String generateBreadcrumbs(SteamwarUser user) { - return generateBreadcrumbs("/", user); + return brCache.computeIfAbsent(user.getId(), integer -> generateBreadcrumbs("/", user)); } public String generateBreadcrumbs(String split, SteamwarUser user) { @@ -413,20 +403,24 @@ public class SchematicNode { } private void updateDB() { - SQL.update("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?", - name, owner, parent == 0 ? null : parent, item, type, rank, id); + updateDB.update(name, owner, parent == 0 ? null : parent, item, type, rank, id); this.lastUpdate = Timestamp.from(Instant.now()); + this.brCache.clear(); } public void delete() { if (isDir()) { getSchematicNodeInNode(getId()).forEach(SchematicNode::delete); } - SQL.update("DELETE FROM SchematicNode WHERE NodeId = ?", id); + deleteNode.update(id); } - private void updateDatabase(Blob blob, boolean newFormat) { - SQL.update("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?", blob, newFormat, id); - schemFormat = newFormat; + @Override + public boolean equals(Object obj) { + if (!(obj instanceof SchematicNode)) + return false; + + SchematicNode node = (SchematicNode) obj; + return node.getId() == id; } } From 2e5f0de710c863b9c5f815ade993c80ca1c2c129 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 14 Nov 2021 12:00:29 +0100 Subject: [PATCH 5/6] Everthings Tested! Signed-off-by: Chaoscaot --- .../bungeecore/sql/CheckedSchematic.java | 2 +- .../bungeecore/sql/SchematicNode.java | 89 +++++++++++-------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java index 82b71333..baae8933 100644 --- a/src/de/steamwar/bungeecore/sql/CheckedSchematic.java +++ b/src/de/steamwar/bungeecore/sql/CheckedSchematic.java @@ -30,7 +30,7 @@ public class CheckedSchematic { private static final Statement checkHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' AND NodeId is not NULL ORDER BY EndTime DESC"); private static final Statement nodeHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC"); - private static final Statement insert = new Statement("INSERT INTO CheckedSchematic (NodeId, NodeName, NodeOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?)"); + private static final Statement insert = new Statement("INSERT INTO CheckedSchematic (NodeId, NodeName, NodeOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?, ?)"); private final Integer node; private final int validator; diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java index b111a2db..e16acddc 100644 --- a/src/de/steamwar/bungeecore/sql/SchematicNode.java +++ b/src/de/steamwar/bungeecore/sql/SchematicNode.java @@ -19,7 +19,6 @@ package de.steamwar.bungeecore.sql; -import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; @@ -42,8 +41,16 @@ public class SchematicNode { private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?"); private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?"); 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.ParentNode is NULL 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 = ?"); + 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"); + 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 = ?"); + 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 WHERE NodeType is not null"); + 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 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"); 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 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 deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?"); public static SchematicNode createSchematic(int owner, String name, Integer parent) { @@ -166,21 +173,32 @@ public class SchematicNode { if (!rs.next()) return null; return new SchematicNode(rs); - }); + }, id); } - public static List getSchematicsOfType(int owner, String schemType, Integer parent) { - List schems = getAllSchematicsAccessibleByUser(owner); - schems.removeIf(node -> node.isDir() || !node.getType().equals(schemType)); - Map nodesInParent = new LinkedHashMap<>(); - for (SchematicNode schematicNode : schems) { - SchematicNode currentNode = schematicNode; - while (currentNode.getParent() != parent) { - currentNode = currentNode.getParentNode(); + public static List getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) { + Statement.ResultSetUser> user = rs -> { + List nodes = new ArrayList<>(); + while (rs.next()) { + nodes.add(new SchematicNode(rs)); } - nodesInParent.putIfAbsent(currentNode.getId(), currentNode); + return nodes; + }; + if(parent == null || parent == 0) { + return getAccessibleByUserByTypeInNode_Null.select(user, owner, owner, schemType); + } else { + return getAccessibleByUserByTypeInNode.select(user, owner, owner, parent, schemType); } - return new ArrayList<>(nodesInParent.values()); + } + + public static List getAllAccessibleSchematicsOfType(int user, String schemType) { + return getAccessibleByUserByType.select(rs -> { + List nodes = new ArrayList<>(); + while (rs.next()) { + nodes.add(new SchematicNode(rs)); + } + return nodes; + }, user, user, schemType); } public static List getAllSchematicsOfType(int owner, String schemType) { @@ -192,7 +210,6 @@ public class SchematicNode { }, owner, schemType); } - public static List getAllSchematicsOfType(String schemType) { return getAllSchemsOfType.select(rs -> { List nodes = new ArrayList<>(); @@ -218,18 +235,10 @@ public class SchematicNode { public static List getSchematicsAccessibleByUser(int user, Integer parent) { if (parent != null && parent != 0) { - SchematicNode node = SchematicNode.getSchematicNode(parent); - boolean isAdded = false; - while (node.getId() != 0) { - for (NodeMember member:node.getMembers()) { - if (member.getMember() == user) { - isAdded = true; - break; - } - } - node = SchematicNode.getSchematicNode(node.getParent()); - } - if(isAdded) + if(isSchematicAccessibleForUser.select(rs -> { + rs.next(); + return rs.getInt("Accessible") > 0; + }, parent, user, user)) return getSchematicNodeInNode(parent); } else { return getAccessibleByUser.select(rs -> { @@ -243,20 +252,29 @@ public class SchematicNode { } public static List getAllSchematicsAccessibleByUser(int user) { - return getAccessibleByUser.select(rs -> { + return getAllSchematicsAccessibleByUser.select(rs -> { List nodes = new ArrayList<>(); while(rs.next()) { - SchematicNode node = new SchematicNode(rs); - if(node.isDir()) { - nodes.addAll(deepGet(node.getId(), node1 -> true)); - } else { - nodes.add(node); - } + nodes.add(new SchematicNode(rs)); } return nodes; }, user, user); } + public static List getAllParentsOfNode(SchematicNode node) { + return getAllParentsOfNode(node.getId()); + } + + public static List getAllParentsOfNode(int node) { + return getAllParentsOfNode.select(rs -> { + List nodes = new ArrayList<>(); + while(rs.next()) { + nodes.add(new SchematicNode(rs)); + } + return nodes; + }, node); + } + private final int id; private final int owner; private String name; @@ -408,13 +426,6 @@ public class SchematicNode { this.brCache.clear(); } - public void delete() { - if (isDir()) { - getSchematicNodeInNode(getId()).forEach(SchematicNode::delete); - } - deleteNode.update(id); - } - @Override public boolean equals(Object obj) { if (!(obj instanceof SchematicNode)) From ea8e5831c42bfc54b50ca4107a1a80d449e292c3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 20 Nov 2021 11:29:04 +0100 Subject: [PATCH 6/6] Update from Spigot Signed-off-by: Chaoscaot --- .../bungeecore/sql/SchematicNode.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/SchematicNode.java b/src/de/steamwar/bungeecore/sql/SchematicNode.java index e16acddc..83e9391f 100644 --- a/src/de/steamwar/bungeecore/sql/SchematicNode.java +++ b/src/de/steamwar/bungeecore/sql/SchematicNode.java @@ -19,12 +19,17 @@ package de.steamwar.bungeecore.sql; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.time.Instant; import java.util.*; import java.util.function.Predicate; +import java.util.zip.GZIPInputStream; public class SchematicNode { @@ -33,6 +38,8 @@ public class SchematicNode { 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 getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL"); private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?"); + 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"); + 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"); 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"); private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?"); 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"); @@ -40,12 +47,12 @@ public class SchematicNode { 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 getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?"); private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?"); - 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.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.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 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 = ?"); 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"); 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 = ?"); - 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 WHERE NodeType is not null"); - 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 Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1"); + 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"); + 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 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"); 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 = ?"); @@ -133,6 +140,22 @@ public class SchematicNode { } } + public static List getSchematicDirectoryInNode(Integer parent) { + if(parent != null && parent == 0) + parent = null; + Statement.ResultSetUser> user = rs -> { + List nodes = new ArrayList<>(); + while (rs.next()) + nodes.add(new SchematicNode(rs)); + return nodes; + }; + if(parent == null) { + return getDirsInNode_Null.select(user); + }else { + return getDirsInNode.select(user, parent); + } + } + public static SchematicNode getSchematicDirectory(String name, Integer parent) { if(parent != null && parent == 0) parent = null; @@ -187,7 +210,7 @@ public class SchematicNode { if(parent == null || parent == 0) { return getAccessibleByUserByTypeInNode_Null.select(user, owner, owner, schemType); } else { - return getAccessibleByUserByTypeInNode.select(user, owner, owner, parent, schemType); + return getAccessibleByUserByTypeInNode.select(user, owner, owner, schemType, parent); } } @@ -246,7 +269,7 @@ public class SchematicNode { while(rs.next()) nodes.add(new SchematicNode(rs)); return nodes; - }, user, user); + }, user, user, user, user); } return Collections.emptyList(); } @@ -421,7 +444,7 @@ public class SchematicNode { } private void updateDB() { - updateDB.update(name, owner, parent == 0 ? null : parent, item, type, rank, id); + updateDB.update(name, owner, parent, item, type, rank, id); this.lastUpdate = Timestamp.from(Instant.now()); this.brCache.clear(); }