From e544abf328720e2b186bce6371507259963d4e1d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Dec 2021 14:02:57 +0100 Subject: [PATCH 1/4] Some Fixes for SchematicSelector Signed-off-by: Chaoscaot --- .../steamwar/inventory/SchematicSelector.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 83e8ef8..3e1bc37 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -53,6 +53,7 @@ public class SchematicSelector { @Getter private boolean singleDirOpen; private boolean sdoTrigger = false; + private boolean noDirOpen = true; public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { this.player = player; @@ -80,12 +81,13 @@ public class SchematicSelector { if(sdoTrigger) { sdoTrigger = false; + openList(nodes.get(0)); return; } List> list = new ArrayList<>(); - if(parent != null) { + if(parent != null && !noDirOpen) { list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null)); } @@ -125,7 +127,25 @@ public class SchematicSelector { private void handleClick(SchematicNode node, SchematicNode parent) { if(node == null) { - openList(getParent(parent)); + if(!singleDirOpen) { + if(parent.getParent() == null) { + noDirOpen = true; + } + openList(getParent(parent)); + } else { + SchematicNode currentParent = parent; + do { + sdoTrigger = false; + currentParent = getParent(currentParent); + if(currentParent == null) + break; + getSchematicList(currentParent); + } while (sdoTrigger); + if(currentParent == null) { + noDirOpen = true; + } + openList(currentParent); + } return; } if(node.isDir()) { @@ -135,6 +155,7 @@ public class SchematicSelector { return; } filter.reset(); + noDirOpen = false; openList(node); return; } @@ -308,7 +329,12 @@ public class SchematicSelector { case SCHEMATIC_TYPE: nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(user.getId(), target.type.toDB(), parent==null?0:parent.getId())); if(target.rank >= 0) { - nodes.removeIf(node -> node.getRank() > target.rank); + nodes.removeIf(node -> { + if(node.isDir()) { + return false; + } + return node.getRank() > target.rank; + }); } break; default: @@ -316,7 +342,6 @@ public class SchematicSelector { } if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { - openList(nodes.get(0)); sdoTrigger = true; } return nodes; -- 2.39.5 From d1ca48436c9360abad966bfc899a64a7bd1d1167 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 8 Dec 2021 18:54:13 +0100 Subject: [PATCH 2/4] Fixes, Fixes, damn Fixes Signed-off-by: Chaoscaot --- .../steamwar/inventory/SchematicSelector.java | 28 +++++++++++++------ .../src/de/steamwar/sql/SchematicNode.java | 5 +--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 3e1bc37..4634738 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -20,6 +20,7 @@ package de.steamwar.inventory; import de.steamwar.core.Core; +import de.steamwar.sql.NodeMember; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; @@ -53,7 +54,9 @@ public class SchematicSelector { @Getter private boolean singleDirOpen; private boolean sdoTrigger = false; - private boolean noDirOpen = true; + @Getter + @Setter + private int openedDirs = 0; public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { this.player = player; @@ -87,7 +90,7 @@ public class SchematicSelector { List> list = new ArrayList<>(); - if(parent != null && !noDirOpen) { + if(parent != null && openedDirs != 0) { list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null)); } @@ -127,24 +130,31 @@ public class SchematicSelector { private void handleClick(SchematicNode node, SchematicNode parent) { if(node == null) { + openedDirs--; if(!singleDirOpen) { - if(parent.getParent() == null) { - noDirOpen = true; + if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { + openList(null); + } else { + openList(getParent(parent)); } - openList(getParent(parent)); } else { SchematicNode currentParent = parent; + boolean isMember = false; do { sdoTrigger = false; + if(NodeMember.getNodeMember(currentParent.getId(), user.getId()) != null) { + isMember = true; + } currentParent = getParent(currentParent); if(currentParent == null) break; getSchematicList(currentParent); } while (sdoTrigger); - if(currentParent == null) { - noDirOpen = true; + if(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { + openList(null); + } else { + openList(currentParent); } - openList(currentParent); } return; } @@ -155,7 +165,7 @@ public class SchematicSelector { return; } filter.reset(); - noDirOpen = false; + openedDirs++; openList(node); return; } diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index faea608..e67cdd5 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -488,13 +488,10 @@ public class SchematicNode { StringBuilder builder = new StringBuilder(getName()); SchematicNode currentNode = this; if (currentNode.isDir()) builder.append("/"); - while (currentNode.getParentNode() != null) { + while (currentNode.getParentNode() != null && !currentNode.getMembers().stream().anyMatch(member -> member.getMember() == user.getId())) { 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(); } -- 2.39.5 From 72708d7183567e8480d63b596960b0e4c90c0c59 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 11 Dec 2021 12:58:09 +0100 Subject: [PATCH 3/4] More Fixes Signed-off-by: Chaoscaot --- .../src/de/steamwar/inventory/SchematicSelector.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 4634738..ca508f6 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -56,7 +56,7 @@ public class SchematicSelector { private boolean sdoTrigger = false; @Getter @Setter - private int openedDirs = 0; + private int depth = 0; public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { this.player = player; @@ -90,7 +90,7 @@ public class SchematicSelector { List> list = new ArrayList<>(); - if(parent != null && openedDirs != 0) { + if(depth != 0) { list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null)); } @@ -130,7 +130,7 @@ public class SchematicSelector { private void handleClick(SchematicNode node, SchematicNode parent) { if(node == null) { - openedDirs--; + depth--; if(!singleDirOpen) { if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { openList(null); @@ -165,7 +165,7 @@ public class SchematicSelector { return; } filter.reset(); - openedDirs++; + depth++; openList(node); return; } @@ -320,7 +320,7 @@ public class SchematicSelector { nodes.removeIf(node -> !node.isDir()); } if(target.target == Target.SCHEMATIC_TYPE) { - nodes.removeIf(node -> node.isDir() || !node.getType().equals(target.type.toDB())); + nodes.removeIf(node -> node.isDir() || !node.getSchemtype().equals(target.type)); } return nodes; } -- 2.39.5 From 04de43ed4de5805b97b57a51e844911fecd27ca8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 11 Dec 2021 13:04:05 +0100 Subject: [PATCH 4/4] Improve Performance Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index e67cdd5..d888e5e 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -34,6 +34,7 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.time.Instant; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import java.util.zip.GZIPInputStream; @@ -488,8 +489,12 @@ public class SchematicNode { StringBuilder builder = new StringBuilder(getName()); SchematicNode currentNode = this; if (currentNode.isDir()) builder.append("/"); - while (currentNode.getParentNode() != null && !currentNode.getMembers().stream().anyMatch(member -> member.getMember() == user.getId())) { + final Set nodeMembers = NodeMember.getSchematics(user.getId()); + AtomicInteger i = new AtomicInteger(); + i.set(currentNode.getId()); + while (currentNode.getParentNode() != null && nodeMembers.stream().noneMatch(nodeMember -> nodeMember.getNode() == i.get())) { currentNode = currentNode.getParentNode(); + i.set(currentNode.getId()); builder.insert(0, split) .insert(0, currentNode.getName()); } -- 2.39.5