|
|
|
@ -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<SchematicNode> callback;
|
|
|
|
|
private Consumer<EffectiveSchematicNode> 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<SchematicNode> callback) {
|
|
|
|
|
public SchematicSelector(Player player, SelectorTarget target, Consumer<EffectiveSchematicNode> 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<SchematicNode> callback) {
|
|
|
|
|
public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer<EffectiveSchematicNode> 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<SchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
|
|
|
|
|
List<EffectiveSchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
|
|
|
|
|
|
|
|
|
|
if(sdoTrigger) {
|
|
|
|
|
sdoTrigger = false;
|
|
|
|
@ -107,18 +104,18 @@ public class SchematicSelector {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<SWListInv.SWListEntry<SchematicNode>> list = new ArrayList<>();
|
|
|
|
|
List<SWListInv.SWListEntry<EffectiveSchematicNode>> 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<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(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<EffectiveSchematicNode> 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<SchematicNode> applySorting(List<SchematicNode> nodes) {
|
|
|
|
|
private List<EffectiveSchematicNode> applySorting(List<EffectiveSchematicNode> nodes) {
|
|
|
|
|
if(sorting == Sorting.NAME && !invertSorting) {
|
|
|
|
|
return nodes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Comparator<SchematicNode> comparator = sorting.comparator;
|
|
|
|
|
Comparator<EffectiveSchematicNode> comparator = sorting.comparator;
|
|
|
|
|
if(invertSorting) {
|
|
|
|
|
comparator = comparator.reversed();
|
|
|
|
|
}
|
|
|
|
@ -234,19 +224,19 @@ public class SchematicSelector {
|
|
|
|
|
return nodes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SWListInv.SWListEntry<SchematicNode> renderItem(SchematicNode node) {
|
|
|
|
|
Material m = SWItem.getMaterial(node.getItem());
|
|
|
|
|
private SWListInv.SWListEntry<EffectiveSchematicNode> 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<SchematicNode> getFilteredSchematics() {
|
|
|
|
|
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(user.getId()));
|
|
|
|
|
private List<EffectiveSchematicNode> getFilteredSchematics() {
|
|
|
|
|
List<EffectiveSchematicNode> 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<SchematicNode> getSchematicList(SchematicNode parent) {
|
|
|
|
|
List<SchematicNode> nodes = new ArrayList<>();
|
|
|
|
|
private List<EffectiveSchematicNode> getSchematicList(EffectiveSchematicNode parent) {
|
|
|
|
|
List<EffectiveSchematicNode> 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<EffectiveSchematicNode> 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<SchematicNode> comparator;
|
|
|
|
|
private final Comparator<EffectiveSchematicNode> comparator;
|
|
|
|
|
|
|
|
|
|
private String parseName(Player player) {
|
|
|
|
|
return Core.MESSAGE.parse(name, player);
|
|
|
|
|
Das wird nach dem Merge im CommonCore nochmal aktualisiert werden müssen.