SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Some Fixes for SchematicSelector' (#140) from fix_rank into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #140
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2021-12-27 16:29:43 +01:00
Commit 9b1d88b4f5
2 geänderte Dateien mit 46 neuen und 9 gelöschten Zeilen

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.NodeMember;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType; import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
@ -52,6 +53,9 @@ public class SchematicSelector {
@Getter @Getter
private boolean singleDirOpen; private boolean singleDirOpen;
private boolean sdoTrigger = false; private boolean sdoTrigger = false;
@Getter
@Setter
private int depth = 0;
private Sorting sorting = Sorting.NAME; private Sorting sorting = Sorting.NAME;
private boolean invertSorting = false; private boolean invertSorting = false;
@ -81,12 +85,13 @@ public class SchematicSelector {
if(sdoTrigger) { if(sdoTrigger) {
sdoTrigger = false; sdoTrigger = false;
openList(nodes.get(0));
return; return;
} }
List<SWListInv.SWListEntry<SchematicNode>> list = new ArrayList<>(); List<SWListInv.SWListEntry<SchematicNode>> list = new ArrayList<>();
if(parent != null) { 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));
} }
@ -137,7 +142,32 @@ public class SchematicSelector {
private void handleClick(SchematicNode node, SchematicNode parent) { private void handleClick(SchematicNode node, SchematicNode parent) {
if(node == null) { if(node == null) {
openList(getParent(parent)); depth--;
if(!singleDirOpen) {
if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
openList(null);
} else {
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(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
openList(null);
} else {
openList(currentParent);
}
}
return; return;
} }
if(node.isDir()) { if(node.isDir()) {
@ -147,6 +177,7 @@ public class SchematicSelector {
return; return;
} }
filter.reset(); filter.reset();
depth++;
openList(node); openList(node);
return; return;
} }
@ -323,7 +354,7 @@ 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.getType().equals(target.type.toDB())); nodes.removeIf(node -> node.isDir() || !node.getSchemtype().equals(target.type));
} }
return nodes; return nodes;
} }
@ -342,7 +373,12 @@ public class SchematicSelector {
case SCHEMATIC_TYPE: case SCHEMATIC_TYPE:
nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(user.getId(), target.type.toDB(), parent==null?0:parent.getId())); nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(user.getId(), target.type.toDB(), parent==null?0:parent.getId()));
if(target.rank >= 0) { 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; break;
default: default:
@ -350,7 +386,6 @@ public class SchematicSelector {
} }
if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
openList(nodes.get(0));
sdoTrigger = true; sdoTrigger = true;
} }
return nodes; return nodes;

Datei anzeigen

@ -34,6 +34,7 @@ import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@ -488,13 +489,14 @@ public class SchematicNode {
StringBuilder builder = new StringBuilder(getName()); StringBuilder builder = new StringBuilder(getName());
SchematicNode currentNode = this; SchematicNode currentNode = this;
if (currentNode.isDir()) builder.append("/"); if (currentNode.isDir()) builder.append("/");
while (currentNode.getParentNode() != null) { final Set<NodeMember> 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(); currentNode = currentNode.getParentNode();
i.set(currentNode.getId());
builder.insert(0, split) builder.insert(0, split)
.insert(0, currentNode.getName()); .insert(0, currentNode.getName());
if (currentNode.getMembers().stream().anyMatch(member -> member.getMember() == user.getId())) {
break;
}
} }
return builder.toString(); return builder.toString();
} }