From 9fb49405ca75187ec8c2962f69592c259ca09d22 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 12 Jan 2023 21:53:28 +0100 Subject: [PATCH 1/4] NodeMember: Move Member Schematics --- CommonCore | 2 +- .../steamwar/inventory/SchematicSelector.java | 125 ++++++++---------- .../SchematicSelectorInjectable.java | 5 +- 3 files changed, 58 insertions(+), 74 deletions(-) diff --git a/CommonCore b/CommonCore index c6da22f..8ce900d 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit c6da22f0bee3865b7b3283bc17275e12c5de14af +Subproject commit 8ce900db31e5c4cf0cc5a39dcb61bed297b9d392 diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index ef9cf7f..6c8318b 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -20,10 +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; +import de.steamwar.sql.*; import lombok.*; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -44,7 +41,7 @@ public class SchematicSelector { private SteamwarUser user; @Getter @Setter - private Consumer callback; + private Consumer callback; private final SelectorTarget target; @Getter private final SelectorFilter filter = new SelectorFilter(); @@ -62,9 +59,9 @@ public class SchematicSelector { private Sorting sorting = Sorting.NAME; private boolean invertSorting = false; @Getter - private SchematicNode lastParent; + private EffectiveSchematicNode lastParent; - public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { + public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { this.player = player; this.user = SteamwarUser.get(player.getUniqueId()); this.target = target; @@ -72,7 +69,7 @@ public class SchematicSelector { this.singleDirOpen = !target.target.dirs; } - public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer callback) { + public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer callback) { this(player, target, callback); this.injectable = injectable; } @@ -97,9 +94,9 @@ public class SchematicSelector { injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); } - private void openList(SchematicNode parent) { + private void openList(EffectiveSchematicNode parent) { lastParent = parent; - List nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent)); + List nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent)); if(sdoTrigger) { sdoTrigger = false; @@ -107,18 +104,18 @@ public class SchematicSelector { return; } - List> list = new ArrayList<>(); + List> list = new ArrayList<>(); if(depth != 0) { list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null)); } - for (SchematicNode node : nodes) { - if(node.getName().equals("//copy")) continue; + for (EffectiveSchematicNode node : nodes) { + if(node.getNodeName().equals("//copy")) continue; list.add(renderItem(node)); } - SWListInv inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName() == null?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent)); + SWListInv inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName() == null?(parent == null?"/":parent.generateBreadcrumbs()):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent)); if(publicMode == PublicMode.ALL) { if(user.getId() == 0) { inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { @@ -158,40 +155,33 @@ public class SchematicSelector { inv.open(); } - private SchematicNode dirUp(SchematicNode parent) { + private EffectiveSchematicNode dirUp(EffectiveSchematicNode parent) { if(parent == null) { // Gracefully handle unexpected Updir in Root Folder depth = 0; return null; } if(!singleDirOpen) { - if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { - return null; + if(NodeMember.getNodeMember(parent.getNodeId(), user.getId()) != null) { + return EffectiveSchematicNode.byIdAndUser(user, parent.getNodeId()).flatMap(EffectiveSchematicNode::getNodeParent).flatMap(integer -> EffectiveSchematicNode.byIdAndUser(user, integer)).orElse(null); } else { - return getParent(parent); + return getParent(parent).orElse(null); } } else { - SchematicNode currentParent = parent; - boolean isMember = false; + Optional currentParent = Optional.of(parent); do { sdoTrigger = false; - if(NodeMember.getNodeMember(currentParent.getId(), user.getId()) != null) { - isMember = true; - } - currentParent = getParent(currentParent); - if(currentParent == null) + currentParent = currentParent.flatMap(SchematicSelector::getParent); + if(!currentParent.isPresent()) { break; - getSchematicList(currentParent); + } + getSchematicList(currentParent.get()); } while (sdoTrigger); - if(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { - return null; - } else { - return currentParent; - } + return currentParent.orElse(null); } } - private void handleClick(SchematicNode node, SchematicNode parent) { + private void handleClick(EffectiveSchematicNode node, EffectiveSchematicNode parent) { if(node == null) { depth--; openList(dirUp(parent)); @@ -220,12 +210,12 @@ public class SchematicSelector { sorting = all_sortings[next]; } - private List applySorting(List nodes) { + private List applySorting(List nodes) { if(sorting == Sorting.NAME && !invertSorting) { return nodes; } - Comparator comparator = sorting.comparator; + Comparator comparator = sorting.comparator; if(invertSorting) { comparator = comparator.reversed(); } @@ -234,19 +224,19 @@ public class SchematicSelector { return nodes; } - private SWListInv.SWListEntry renderItem(SchematicNode node) { - Material m = SWItem.getMaterial(node.getItem()); + private SWListInv.SWListEntry renderItem(EffectiveSchematicNode node) { + Material m = SWItem.getMaterial(node.getNodeItem()); - String name = Core.MESSAGE.parse(filter.name == null?"SCHEM_SELECTOR_ITEM_NAME":"SCHEM_SELECTOR_ITEM_NAME_FILTER", player, node.getName()); + String name = Core.MESSAGE.parse(filter.name == null?"SCHEM_SELECTOR_ITEM_NAME":"SCHEM_SELECTOR_ITEM_NAME_FILTER", player, node.getNodeName()); if(filter.getName() != null) { name = name.replace(filter.getName(), Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_REPLACE", player, filter.getName())); } - SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? (Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getSchemtype().name())), !node.isDir() && !node.getSchemtype().writeable(), click -> { + SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? (Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getNodeType().name())), !node.isDir() && !node.getNodeType().writeable(), click -> { }); - if(!node.isDir() && node.getRank() > 0) { - item.setLore(Arrays.asList(Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getSchemtype().name()), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player, node.getRank()))); + if(!node.isDir() && node.getNodeRank() > 0) { + item.setLore(Arrays.asList(Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getNodeType().name()), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player, node.getNodeRank()))); } return new SWListInv.SWListEntry<>(item, node); } @@ -265,13 +255,13 @@ public class SchematicSelector { }); } - private void createFolderIn(SchematicNode parent) { + private void createFolderIn(EffectiveSchematicNode parent) { SWAnvilInv inv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player)); inv.setItem(Material.CHEST, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false); inv.setCallback(s -> { if(!SchematicNode.invalidSchemName(new String[] {s})) { if(injectable.onFolderCreate(this, s)) { - SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId()); + SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getNodeId()); openList(parent); } return; @@ -396,8 +386,8 @@ public class SchematicSelector { inv.open(); } - private List getFilteredSchematics() { - List nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(user.getId())); + private List getFilteredSchematics() { + List nodes = new ArrayList<>(EffectiveSchematicNode.getAll(user)); nodes.removeIf(node -> { injectable.onNodeFilter(this, node); return !filter.matches(node); @@ -406,35 +396,31 @@ public class SchematicSelector { nodes.removeIf(node -> !node.isDir()); } if(target.target == Target.SCHEMATIC_TYPE) { - nodes.removeIf(node -> node.isDir() || !node.getSchemtype().equals(target.type) || node.getRank() > target.rank); + nodes.removeIf(node -> node.isDir() || !node.getNodeType().equals(target.type) || node.getNodeRank() > target.rank); } return nodes; } - private List getSchematicList(SchematicNode parent) { - List nodes = new ArrayList<>(); + private List getSchematicList(EffectiveSchematicNode parent) { + List nodes = new ArrayList<>(); switch (target.target) { case DIRECTORY: - if(parent == null) { - nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(user.getId(), null)); - nodes.removeIf(node -> !node.isDir()); - } else { - nodes.addAll(SchematicNode.getSchematicDirectoryInNode(parent.getId())); - } + nodes.addAll(EffectiveSchematicNode.list(user, Optional.ofNullable(parent).map(EffectiveSchematicNode::getNodeId).orElse(null))); + nodes.removeIf(node -> !node.isDir()); break; case SCHEMATIC_TYPE: - nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(user.getId(), target.type.toDB(), parent==null?0:parent.getId())); + nodes.addAll(EffectiveSchematicNode.accessibleByUserTypeMap(user, target.type).get(parent==null?0:parent.getNodeId())); if(target.rank >= 0) { nodes.removeIf(node -> { if(node.isDir()) { return false; } - return node.getRank() > target.rank; + return node.getNodeRank() > target.rank; }); } break; default: - nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(user.getId(), parent == null?0:parent.getId())); + nodes.addAll(EffectiveSchematicNode.list(user, parent == null?0:parent.getNodeId())); } if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { @@ -443,11 +429,8 @@ public class SchematicSelector { return nodes; } - private static SchematicNode getParent(SchematicNode node) { - if(node.getParent() == null) { - return null; - } - return node.getParentNode(); + private static Optional getParent(EffectiveSchematicNode node) { + return node.getNodeParent().flatMap(integer -> EffectiveSchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer)); } public static SelectorTarget selectSchematic() { @@ -513,26 +496,26 @@ public class SchematicSelector { filter = false; } - public boolean matches(SchematicNode node) { + public boolean matches(EffectiveSchematicNode node) { boolean matches = true; - if(name != null && !node.getName().contains(name)) { + if(name != null && !node.getNodeName().contains(name)) { matches = false; } - if(owner != null && node.getOwner() != owner) { + if(owner != null && node.getNodeOwner() != owner) { matches = false; } - if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) { + if(type != null && (node.isDir() || !node.getNodeType().equals(type))) { matches = false; } if(item != null) { String i; - if(node.getItem().isEmpty()) { + if(node.getNodeItem().isEmpty()) { i = node.isDir()?"CHEST":"CAULDRON"; } else { - i = node.getItem(); + i = node.getNodeItem(); } if(!item.name().equals(i)) { matches = false; @@ -550,19 +533,19 @@ public class SchematicSelector { @AllArgsConstructor private enum Sorting { - NAME(Material.PAPER, "SCHEM_SELECTOR_SORTING_NAME", Comparator.comparing(SchematicNode::getName)), + NAME(Material.PAPER, "SCHEM_SELECTOR_SORTING_NAME", Comparator.comparing(EffectiveSchematicNode::getNodeName)), TYPE(Material.CAULDRON, "SCHEM_SELECTOR_SORTING_TYPE", (o1, o2) -> { if(o1.isDir() || o2.isDir()) { return Boolean.compare(o1.isDir(), o2.isDir()); } else { - return o1.getSchemtype().name().compareTo(o2.getSchemtype().name()); + return o1.getNodeType().name().compareTo(o2.getNodeType().name()); } }), - LAST_UPDATED(SWItem.getMaterial("WATCH"), "SCHEM_SELECTOR_SORTING_UPDATE", Comparator.comparing(SchematicNode::getLastUpdate)); + LAST_UPDATED(SWItem.getMaterial("WATCH"), "SCHEM_SELECTOR_SORTING_UPDATE", Comparator.comparing(EffectiveSchematicNode::getLastUpdate)); private final Material mat; private final String name; - private final Comparator comparator; + private final Comparator comparator; private String parseName(Player player) { return Core.MESSAGE.parse(name, player); diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java index 235dda4..afc0e07 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java @@ -20,6 +20,7 @@ package de.steamwar.inventory; import de.steamwar.core.Core; +import de.steamwar.sql.EffectiveSchematicNode; import de.steamwar.sql.SchematicNode; import org.bukkit.entity.Player; @@ -33,7 +34,7 @@ public interface SchematicSelectorInjectable { default void onSelectorCreate(SchematicSelector selector) {} - default void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) {} + default void onListRender(SchematicSelector selector, SWListInv inv, EffectiveSchematicNode parent) {} default void onFilterRender(SchematicSelector selector, SWInventory inventory) {} @@ -41,7 +42,7 @@ public interface SchematicSelectorInjectable { default boolean onFolderCreate(SchematicSelector selector, String name) {return true;} - default void onNodeFilter(SchematicSelector selector, SchematicNode node) {} + default void onNodeFilter(SchematicSelector selector, EffectiveSchematicNode node) {} default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {} From 94fd8da7d313f74d09a73d1d26b0914c43133f6a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 15 Jan 2023 17:55:17 +0100 Subject: [PATCH 2/4] Add Copyright --- .../steamwar/inventory/SchematicSelector.java | 92 +++++++++---------- .../SchematicSelectorInjectable.java | 5 +- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 6c8318b..2bafb8d 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -41,7 +41,7 @@ public class SchematicSelector { private SteamwarUser user; @Getter @Setter - private Consumer callback; + private Consumer callback; private final SelectorTarget target; @Getter private final SelectorFilter filter = new SelectorFilter(); @@ -59,9 +59,9 @@ public class SchematicSelector { private Sorting sorting = Sorting.NAME; private boolean invertSorting = false; @Getter - private EffectiveSchematicNode lastParent; + private SchematicNode lastParent; - public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { + public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { this.player = player; this.user = SteamwarUser.get(player.getUniqueId()); this.target = target; @@ -69,7 +69,7 @@ public class SchematicSelector { this.singleDirOpen = !target.target.dirs; } - public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer callback) { + public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer callback) { this(player, target, callback); this.injectable = injectable; } @@ -94,9 +94,9 @@ public class SchematicSelector { injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); } - private void openList(EffectiveSchematicNode parent) { + private void openList(SchematicNode parent) { lastParent = parent; - List nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent)); + List nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent)); if(sdoTrigger) { sdoTrigger = false; @@ -104,18 +104,18 @@ public class SchematicSelector { return; } - List> list = new ArrayList<>(); + List> list = new ArrayList<>(); if(depth != 0) { list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null)); } - for (EffectiveSchematicNode node : nodes) { - if(node.getNodeName().equals("//copy")) continue; + for (SchematicNode node : nodes) { + if(node.getName().equals("//copy")) continue; list.add(renderItem(node)); } - SWListInv inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName() == null?(parent == null?"/":parent.generateBreadcrumbs()):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent)); + SWListInv inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName() == null?(parent == null?"/":parent.generateBreadcrumbs()):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent)); if(publicMode == PublicMode.ALL) { if(user.getId() == 0) { inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { @@ -155,20 +155,20 @@ public class SchematicSelector { inv.open(); } - private EffectiveSchematicNode dirUp(EffectiveSchematicNode parent) { + private SchematicNode dirUp(SchematicNode parent) { if(parent == null) { // Gracefully handle unexpected Updir in Root Folder depth = 0; return null; } if(!singleDirOpen) { - if(NodeMember.getNodeMember(parent.getNodeId(), user.getId()) != null) { - return EffectiveSchematicNode.byIdAndUser(user, parent.getNodeId()).flatMap(EffectiveSchematicNode::getNodeParent).flatMap(integer -> EffectiveSchematicNode.byIdAndUser(user, integer)).orElse(null); + if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { + return Optional.ofNullable(SchematicNode.byIdAndUser(user, parent.getId())).flatMap(SchematicNode::getOptionalParent).map(integer -> SchematicNode.byIdAndUser(user, integer)).orElse(null); } else { return getParent(parent).orElse(null); } } else { - Optional currentParent = Optional.of(parent); + Optional currentParent = Optional.of(parent); do { sdoTrigger = false; currentParent = currentParent.flatMap(SchematicSelector::getParent); @@ -181,7 +181,7 @@ public class SchematicSelector { } } - private void handleClick(EffectiveSchematicNode node, EffectiveSchematicNode parent) { + private void handleClick(SchematicNode node, SchematicNode parent) { if(node == null) { depth--; openList(dirUp(parent)); @@ -210,12 +210,12 @@ public class SchematicSelector { sorting = all_sortings[next]; } - private List applySorting(List nodes) { + private List applySorting(List nodes) { if(sorting == Sorting.NAME && !invertSorting) { return nodes; } - Comparator comparator = sorting.comparator; + Comparator comparator = sorting.comparator; if(invertSorting) { comparator = comparator.reversed(); } @@ -224,19 +224,19 @@ public class SchematicSelector { return nodes; } - private SWListInv.SWListEntry renderItem(EffectiveSchematicNode node) { - Material m = SWItem.getMaterial(node.getNodeItem()); + private SWListInv.SWListEntry renderItem(SchematicNode node) { + Material m = SWItem.getMaterial(node.getItem()); - String name = Core.MESSAGE.parse(filter.name == null?"SCHEM_SELECTOR_ITEM_NAME":"SCHEM_SELECTOR_ITEM_NAME_FILTER", player, node.getNodeName()); + String name = Core.MESSAGE.parse(filter.name == null?"SCHEM_SELECTOR_ITEM_NAME":"SCHEM_SELECTOR_ITEM_NAME_FILTER", player, node.getName()); if(filter.getName() != null) { name = name.replace(filter.getName(), Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_REPLACE", player, filter.getName())); } - SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? (Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getNodeType().name())), !node.isDir() && !node.getNodeType().writeable(), click -> { + SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? (Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getSchemtype().name())), !node.isDir() && !node.getSchemtype().writeable(), click -> { }); - if(!node.isDir() && node.getNodeRank() > 0) { - item.setLore(Arrays.asList(Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getNodeType().name()), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player, node.getNodeRank()))); + if(!node.isDir() && node.getRank() > 0) { + item.setLore(Arrays.asList(Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getSchemtype().name()), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player, node.getRank()))); } return new SWListInv.SWListEntry<>(item, node); } @@ -255,13 +255,13 @@ public class SchematicSelector { }); } - private void createFolderIn(EffectiveSchematicNode parent) { + private void createFolderIn(SchematicNode parent) { SWAnvilInv inv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player)); inv.setItem(Material.CHEST, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false); inv.setCallback(s -> { if(!SchematicNode.invalidSchemName(new String[] {s})) { if(injectable.onFolderCreate(this, s)) { - SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getNodeId()); + SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId()); openList(parent); } return; @@ -386,8 +386,8 @@ public class SchematicSelector { inv.open(); } - private List getFilteredSchematics() { - List nodes = new ArrayList<>(EffectiveSchematicNode.getAll(user)); + private List getFilteredSchematics() { + List nodes = new ArrayList<>(SchematicNode.getAll(user)); nodes.removeIf(node -> { injectable.onNodeFilter(this, node); return !filter.matches(node); @@ -396,31 +396,31 @@ public class SchematicSelector { nodes.removeIf(node -> !node.isDir()); } if(target.target == Target.SCHEMATIC_TYPE) { - nodes.removeIf(node -> node.isDir() || !node.getNodeType().equals(target.type) || node.getNodeRank() > target.rank); + nodes.removeIf(node -> node.isDir() || !node.getSchemtype().equals(target.type) || node.getRank() > target.rank); } return nodes; } - private List getSchematicList(EffectiveSchematicNode parent) { - List nodes = new ArrayList<>(); + private List getSchematicList(SchematicNode parent) { + List nodes = new ArrayList<>(); switch (target.target) { case DIRECTORY: - nodes.addAll(EffectiveSchematicNode.list(user, Optional.ofNullable(parent).map(EffectiveSchematicNode::getNodeId).orElse(null))); + nodes.addAll(SchematicNode.list(user, Optional.ofNullable(parent).map(SchematicNode::getId).orElse(null))); nodes.removeIf(node -> !node.isDir()); break; case SCHEMATIC_TYPE: - nodes.addAll(EffectiveSchematicNode.accessibleByUserTypeMap(user, target.type).get(parent==null?0:parent.getNodeId())); + nodes.addAll(SchematicNode.accessibleByUserTypeMap(user, target.type).get(parent==null?0:parent.getId())); if(target.rank >= 0) { nodes.removeIf(node -> { if(node.isDir()) { return false; } - return node.getNodeRank() > target.rank; + return node.getRank() > target.rank; }); } break; default: - nodes.addAll(EffectiveSchematicNode.list(user, parent == null?0:parent.getNodeId())); + nodes.addAll(SchematicNode.list(user, parent == null?0:parent.getId())); } if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { @@ -429,8 +429,8 @@ public class SchematicSelector { return nodes; } - private static Optional getParent(EffectiveSchematicNode node) { - return node.getNodeParent().flatMap(integer -> EffectiveSchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer)); + private static Optional getParent(SchematicNode node) { + return node.getOptionalParent().map(integer -> SchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer)); } public static SelectorTarget selectSchematic() { @@ -496,26 +496,26 @@ public class SchematicSelector { filter = false; } - public boolean matches(EffectiveSchematicNode node) { + public boolean matches(SchematicNode node) { boolean matches = true; - if(name != null && !node.getNodeName().contains(name)) { + if(name != null && !node.getName().contains(name)) { matches = false; } - if(owner != null && node.getNodeOwner() != owner) { + if(owner != null && node.getOwner() != owner) { matches = false; } - if(type != null && (node.isDir() || !node.getNodeType().equals(type))) { + if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) { matches = false; } if(item != null) { String i; - if(node.getNodeItem().isEmpty()) { + if(node.getItem().isEmpty()) { i = node.isDir()?"CHEST":"CAULDRON"; } else { - i = node.getNodeItem(); + i = node.getItem(); } if(!item.name().equals(i)) { matches = false; @@ -533,19 +533,19 @@ public class SchematicSelector { @AllArgsConstructor private enum Sorting { - NAME(Material.PAPER, "SCHEM_SELECTOR_SORTING_NAME", Comparator.comparing(EffectiveSchematicNode::getNodeName)), + NAME(Material.PAPER, "SCHEM_SELECTOR_SORTING_NAME", Comparator.comparing(SchematicNode::getName)), TYPE(Material.CAULDRON, "SCHEM_SELECTOR_SORTING_TYPE", (o1, o2) -> { if(o1.isDir() || o2.isDir()) { return Boolean.compare(o1.isDir(), o2.isDir()); } else { - return o1.getNodeType().name().compareTo(o2.getNodeType().name()); + return o1.getSchemtype().name().compareTo(o2.getSchemtype().name()); } }), - LAST_UPDATED(SWItem.getMaterial("WATCH"), "SCHEM_SELECTOR_SORTING_UPDATE", Comparator.comparing(EffectiveSchematicNode::getLastUpdate)); + LAST_UPDATED(SWItem.getMaterial("WATCH"), "SCHEM_SELECTOR_SORTING_UPDATE", Comparator.comparing(SchematicNode::getLastUpdate)); private final Material mat; private final String name; - private final Comparator comparator; + private final Comparator comparator; private String parseName(Player player) { return Core.MESSAGE.parse(name, player); diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java index afc0e07..235dda4 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java @@ -20,7 +20,6 @@ package de.steamwar.inventory; import de.steamwar.core.Core; -import de.steamwar.sql.EffectiveSchematicNode; import de.steamwar.sql.SchematicNode; import org.bukkit.entity.Player; @@ -34,7 +33,7 @@ public interface SchematicSelectorInjectable { default void onSelectorCreate(SchematicSelector selector) {} - default void onListRender(SchematicSelector selector, SWListInv inv, EffectiveSchematicNode parent) {} + default void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) {} default void onFilterRender(SchematicSelector selector, SWInventory inventory) {} @@ -42,7 +41,7 @@ public interface SchematicSelectorInjectable { default boolean onFolderCreate(SchematicSelector selector, String name) {return true;} - default void onNodeFilter(SchematicSelector selector, EffectiveSchematicNode node) {} + default void onNodeFilter(SchematicSelector selector, SchematicNode node) {} default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {} From a12e15266f27dd6565a6393dfd517c566f94974f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 16 Jan 2023 16:33:17 +0100 Subject: [PATCH 3/4] Fixes "0 wird nicht benutzt" --- CommonCore | 2 +- .../src/de/steamwar/inventory/SchematicSelector.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CommonCore b/CommonCore index 27d6e9a..d30650b 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 27d6e9accfa14fa8d5c74ebbcad9d8c2f17767c7 +Subproject commit d30650bad30d53b5fb6c4e5c9499b71c577cf849 diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 2bafb8d..8c7ed13 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -409,7 +409,7 @@ public class SchematicSelector { nodes.removeIf(node -> !node.isDir()); break; case SCHEMATIC_TYPE: - nodes.addAll(SchematicNode.accessibleByUserTypeMap(user, target.type).get(parent==null?0:parent.getId())); + nodes.addAll(SchematicNode.accessibleByUserTypeMap(user, target.type).get(parent==null?null:parent.getId())); if(target.rank >= 0) { nodes.removeIf(node -> { if(node.isDir()) { @@ -420,7 +420,7 @@ public class SchematicSelector { } break; default: - nodes.addAll(SchematicNode.list(user, parent == null?0:parent.getId())); + nodes.addAll(SchematicNode.list(user, parent == null?null:parent.getId())); } if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { From 400c7161f6029366ba8e7b35591d0a1dc5ff0860 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 17 Jan 2023 18:04:00 +0100 Subject: [PATCH 4/4] Update CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index d30650b..8b8e6a9 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit d30650bad30d53b5fb6c4e5c9499b71c577cf849 +Subproject commit 8b8e6a9e574040eea1bdea955f69263e63eb8078