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;
@Getter
@Setter
private Consumer<EffectiveSchematicNode> callback;
private Consumer<SchematicNode> callback;
private final SelectorTarget target;
@Getter
private final SelectorFilter filter = new SelectorFilter();
@ -59,9 +59,9 @@ public class SchematicSelector {
private Sorting sorting = Sorting.NAME;
private boolean invertSorting = false;
@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.user = SteamwarUser.get(player.getUniqueId());
this.target = target;
@ -69,7 +69,7 @@ public class SchematicSelector {
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.injectable = injectable;
}
@ -94,9 +94,9 @@ public class SchematicSelector {
injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN);
}
private void openList(EffectiveSchematicNode parent) {
private void openList(SchematicNode parent) {
lastParent = parent;
List<EffectiveSchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
List<SchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
if(sdoTrigger) {
sdoTrigger = false;
@ -104,18 +104,18 @@ public class SchematicSelector {
return;
}
List<SWListInv.SWListEntry<EffectiveSchematicNode>> list = new ArrayList<>();
List<SWListInv.SWListEntry<SchematicNode>> 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 (EffectiveSchematicNode node : nodes) {
if(node.getNodeName().equals("//copy")) continue;
for (SchematicNode node : nodes) {
if(node.getName().equals("//copy")) continue;
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(user.getId() == 0) {
inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> {
@ -155,20 +155,20 @@ public class SchematicSelector {
inv.open();
}
private EffectiveSchematicNode dirUp(EffectiveSchematicNode parent) {
private SchematicNode dirUp(SchematicNode parent) {
if(parent == null) {
// Gracefully handle unexpected Updir in Root Folder
depth = 0;
return null;
}
if(!singleDirOpen) {
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);
if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
return Optional.ofNullable(SchematicNode.byIdAndUser(user, parent.getId())).flatMap(SchematicNode::getOptionalParent).map(integer -> SchematicNode.byIdAndUser(user, integer)).orElse(null);
} else {
return getParent(parent).orElse(null);
}
} else {
Optional<EffectiveSchematicNode> currentParent = Optional.of(parent);
Optional<SchematicNode> currentParent = Optional.of(parent);
do {
sdoTrigger = false;
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) {
depth--;
openList(dirUp(parent));
@ -210,12 +210,12 @@ public class SchematicSelector {
sorting = all_sortings[next];
}
private List<EffectiveSchematicNode> applySorting(List<EffectiveSchematicNode> nodes) {
private List<SchematicNode> applySorting(List<SchematicNode> nodes) {
if(sorting == Sorting.NAME && !invertSorting) {
return nodes;
}
Comparator<EffectiveSchematicNode> comparator = sorting.comparator;
Comparator<SchematicNode> comparator = sorting.comparator;
if(invertSorting) {
comparator = comparator.reversed();
}
@ -224,19 +224,19 @@ public class SchematicSelector {
return nodes;
}
private SWListInv.SWListEntry<EffectiveSchematicNode> renderItem(EffectiveSchematicNode node) {
Material m = SWItem.getMaterial(node.getNodeItem());
private SWListInv.SWListEntry<SchematicNode> renderItem(SchematicNode node) {
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) {
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) {
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())));
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())));
}
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));
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.getNodeId());
SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId());
openList(parent);
}
return;
@ -386,8 +386,8 @@ public class SchematicSelector {
inv.open();
}
private List<EffectiveSchematicNode> getFilteredSchematics() {
List<EffectiveSchematicNode> nodes = new ArrayList<>(EffectiveSchematicNode.getAll(user));
private List<SchematicNode> getFilteredSchematics() {
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAll(user));
nodes.removeIf(node -> {
injectable.onNodeFilter(this, node);
return !filter.matches(node);
@ -396,31 +396,31 @@ public class SchematicSelector {
nodes.removeIf(node -> !node.isDir());
}
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;
}
private List<EffectiveSchematicNode> getSchematicList(EffectiveSchematicNode parent) {
List<EffectiveSchematicNode> nodes = new ArrayList<>();
private List<SchematicNode> getSchematicList(SchematicNode parent) {
List<SchematicNode> nodes = new ArrayList<>();
switch (target.target) {
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());
break;
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) {
nodes.removeIf(node -> {
if(node.isDir()) {
return false;
}
return node.getNodeRank() > target.rank;
return node.getRank() > target.rank;
});
}
break;
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()) {
@ -429,8 +429,8 @@ public class SchematicSelector {
return nodes;
}
private static Optional<EffectiveSchematicNode> getParent(EffectiveSchematicNode node) {
return node.getNodeParent().flatMap(integer -> EffectiveSchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer));
private static Optional<SchematicNode> getParent(SchematicNode node) {
return node.getOptionalParent().map(integer -> SchematicNode.byIdAndUser(SteamwarUser.get(node.getEffectiveOwner()), integer));
}
public static SelectorTarget selectSchematic() {
@ -496,26 +496,26 @@ public class SchematicSelector {
filter = false;
}
public boolean matches(EffectiveSchematicNode node) {
public boolean matches(SchematicNode node) {
boolean matches = true;
if(name != null && !node.getNodeName().contains(name)) {
if(name != null && !node.getName().contains(name)) {
matches = false;
}
if(owner != null && node.getNodeOwner() != owner) {
if(owner != null && node.getOwner() != owner) {
matches = false;
}
if(type != null && (node.isDir() || !node.getNodeType().equals(type))) {
if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) {
matches = false;
}
if(item != null) {
String i;
if(node.getNodeItem().isEmpty()) {
if(node.getItem().isEmpty()) {
i = node.isDir()?"CHEST":"CAULDRON";
} else {
i = node.getNodeItem();
i = node.getItem();
}
if(!item.name().equals(i)) {
matches = false;
@ -533,19 +533,19 @@ public class SchematicSelector {
@AllArgsConstructor
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) -> {
if(o1.isDir() || o2.isDir()) {
return Boolean.compare(o1.isDir(), o2.isDir());
} 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 String name;
private final Comparator<EffectiveSchematicNode> comparator;
private final Comparator<SchematicNode> comparator;
private String parseName(Player player) {
return Core.MESSAGE.parse(name, player);

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.inventory;
import de.steamwar.core.Core;
import de.steamwar.sql.EffectiveSchematicNode;
import de.steamwar.sql.SchematicNode;
import org.bukkit.entity.Player;
@ -34,7 +33,7 @@ public interface SchematicSelectorInjectable {
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) {}
@ -42,7 +41,7 @@ public interface SchematicSelectorInjectable {
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) {}