SteamWar/SpigotCore
Archiviert
13
0

NodeMember: Move Member Schematics
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Chaoscaot 2023-01-12 21:53:28 +01:00
Ursprung 36fe101e56
Commit 9fb49405ca
3 geänderte Dateien mit 58 neuen und 74 gelöschten Zeilen

@ -1 +1 @@
Subproject commit c6da22f0bee3865b7b3283bc17275e12c5de14af Subproject commit 8ce900db31e5c4cf0cc5a39dcb61bed297b9d392

Datei anzeigen

@ -20,10 +20,7 @@
package de.steamwar.inventory; package de.steamwar.inventory;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.sql.NodeMember; import de.steamwar.sql.*;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
import lombok.*; import lombok.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -44,7 +41,7 @@ public class SchematicSelector {
private SteamwarUser user; private SteamwarUser user;
@Getter @Getter
@Setter @Setter
private Consumer<SchematicNode> callback; private Consumer<EffectiveSchematicNode> callback;
private final SelectorTarget target; private final SelectorTarget target;
@Getter @Getter
private final SelectorFilter filter = new SelectorFilter(); private final SelectorFilter filter = new SelectorFilter();
@ -62,9 +59,9 @@ public class SchematicSelector {
private Sorting sorting = Sorting.NAME; private Sorting sorting = Sorting.NAME;
private boolean invertSorting = false; private boolean invertSorting = false;
@Getter @Getter
private SchematicNode lastParent; private EffectiveSchematicNode lastParent;
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) { public SchematicSelector(Player player, SelectorTarget target, Consumer<EffectiveSchematicNode> callback) {
this.player = player; this.player = player;
this.user = SteamwarUser.get(player.getUniqueId()); this.user = SteamwarUser.get(player.getUniqueId());
this.target = target; this.target = target;
@ -72,7 +69,7 @@ public class SchematicSelector {
this.singleDirOpen = !target.target.dirs; this.singleDirOpen = !target.target.dirs;
} }
public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer<SchematicNode> callback) { public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer<EffectiveSchematicNode> callback) {
this(player, target, callback); this(player, target, callback);
this.injectable = injectable; this.injectable = injectable;
} }
@ -97,9 +94,9 @@ public class SchematicSelector {
injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN);
} }
private void openList(SchematicNode parent) { private void openList(EffectiveSchematicNode parent) {
lastParent = parent; lastParent = parent;
List<SchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent)); List<EffectiveSchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
if(sdoTrigger) { if(sdoTrigger) {
sdoTrigger = false; sdoTrigger = false;
@ -107,18 +104,18 @@ public class SchematicSelector {
return; return;
} }
List<SWListInv.SWListEntry<SchematicNode>> list = new ArrayList<>(); List<SWListInv.SWListEntry<EffectiveSchematicNode>> list = new ArrayList<>();
if(depth != 0) { if(depth != 0) {
list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null)); list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null));
} }
for (SchematicNode node : nodes) { for (EffectiveSchematicNode node : nodes) {
if(node.getName().equals("//copy")) continue; if(node.getNodeName().equals("//copy")) continue;
list.add(renderItem(node)); list.add(renderItem(node));
} }
SWListInv<SchematicNode> 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<EffectiveSchematicNode> 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(publicMode == PublicMode.ALL) {
if(user.getId() == 0) { if(user.getId() == 0) {
inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> {
@ -158,40 +155,33 @@ public class SchematicSelector {
inv.open(); inv.open();
} }
private SchematicNode dirUp(SchematicNode parent) { private EffectiveSchematicNode dirUp(EffectiveSchematicNode parent) {
if(parent == null) { if(parent == null) {
// Gracefully handle unexpected Updir in Root Folder // Gracefully handle unexpected Updir in Root Folder
depth = 0; depth = 0;
return null; return null;
} }
if(!singleDirOpen) { if(!singleDirOpen) {
if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { if(NodeMember.getNodeMember(parent.getNodeId(), user.getId()) != null) {
return null; return EffectiveSchematicNode.byIdAndUser(user, parent.getNodeId()).flatMap(EffectiveSchematicNode::getNodeParent).flatMap(integer -> EffectiveSchematicNode.byIdAndUser(user, integer)).orElse(null);
} else { } else {
return getParent(parent); return getParent(parent).orElse(null);
} }
} else { } else {
SchematicNode currentParent = parent; Optional<EffectiveSchematicNode> currentParent = Optional.of(parent);
boolean isMember = false;
do { do {
sdoTrigger = false; sdoTrigger = false;
if(NodeMember.getNodeMember(currentParent.getId(), user.getId()) != null) { currentParent = currentParent.flatMap(SchematicSelector::getParent);
isMember = true; if(!currentParent.isPresent()) {
}
currentParent = getParent(currentParent);
if(currentParent == null)
break; break;
getSchematicList(currentParent); }
getSchematicList(currentParent.get());
} while (sdoTrigger); } while (sdoTrigger);
if(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { return currentParent.orElse(null);
return null;
} else {
return currentParent;
}
} }
} }
private void handleClick(SchematicNode node, SchematicNode parent) { private void handleClick(EffectiveSchematicNode node, EffectiveSchematicNode parent) {
if(node == null) { if(node == null) {
depth--; depth--;
openList(dirUp(parent)); openList(dirUp(parent));
@ -220,12 +210,12 @@ public class SchematicSelector {
sorting = all_sortings[next]; sorting = all_sortings[next];
} }
private List<SchematicNode> applySorting(List<SchematicNode> nodes) { private List<EffectiveSchematicNode> applySorting(List<EffectiveSchematicNode> nodes) {
if(sorting == Sorting.NAME && !invertSorting) { if(sorting == Sorting.NAME && !invertSorting) {
return nodes; return nodes;
} }
Comparator<SchematicNode> comparator = sorting.comparator; Comparator<EffectiveSchematicNode> comparator = sorting.comparator;
if(invertSorting) { if(invertSorting) {
comparator = comparator.reversed(); comparator = comparator.reversed();
} }
@ -234,19 +224,19 @@ public class SchematicSelector {
return nodes; return nodes;
} }
private SWListInv.SWListEntry<SchematicNode> renderItem(SchematicNode node) { private SWListInv.SWListEntry<EffectiveSchematicNode> renderItem(EffectiveSchematicNode node) {
Material m = SWItem.getMaterial(node.getItem()); 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) { if(filter.getName() != null) {
name = name.replace(filter.getName(), Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_REPLACE", player, filter.getName())); 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) { if(!node.isDir() && node.getNodeRank() > 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()))); 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); 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)); 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.setItem(Material.CHEST, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false);
inv.setCallback(s -> { inv.setCallback(s -> {
if(!SchematicNode.invalidSchemName(new String[] {s})) { if(!SchematicNode.invalidSchemName(new String[] {s})) {
if(injectable.onFolderCreate(this, 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); openList(parent);
} }
return; return;
@ -396,8 +386,8 @@ public class SchematicSelector {
inv.open(); inv.open();
} }
private List<SchematicNode> getFilteredSchematics() { private List<EffectiveSchematicNode> getFilteredSchematics() {
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(user.getId())); List<EffectiveSchematicNode> nodes = new ArrayList<>(EffectiveSchematicNode.getAll(user));
nodes.removeIf(node -> { nodes.removeIf(node -> {
injectable.onNodeFilter(this, node); injectable.onNodeFilter(this, node);
return !filter.matches(node); return !filter.matches(node);
@ -406,35 +396,31 @@ public class SchematicSelector {
nodes.removeIf(node -> !node.isDir()); nodes.removeIf(node -> !node.isDir());
} }
if(target.target == Target.SCHEMATIC_TYPE) { 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; return nodes;
} }
private List<SchematicNode> getSchematicList(SchematicNode parent) { private List<EffectiveSchematicNode> getSchematicList(EffectiveSchematicNode parent) {
List<SchematicNode> nodes = new ArrayList<>(); List<EffectiveSchematicNode> nodes = new ArrayList<>();
switch (target.target) { switch (target.target) {
case DIRECTORY: case DIRECTORY:
if(parent == null) { nodes.addAll(EffectiveSchematicNode.list(user, Optional.ofNullable(parent).map(EffectiveSchematicNode::getNodeId).orElse(null)));
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(user.getId(), null)); nodes.removeIf(node -> !node.isDir());
nodes.removeIf(node -> !node.isDir());
} else {
nodes.addAll(SchematicNode.getSchematicDirectoryInNode(parent.getId()));
}
break; break;
case SCHEMATIC_TYPE: 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) { if(target.rank >= 0) {
nodes.removeIf(node -> { nodes.removeIf(node -> {
if(node.isDir()) { if(node.isDir()) {
return false; return false;
} }
return node.getRank() > target.rank; return node.getNodeRank() > target.rank;
}); });
} }
break; break;
default: 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()) { if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
@ -443,11 +429,8 @@ public class SchematicSelector {
return nodes; return nodes;
} }
private static SchematicNode getParent(SchematicNode node) { private static Optional<EffectiveSchematicNode> getParent(EffectiveSchematicNode node) {
if(node.getParent() == null) { return node.getNodeParent().flatMap(integer -> EffectiveSchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer));
return null;
}
return node.getParentNode();
} }
public static SelectorTarget selectSchematic() { public static SelectorTarget selectSchematic() {
@ -513,26 +496,26 @@ public class SchematicSelector {
filter = false; filter = false;
} }
public boolean matches(SchematicNode node) { public boolean matches(EffectiveSchematicNode node) {
boolean matches = true; boolean matches = true;
if(name != null && !node.getName().contains(name)) { if(name != null && !node.getNodeName().contains(name)) {
matches = false; matches = false;
} }
if(owner != null && node.getOwner() != owner) { if(owner != null && node.getNodeOwner() != owner) {
matches = false; matches = false;
} }
if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) { if(type != null && (node.isDir() || !node.getNodeType().equals(type))) {
matches = false; matches = false;
} }
if(item != null) { if(item != null) {
String i; String i;
if(node.getItem().isEmpty()) { if(node.getNodeItem().isEmpty()) {
i = node.isDir()?"CHEST":"CAULDRON"; i = node.isDir()?"CHEST":"CAULDRON";
} else { } else {
i = node.getItem(); i = node.getNodeItem();
} }
if(!item.name().equals(i)) { if(!item.name().equals(i)) {
matches = false; matches = false;
@ -550,19 +533,19 @@ public class SchematicSelector {
@AllArgsConstructor @AllArgsConstructor
private enum Sorting { 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) -> { TYPE(Material.CAULDRON, "SCHEM_SELECTOR_SORTING_TYPE", (o1, o2) -> {
if(o1.isDir() || o2.isDir()) { if(o1.isDir() || o2.isDir()) {
return Boolean.compare(o1.isDir(), o2.isDir()); return Boolean.compare(o1.isDir(), o2.isDir());
} else { } 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 Material mat;
private final String name; private final String name;
private final Comparator<SchematicNode> comparator; private final Comparator<EffectiveSchematicNode> comparator;
private String parseName(Player player) { private String parseName(Player player) {
return Core.MESSAGE.parse(name, player); return Core.MESSAGE.parse(name, player);

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.inventory; package de.steamwar.inventory;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.sql.EffectiveSchematicNode;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -33,7 +34,7 @@ public interface SchematicSelectorInjectable {
default void onSelectorCreate(SchematicSelector selector) {} default void onSelectorCreate(SchematicSelector selector) {}
default void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent) {} default void onListRender(SchematicSelector selector, SWListInv<EffectiveSchematicNode> inv, EffectiveSchematicNode parent) {}
default void onFilterRender(SchematicSelector selector, SWInventory inventory) {} default void onFilterRender(SchematicSelector selector, SWInventory inventory) {}
@ -41,7 +42,7 @@ public interface SchematicSelectorInjectable {
default boolean onFolderCreate(SchematicSelector selector, String name) {return true;} 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) {} default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {}