SteamWar/SpigotCore
Archiviert
13
0

Fix Language & more PR Stuff
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-11-27 10:13:19 +01:00
Ursprung 6ecd8a5f0e
Commit cf9f2a2375
4 geänderte Dateien mit 84 neuen und 101 gelöschten Zeilen

Datei anzeigen

@ -27,23 +27,22 @@ SCHEM_SELECTOR_SEL_DIR=
SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner
SCHEM_SELECTOR_FILTER=§7Filter
SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner Erstellen
SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner erstellen
SCHEM_SELECTOR_FILTER_TITLE=Filter
SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben
SCHEM_SELECTOR_FILTER_NAME=§7Nach Namen suchen...
SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchwort: §e{0}
SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchbegriff: §e{0}
SCHEM_SELECTOR_FILTER_ENTER_OWNER=Besitzer eingeben
SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen...
SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0}
SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ wählen...
SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ Filtern...
SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ filtern...
SCHEM_SELECTOR_FILTER_TYPE_SEARCH=§7Typ: §e{0}
SCHEM_SELECTOR_FILTER_MAT=§7Nach Item Filtern...
SCHEM_SELECTOR_FILTER_MAT=§7Nach Item filtern...
SCHEM_SELECTOR_FILTER_MAT_SEARCH=§7Item: §e{0}
SCHEM_SELECTOR_CANCEL=§eAbbrechen
SCHEM_SELECTOR_GO=§eSuchen...
SCHEM_SELECTOR_SCHEMATIC=Schematic
SCHEM_SELECTOR_DIRECTORY=Ordner
SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner

Datei anzeigen

@ -57,7 +57,7 @@ public class SchematicNode {
private static final SQL.Statement getAccessibleByUserByTypeInNode_Null = new SQL.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName");
private static final SQL.Statement getAccessibleByUserByType = new SQL.Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName");
private static final SQL.Statement getAllSchematicsAccessibleByUser = new SQL.Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
private static final SQL.Statement isSchematicAccessibleForUser = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1 ORDER BY NodeName");
private static final SQL.Statement isSchematicAccessibleForUser = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
private static final SQL.Statement getAllParentsOfNode = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
private static final SQL.Statement countNodes = new SQL.Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
private static final SQL.Statement updateDB = new SQL.Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?");
@ -80,8 +80,6 @@ public class SchematicNode {
return getSchematicNode(owner, name, parent);
}
private Timestamp lastUpdate;
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
return getSchematicNode(owner, name, parent.getId());
}
@ -119,9 +117,8 @@ public class SchematicNode {
parent = null;
}
SQL.Statement.ResultSetUser<SchematicNode> user = rs -> {
while (rs.next()) {
SchematicNode node = new SchematicNode(rs);
return node;
if (rs.next()) {
return new SchematicNode(rs);
}
return null;
};
@ -137,8 +134,9 @@ public class SchematicNode {
parent = null;
SQL.Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
List<SchematicNode> nodes = new ArrayList<>();
while (rs.next())
while (rs.next()) {
nodes.add(new SchematicNode(rs));
}
return nodes;
};
if(parent == null) {
@ -266,11 +264,12 @@ public class SchematicNode {
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
if (parent != null && parent != 0) {
if(isSchematicAccessibleForUser.select(rs -> {
if(Boolean.TRUE.equals(isSchematicAccessibleForUser.select(rs -> {
rs.next();
return rs.getInt("Accessible") > 0;
}, parent, user, user))
}, parent, user, user))) {
return getSchematicNodeInNode(parent);
}
} else {
return getAccessibleByUser.select(rs -> {
List<SchematicNode> nodes = new ArrayList<>();
@ -322,7 +321,7 @@ public class SchematicNode {
if (currentNode == null) {
node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
} else {
node = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
node = Optional.of(SchematicNode.getSchematicNode(layers[i], currentNode.getId()));
}
if (!node.isPresent()) {
return null;
@ -348,6 +347,7 @@ public class SchematicNode {
private String type;
private boolean schemFormat;
private int rank;
private Timestamp lastUpdate;
private final boolean isDir;
private Map<Integer, String> brCache = new HashMap<>();

Datei anzeigen

@ -34,33 +34,27 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
public class SchematicSelector {
public static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE";
protected static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE";
@Getter
private final Player player;
@Getter
private final SteamwarUser user;
private SteamwarUser user;
@Getter
private final Consumer<SchematicNode> callback;
@Getter
private final SelectorTarget target;
@Getter
private final SelectorFilter filter = new SelectorFilter();
private SchematicSelectorInjectable injectable;
private boolean useHooks;
private SchematicSelectorInjectable injectable = SchematicSelectorInjectable.DEFAULT;
@Setter
@Getter
private PublicMode publicMode = PublicMode.ALL;
@Setter
@Getter
private boolean singleDirOpen;
@Setter
@Getter
private Function<Player, String> title;
private boolean sdoTrigger = false;
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) {
@ -68,24 +62,24 @@ public class SchematicSelector {
this.user = SteamwarUser.get(player.getUniqueId());
this.target = target;
this.callback = callback;
this.singleDirOpen = !target.target.isDirs();
this.singleDirOpen = !target.target.dirs;
}
public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer<SchematicNode> callback) {
this(player, target, callback);
this.useHooks = true;
this.injectable = injectable;
}
public void open() {
if(useHooks) {
injectable.onSelectorCreate(this);
injectable.onSelectorCreate(this);
if(publicMode == PublicMode.PUBLIC_ONLY) {
this.user = SteamwarUser.get(0);
}
openList(null, publicMode == PublicMode.PUBLIC_ONLY);
openList(null);
}
private void openList(SchematicNode parent, boolean publics) {
List<SchematicNode> nodes = filter.isFilter()?getFilteredSchematics(publics):getSchematicList(publics, parent);
private void openList(SchematicNode parent) {
List<SchematicNode> nodes = filter.isFilter()?getFilteredSchematics():getSchematicList(parent);
if(sdoTrigger) {
sdoTrigger = false;
@ -103,44 +97,48 @@ public class SchematicSelector {
list.add(renderItem(node));
}
SWListInv<SchematicNode> inv = new SWListInv<>(player, MessageFormat.format(title==null?DEFAULT_TITLE:title.apply(player), target.target.getName(player), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(publics, node, parent));
SWListInv<SchematicNode> inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent));
if(publicMode == PublicMode.ALL) {
if(publics) {
inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> openList(null, false));
if(user.getId() == 0) {
inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> {
this.user = SteamwarUser.get(player.getUniqueId());
openList(null);
});
} else {
inv.setItem(48, Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> openList(null, true));
inv.setItem(48, Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> {
this.user = SteamwarUser.get(0);
openList(null);
});
}
}
if(target.target.isDirs()) {
if(target.target.dirs) {
inv.setItem(49, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_SEL_DIR", player), clickType -> {
player.closeInventory();
callback.accept(parent);
});
}
if(!publics) {
if(user.getId() != 0) {
inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent));
}
inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter(publics));
inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter());
if(useHooks) {
injectable.onListRender(this, inv, parent);
}
injectable.onListRender(this, inv, parent);
inv.open();
}
private void handleClick(boolean publics, SchematicNode node, SchematicNode parent) {
private void handleClick(SchematicNode node, SchematicNode parent) {
if(node == null) {
openList(getParent(parent), publics);
openList(getParent(parent));
return;
}
if(node.isDir()) {
if(filter.isFilter() && target.target.isDirs()) {
if(filter.isFilter() && target.target.dirs) {
player.closeInventory();
callback.accept(node);
return;
}
filter.reset();
openList(node, publics);
openList(node);
return;
}
player.closeInventory();
@ -172,31 +170,26 @@ public class SchematicSelector {
SWAnvilInv inv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player));
inv.setItem(Material.CHEST);
inv.setCallback(s -> {
if(useHooks) {
if(injectable.onFolderCreate(this, s)) {
SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId());
openList(parent, false);
}
} else {
if(injectable.onFolderCreate(this, s)) {
SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId());
openList(parent, false);
openList(parent);
}
});
inv.open();
}
private void openFilter(boolean publics) {
private void openFilter() {
SWInventory inv = new SWInventory(player, 9, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player));
InvCallback nameCallback = clickType -> {
if(clickType.isRightClick()) {
filter.setName("");
openFilter(publics);
openFilter();
} else {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player));
swAnvilInv.setItem(Material.NAME_TAG);
swAnvilInv.setCallback(s -> {
filter.setName(s);
openFilter(publics);
openFilter();
});
swAnvilInv.open();
}
@ -210,13 +203,13 @@ public class SchematicSelector {
InvCallback ownerCallback = clickType -> {
if(clickType.isRightClick()) {
filter.setOwner(null);
openFilter(publics);
openFilter();
} else {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player));
swAnvilInv.setItem(Material.PLAYER_HEAD);
swAnvilInv.setCallback(s -> {
filter.setOwner(SteamwarUser.get(s).getId());
openFilter(publics);
openFilter();
});
swAnvilInv.open();
}
@ -237,7 +230,7 @@ public class SchematicSelector {
InvCallback schemTypeCallback = clickType -> {
if(clickType.isRightClick()) {
filter.setType(null);
openFilter(publics);
openFilter();
} else {
List<SWListInv.SWListEntry<SchematicType>> types = new ArrayList<>();
SchematicType.values().forEach(schematicType -> {
@ -245,7 +238,7 @@ public class SchematicSelector {
});
SWListInv<SchematicType> listInv = new SWListInv<>(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_SEL_TYPE", player), types, (clickType1, schematicType) -> {
filter.setType(schematicType);
openFilter(publics);
openFilter();
});
listInv.open();
}
@ -261,11 +254,11 @@ public class SchematicSelector {
InvCallback materialCallback = clickType -> {
if(clickType.isRightClick()) {
filter.setItem(null);
openFilter(publics);
openFilter();
} else {
UtilGui.openMaterialSelector(player, material -> {
filter.setItem(material);
openFilter(publics);
openFilter();
});
}
};
@ -280,29 +273,23 @@ public class SchematicSelector {
inv.setItem(7, SWItem.getDye(1), Core.MESSAGE.parse("SCHEM_SELECTOR_CANCEL", player), clickType -> {
filter.reset();
openList(null, publics);
openList(null);
});
inv.setItem(8, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_GO", player), clickType -> {
filter.setFilter(true);
if(useHooks) {
injectable.onFilterApply(this);
}
openList(null, publics);
injectable.onFilterApply(this);
openList(null);
});
if(useHooks) {
injectable.onFilterRender(this, inv);
}
injectable.onFilterRender(this, inv);
inv.open();
}
private List<SchematicNode> getFilteredSchematics(boolean publics) {
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(publics ? 0 : user.getId()));
private List<SchematicNode> getFilteredSchematics() {
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(user.getId()));
nodes.removeIf(node -> {
if(useHooks) {
injectable.onNodeFilter(this, node);
}
injectable.onNodeFilter(this, node);
return !filter.matches(node);
});
if(target.target == Target.DIRECTORY) {
@ -314,29 +301,29 @@ public class SchematicSelector {
return nodes;
}
private List<SchematicNode> getSchematicList(boolean publics, SchematicNode parent) {
private List<SchematicNode> getSchematicList(SchematicNode parent) {
List<SchematicNode> nodes = new ArrayList<>();
switch (target.target) {
case DIRECTORY:
if(parent == null) {
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), null));
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(user.getId(), null));
nodes.removeIf(node -> !node.isDir());
} else {
nodes.addAll(SchematicNode.getSchematicDirectoryInNode(parent.getId()));
}
break;
case SCHEMATIC_TYPE:
nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(publics?0: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) {
nodes.removeIf(node -> node.getRank() > target.rank);
}
break;
default:
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId()));
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(user.getId(), parent == null?0:parent.getId()));
}
if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
openList(nodes.get(0), publics);
openList(nodes.get(0));
sdoTrigger = true;
}
return nodes;
@ -369,17 +356,12 @@ public class SchematicSelector {
return new SelectorTarget(Target.SCHEMATIC_TYPE, type, rank);
}
public static class SelectorTarget {
@AllArgsConstructor
static class SelectorTarget {
private final Target target;
private final SchematicType type;
private final int rank;
private SelectorTarget(Target target, SchematicType type, int rank) {
this.target = target;
this.type = type;
this.rank = rank;
}
}
@AllArgsConstructor
@ -389,12 +371,10 @@ public class SchematicSelector {
SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true),
SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false);
@Getter
private String rawName;
@Getter
private boolean dirs;
public String getName(Player player) {
private String getName(Player player) {
return Core.MESSAGE.parse(rawName, player);
}
}
@ -421,22 +401,16 @@ public class SchematicSelector {
public boolean matches(SchematicNode node) {
boolean matches = true;
if(!name.isEmpty()) {
if(!node.getName().contains(name)) {
matches = false;
}
if(!name.isEmpty() && !node.getName().contains(name)) {
matches = false;
}
if(owner != null) {
if(node.getOwner() != owner) {
matches = false;
}
if(owner != null && node.getOwner() != owner) {
matches = false;
}
if(type != null) {
if(node.isDir() || !node.getType().equals(type.toDB())) {
matches = false;
}
if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) {
matches = false;
}
if(item != null) {

Datei anzeigen

@ -19,12 +19,20 @@
package de.steamwar.util;
import de.steamwar.core.Core;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWListInv;
import de.steamwar.sql.SchematicNode;
import org.bukkit.entity.Player;
public interface SchematicSelectorInjectable {
SchematicSelectorInjectable DEFAULT = new DefaultSchematicSelectorInjectable();
default String createTitle(Player player) {
return Core.MESSAGE.parse("DEFAULT_TITLE", player);
}
default void onSelectorCreate(SchematicSelector selector) {}
default void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent) {}
@ -36,4 +44,6 @@ public interface SchematicSelectorInjectable {
default boolean onFolderCreate(SchematicSelector selector, String name) {return true;}
default void onNodeFilter(SchematicSelector selector, SchematicNode node) {}
class DefaultSchematicSelectorInjectable implements SchematicSelectorInjectable {}
}