SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'NodeMember: SpigotCore' (#221) from nodemember into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #221
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2023-01-17 18:09:51 +01:00
Commit 5ed8a89d07
2 geänderte Dateien mit 18 neuen und 35 gelöschten Zeilen

@ -1 +1 @@
Subproject commit d56150a8b105f5ad63a8c3a21b6833f388a83225 Subproject commit 8b8e6a9e574040eea1bdea955f69263e63eb8078

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;
@ -118,7 +115,7 @@ public class SchematicSelector {
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<SchematicNode> 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 -> {
@ -166,28 +163,21 @@ public class SchematicSelector {
} }
if(!singleDirOpen) { if(!singleDirOpen) {
if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
return null; return Optional.ofNullable(SchematicNode.byIdAndUser(user, parent.getId())).flatMap(SchematicNode::getOptionalParent).map(integer -> SchematicNode.byIdAndUser(user, integer)).orElse(null);
} else { } else {
return getParent(parent); return getParent(parent).orElse(null);
} }
} else { } else {
SchematicNode currentParent = parent; Optional<SchematicNode> 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);
} while (sdoTrigger);
if(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
return null;
} else {
return currentParent;
} }
getSchematicList(currentParent.get());
} while (sdoTrigger);
return currentParent.orElse(null);
} }
} }
@ -397,7 +387,7 @@ public class SchematicSelector {
} }
private List<SchematicNode> getFilteredSchematics() { private List<SchematicNode> getFilteredSchematics() {
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(user.getId())); List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAll(user));
nodes.removeIf(node -> { nodes.removeIf(node -> {
injectable.onNodeFilter(this, node); injectable.onNodeFilter(this, node);
return !filter.matches(node); return !filter.matches(node);
@ -415,15 +405,11 @@ public class SchematicSelector {
List<SchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
switch (target.target) { switch (target.target) {
case DIRECTORY: case DIRECTORY:
if(parent == null) { nodes.addAll(SchematicNode.list(user, Optional.ofNullable(parent).map(SchematicNode::getId).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(SchematicNode.accessibleByUserTypeMap(user, target.type).get(parent==null?null:parent.getId()));
if(target.rank >= 0) { if(target.rank >= 0) {
nodes.removeIf(node -> { nodes.removeIf(node -> {
if(node.isDir()) { if(node.isDir()) {
@ -434,7 +420,7 @@ public class SchematicSelector {
} }
break; break;
default: default:
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(user.getId(), parent == null?0:parent.getId())); nodes.addAll(SchematicNode.list(user, parent == null?null:parent.getId()));
} }
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<SchematicNode> getParent(SchematicNode node) {
if(node.getParent() == null) { return node.getOptionalParent().map(integer -> SchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer));
return null;
}
return node.getParentNode();
} }
public static SelectorTarget selectSchematic() { public static SelectorTarget selectSchematic() {