SteamWar/SpigotCore
Archiviert
13
0

Add Copyright
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
Chaoscaot 2023-01-15 17:55:17 +01:00
Ursprung 9fb49405ca
Commit 94fd8da7d3
2 geänderte Dateien mit 48 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -41,7 +41,7 @@ public class SchematicSelector {
private SteamwarUser user; private SteamwarUser user;
@Getter @Getter
@Setter @Setter
private Consumer<EffectiveSchematicNode> callback; private Consumer<SchematicNode> callback;
private final SelectorTarget target; private final SelectorTarget target;
@Getter @Getter
private final SelectorFilter filter = new SelectorFilter(); private final SelectorFilter filter = new SelectorFilter();
@ -59,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 EffectiveSchematicNode lastParent; private SchematicNode lastParent;
public SchematicSelector(Player player, SelectorTarget target, Consumer<EffectiveSchematicNode> callback) { public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> 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;
@ -69,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<EffectiveSchematicNode> callback) { public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer<SchematicNode> callback) {
this(player, target, callback); this(player, target, callback);
this.injectable = injectable; this.injectable = injectable;
} }
@ -94,9 +94,9 @@ public class SchematicSelector {
injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN);
} }
private void openList(EffectiveSchematicNode parent) { private void openList(SchematicNode parent) {
lastParent = parent; lastParent = parent;
List<EffectiveSchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent)); List<SchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
if(sdoTrigger) { if(sdoTrigger) {
sdoTrigger = false; sdoTrigger = false;
@ -104,18 +104,18 @@ public class SchematicSelector {
return; return;
} }
List<SWListInv.SWListEntry<EffectiveSchematicNode>> list = new ArrayList<>(); List<SWListInv.SWListEntry<SchematicNode>> 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 (EffectiveSchematicNode node : nodes) { for (SchematicNode node : nodes) {
if(node.getNodeName().equals("//copy")) continue; if(node.getName().equals("//copy")) continue;
list.add(renderItem(node)); list.add(renderItem(node));
} }
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)); 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 -> {
@ -155,20 +155,20 @@ public class SchematicSelector {
inv.open(); inv.open();
} }
private EffectiveSchematicNode dirUp(EffectiveSchematicNode parent) { private SchematicNode dirUp(SchematicNode 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.getNodeId(), user.getId()) != null) { if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
return EffectiveSchematicNode.byIdAndUser(user, parent.getNodeId()).flatMap(EffectiveSchematicNode::getNodeParent).flatMap(integer -> EffectiveSchematicNode.byIdAndUser(user, integer)).orElse(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).orElse(null); return getParent(parent).orElse(null);
} }
} else { } else {
Optional<EffectiveSchematicNode> currentParent = Optional.of(parent); Optional<SchematicNode> currentParent = Optional.of(parent);
do { do {
sdoTrigger = false; sdoTrigger = false;
currentParent = currentParent.flatMap(SchematicSelector::getParent); 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) { if(node == null) {
depth--; depth--;
openList(dirUp(parent)); openList(dirUp(parent));
@ -210,12 +210,12 @@ public class SchematicSelector {
sorting = all_sortings[next]; sorting = all_sortings[next];
} }
private List<EffectiveSchematicNode> applySorting(List<EffectiveSchematicNode> nodes) { private List<SchematicNode> applySorting(List<SchematicNode> nodes) {
if(sorting == Sorting.NAME && !invertSorting) { if(sorting == Sorting.NAME && !invertSorting) {
return nodes; return nodes;
} }
Comparator<EffectiveSchematicNode> comparator = sorting.comparator; Comparator<SchematicNode> comparator = sorting.comparator;
if(invertSorting) { if(invertSorting) {
comparator = comparator.reversed(); comparator = comparator.reversed();
} }
@ -224,19 +224,19 @@ public class SchematicSelector {
return nodes; return nodes;
} }
private SWListInv.SWListEntry<EffectiveSchematicNode> renderItem(EffectiveSchematicNode node) { private SWListInv.SWListEntry<SchematicNode> renderItem(SchematicNode node) {
Material m = SWItem.getMaterial(node.getNodeItem()); 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) { 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.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) { if(!node.isDir() && node.getRank() > 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()))); 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); 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)); 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.getNodeId()); SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId());
openList(parent); openList(parent);
} }
return; return;
@ -386,8 +386,8 @@ public class SchematicSelector {
inv.open(); inv.open();
} }
private List<EffectiveSchematicNode> getFilteredSchematics() { private List<SchematicNode> getFilteredSchematics() {
List<EffectiveSchematicNode> nodes = new ArrayList<>(EffectiveSchematicNode.getAll(user)); 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);
@ -396,31 +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.getNodeType().equals(target.type) || node.getNodeRank() > target.rank); nodes.removeIf(node -> node.isDir() || !node.getSchemtype().equals(target.type) || node.getRank() > target.rank);
} }
return nodes; return nodes;
} }
private List<EffectiveSchematicNode> getSchematicList(EffectiveSchematicNode parent) { private List<SchematicNode> getSchematicList(SchematicNode parent) {
List<EffectiveSchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
switch (target.target) { switch (target.target) {
case DIRECTORY: 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()); nodes.removeIf(node -> !node.isDir());
break; break;
case SCHEMATIC_TYPE: 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) { if(target.rank >= 0) {
nodes.removeIf(node -> { nodes.removeIf(node -> {
if(node.isDir()) { if(node.isDir()) {
return false; return false;
} }
return node.getNodeRank() > target.rank; return node.getRank() > target.rank;
}); });
} }
break; break;
default: 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()) { if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
@ -429,8 +429,8 @@ public class SchematicSelector {
return nodes; return nodes;
} }
private static Optional<EffectiveSchematicNode> getParent(EffectiveSchematicNode node) { private static Optional<SchematicNode> getParent(SchematicNode node) {
return node.getNodeParent().flatMap(integer -> EffectiveSchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer)); return node.getOptionalParent().map(integer -> SchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer));
} }
public static SelectorTarget selectSchematic() { public static SelectorTarget selectSchematic() {
@ -496,26 +496,26 @@ public class SchematicSelector {
filter = false; filter = false;
} }
public boolean matches(EffectiveSchematicNode node) { public boolean matches(SchematicNode node) {
boolean matches = true; boolean matches = true;
if(name != null && !node.getNodeName().contains(name)) { if(name != null && !node.getName().contains(name)) {
matches = false; matches = false;
} }
if(owner != null && node.getNodeOwner() != owner) { if(owner != null && node.getOwner() != owner) {
matches = false; matches = false;
} }
if(type != null && (node.isDir() || !node.getNodeType().equals(type))) { if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) {
matches = false; matches = false;
} }
if(item != null) { if(item != null) {
String i; String i;
if(node.getNodeItem().isEmpty()) { if(node.getItem().isEmpty()) {
i = node.isDir()?"CHEST":"CAULDRON"; i = node.isDir()?"CHEST":"CAULDRON";
} else { } else {
i = node.getNodeItem(); i = node.getItem();
} }
if(!item.name().equals(i)) { if(!item.name().equals(i)) {
matches = false; matches = false;
@ -533,19 +533,19 @@ public class SchematicSelector {
@AllArgsConstructor @AllArgsConstructor
private enum Sorting { 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) -> { 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.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 Material mat;
private final String name; private final String name;
private final Comparator<EffectiveSchematicNode> comparator; private final Comparator<SchematicNode> 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,7 +20,6 @@
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;
@ -34,7 +33,7 @@ public interface SchematicSelectorInjectable {
default void onSelectorCreate(SchematicSelector selector) {} default void onSelectorCreate(SchematicSelector selector) {}
default void onListRender(SchematicSelector selector, SWListInv<EffectiveSchematicNode> inv, EffectiveSchematicNode parent) {} default void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent) {}
default void onFilterRender(SchematicSelector selector, SWInventory inventory) {} default void onFilterRender(SchematicSelector selector, SWInventory inventory) {}
@ -42,7 +41,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, EffectiveSchematicNode node) {} default void onNodeFilter(SchematicSelector selector, SchematicNode node) {}
default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {} default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {}