Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
6ecd8a5f0e
Commit
cf9f2a2375
@ -27,23 +27,22 @@ SCHEM_SELECTOR_SEL_DIR=
|
|||||||
SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner
|
SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner
|
||||||
SCHEM_SELECTOR_FILTER=§7Filter
|
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_TITLE=Filter
|
||||||
SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben
|
SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben
|
||||||
SCHEM_SELECTOR_FILTER_NAME=§7Nach Namen suchen...
|
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_ENTER_OWNER=Besitzer eingeben
|
||||||
SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen...
|
SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen...
|
||||||
SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0}
|
SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0}
|
||||||
SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ wählen...
|
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_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_FILTER_MAT_SEARCH=§7Item: §e{0}
|
||||||
SCHEM_SELECTOR_CANCEL=§eAbbrechen
|
SCHEM_SELECTOR_CANCEL=§eAbbrechen
|
||||||
SCHEM_SELECTOR_GO=§eSuchen...
|
SCHEM_SELECTOR_GO=§eSuchen...
|
||||||
|
|
||||||
SCHEM_SELECTOR_SCHEMATIC=Schematic
|
SCHEM_SELECTOR_SCHEMATIC=Schematic
|
||||||
SCHEM_SELECTOR_DIRECTORY=Ordner
|
SCHEM_SELECTOR_DIRECTORY=Ordner
|
||||||
SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner
|
SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner
|
||||||
|
@ -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 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 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 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 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 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 = ?");
|
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);
|
return getSchematicNode(owner, name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Timestamp lastUpdate;
|
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
|
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
|
||||||
return getSchematicNode(owner, name, parent.getId());
|
return getSchematicNode(owner, name, parent.getId());
|
||||||
}
|
}
|
||||||
@ -119,9 +117,8 @@ public class SchematicNode {
|
|||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
SQL.Statement.ResultSetUser<SchematicNode> user = rs -> {
|
SQL.Statement.ResultSetUser<SchematicNode> user = rs -> {
|
||||||
while (rs.next()) {
|
if (rs.next()) {
|
||||||
SchematicNode node = new SchematicNode(rs);
|
return new SchematicNode(rs);
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@ -137,8 +134,9 @@ public class SchematicNode {
|
|||||||
parent = null;
|
parent = null;
|
||||||
SQL.Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
SQL.Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
while (rs.next())
|
while (rs.next()) {
|
||||||
nodes.add(new SchematicNode(rs));
|
nodes.add(new SchematicNode(rs));
|
||||||
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
};
|
};
|
||||||
if(parent == null) {
|
if(parent == null) {
|
||||||
@ -266,11 +264,12 @@ public class SchematicNode {
|
|||||||
|
|
||||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||||
if (parent != null && parent != 0) {
|
if (parent != null && parent != 0) {
|
||||||
if(isSchematicAccessibleForUser.select(rs -> {
|
if(Boolean.TRUE.equals(isSchematicAccessibleForUser.select(rs -> {
|
||||||
rs.next();
|
rs.next();
|
||||||
return rs.getInt("Accessible") > 0;
|
return rs.getInt("Accessible") > 0;
|
||||||
}, parent, user, user))
|
}, parent, user, user))) {
|
||||||
return getSchematicNodeInNode(parent);
|
return getSchematicNodeInNode(parent);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return getAccessibleByUser.select(rs -> {
|
return getAccessibleByUser.select(rs -> {
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
@ -322,7 +321,7 @@ public class SchematicNode {
|
|||||||
if (currentNode == null) {
|
if (currentNode == null) {
|
||||||
node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
|
node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
|
||||||
} else {
|
} 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()) {
|
if (!node.isPresent()) {
|
||||||
return null;
|
return null;
|
||||||
@ -348,6 +347,7 @@ public class SchematicNode {
|
|||||||
private String type;
|
private String type;
|
||||||
private boolean schemFormat;
|
private boolean schemFormat;
|
||||||
private int rank;
|
private int rank;
|
||||||
|
private Timestamp lastUpdate;
|
||||||
private final boolean isDir;
|
private final boolean isDir;
|
||||||
private Map<Integer, String> brCache = new HashMap<>();
|
private Map<Integer, String> brCache = new HashMap<>();
|
||||||
|
|
||||||
|
@ -34,33 +34,27 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class SchematicSelector {
|
public class SchematicSelector {
|
||||||
|
|
||||||
public static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE";
|
protected static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE";
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Player player;
|
private final Player player;
|
||||||
@Getter
|
@Getter
|
||||||
private final SteamwarUser user;
|
private SteamwarUser user;
|
||||||
@Getter
|
@Getter
|
||||||
private final Consumer<SchematicNode> callback;
|
private final Consumer<SchematicNode> callback;
|
||||||
@Getter
|
|
||||||
private final SelectorTarget target;
|
private final SelectorTarget target;
|
||||||
@Getter
|
@Getter
|
||||||
private final SelectorFilter filter = new SelectorFilter();
|
private final SelectorFilter filter = new SelectorFilter();
|
||||||
private SchematicSelectorInjectable injectable;
|
private SchematicSelectorInjectable injectable = SchematicSelectorInjectable.DEFAULT;
|
||||||
private boolean useHooks;
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
private PublicMode publicMode = PublicMode.ALL;
|
private PublicMode publicMode = PublicMode.ALL;
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
private boolean singleDirOpen;
|
private boolean singleDirOpen;
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
private Function<Player, String> title;
|
|
||||||
private boolean sdoTrigger = false;
|
private boolean sdoTrigger = false;
|
||||||
|
|
||||||
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) {
|
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) {
|
||||||
@ -68,24 +62,24 @@ public class SchematicSelector {
|
|||||||
this.user = SteamwarUser.get(player.getUniqueId());
|
this.user = SteamwarUser.get(player.getUniqueId());
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.singleDirOpen = !target.target.isDirs();
|
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<SchematicNode> callback) {
|
||||||
this(player, target, callback);
|
this(player, target, callback);
|
||||||
this.useHooks = true;
|
|
||||||
this.injectable = injectable;
|
this.injectable = injectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open() {
|
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) {
|
private void openList(SchematicNode parent) {
|
||||||
List<SchematicNode> nodes = filter.isFilter()?getFilteredSchematics(publics):getSchematicList(publics, parent);
|
List<SchematicNode> nodes = filter.isFilter()?getFilteredSchematics():getSchematicList(parent);
|
||||||
|
|
||||||
if(sdoTrigger) {
|
if(sdoTrigger) {
|
||||||
sdoTrigger = false;
|
sdoTrigger = false;
|
||||||
@ -103,44 +97,48 @@ public class SchematicSelector {
|
|||||||
list.add(renderItem(node));
|
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(publicMode == PublicMode.ALL) {
|
||||||
if(publics) {
|
if(user.getId() == 0) {
|
||||||
inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> openList(null, false));
|
inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> {
|
||||||
|
this.user = SteamwarUser.get(player.getUniqueId());
|
||||||
|
openList(null);
|
||||||
|
});
|
||||||
} else {
|
} 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 -> {
|
inv.setItem(49, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_SEL_DIR", player), clickType -> {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
callback.accept(parent);
|
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(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();
|
inv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleClick(boolean publics, SchematicNode node, SchematicNode parent) {
|
private void handleClick(SchematicNode node, SchematicNode parent) {
|
||||||
if(node == null) {
|
if(node == null) {
|
||||||
openList(getParent(parent), publics);
|
openList(getParent(parent));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(node.isDir()) {
|
if(node.isDir()) {
|
||||||
if(filter.isFilter() && target.target.isDirs()) {
|
if(filter.isFilter() && target.target.dirs) {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
callback.accept(node);
|
callback.accept(node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
filter.reset();
|
filter.reset();
|
||||||
openList(node, publics);
|
openList(node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
@ -172,31 +170,26 @@ public class SchematicSelector {
|
|||||||
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);
|
inv.setItem(Material.CHEST);
|
||||||
inv.setCallback(s -> {
|
inv.setCallback(s -> {
|
||||||
if(useHooks) {
|
|
||||||
if(injectable.onFolderCreate(this, 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.getId());
|
||||||
openList(parent, false);
|
openList(parent);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId());
|
|
||||||
openList(parent, false);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
inv.open();
|
inv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openFilter(boolean publics) {
|
private void openFilter() {
|
||||||
SWInventory inv = new SWInventory(player, 9, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player));
|
SWInventory inv = new SWInventory(player, 9, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player));
|
||||||
InvCallback nameCallback = clickType -> {
|
InvCallback nameCallback = clickType -> {
|
||||||
if(clickType.isRightClick()) {
|
if(clickType.isRightClick()) {
|
||||||
filter.setName("");
|
filter.setName("");
|
||||||
openFilter(publics);
|
openFilter();
|
||||||
} else {
|
} else {
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player));
|
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player));
|
||||||
swAnvilInv.setItem(Material.NAME_TAG);
|
swAnvilInv.setItem(Material.NAME_TAG);
|
||||||
swAnvilInv.setCallback(s -> {
|
swAnvilInv.setCallback(s -> {
|
||||||
filter.setName(s);
|
filter.setName(s);
|
||||||
openFilter(publics);
|
openFilter();
|
||||||
});
|
});
|
||||||
swAnvilInv.open();
|
swAnvilInv.open();
|
||||||
}
|
}
|
||||||
@ -210,13 +203,13 @@ public class SchematicSelector {
|
|||||||
InvCallback ownerCallback = clickType -> {
|
InvCallback ownerCallback = clickType -> {
|
||||||
if(clickType.isRightClick()) {
|
if(clickType.isRightClick()) {
|
||||||
filter.setOwner(null);
|
filter.setOwner(null);
|
||||||
openFilter(publics);
|
openFilter();
|
||||||
} else {
|
} else {
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player));
|
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player));
|
||||||
swAnvilInv.setItem(Material.PLAYER_HEAD);
|
swAnvilInv.setItem(Material.PLAYER_HEAD);
|
||||||
swAnvilInv.setCallback(s -> {
|
swAnvilInv.setCallback(s -> {
|
||||||
filter.setOwner(SteamwarUser.get(s).getId());
|
filter.setOwner(SteamwarUser.get(s).getId());
|
||||||
openFilter(publics);
|
openFilter();
|
||||||
});
|
});
|
||||||
swAnvilInv.open();
|
swAnvilInv.open();
|
||||||
}
|
}
|
||||||
@ -237,7 +230,7 @@ public class SchematicSelector {
|
|||||||
InvCallback schemTypeCallback = clickType -> {
|
InvCallback schemTypeCallback = clickType -> {
|
||||||
if(clickType.isRightClick()) {
|
if(clickType.isRightClick()) {
|
||||||
filter.setType(null);
|
filter.setType(null);
|
||||||
openFilter(publics);
|
openFilter();
|
||||||
} else {
|
} else {
|
||||||
List<SWListInv.SWListEntry<SchematicType>> types = new ArrayList<>();
|
List<SWListInv.SWListEntry<SchematicType>> types = new ArrayList<>();
|
||||||
SchematicType.values().forEach(schematicType -> {
|
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) -> {
|
SWListInv<SchematicType> listInv = new SWListInv<>(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_SEL_TYPE", player), types, (clickType1, schematicType) -> {
|
||||||
filter.setType(schematicType);
|
filter.setType(schematicType);
|
||||||
openFilter(publics);
|
openFilter();
|
||||||
});
|
});
|
||||||
listInv.open();
|
listInv.open();
|
||||||
}
|
}
|
||||||
@ -261,11 +254,11 @@ public class SchematicSelector {
|
|||||||
InvCallback materialCallback = clickType -> {
|
InvCallback materialCallback = clickType -> {
|
||||||
if(clickType.isRightClick()) {
|
if(clickType.isRightClick()) {
|
||||||
filter.setItem(null);
|
filter.setItem(null);
|
||||||
openFilter(publics);
|
openFilter();
|
||||||
} else {
|
} else {
|
||||||
UtilGui.openMaterialSelector(player, material -> {
|
UtilGui.openMaterialSelector(player, material -> {
|
||||||
filter.setItem(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 -> {
|
inv.setItem(7, SWItem.getDye(1), Core.MESSAGE.parse("SCHEM_SELECTOR_CANCEL", player), clickType -> {
|
||||||
filter.reset();
|
filter.reset();
|
||||||
openList(null, publics);
|
openList(null);
|
||||||
});
|
});
|
||||||
inv.setItem(8, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_GO", player), clickType -> {
|
inv.setItem(8, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_GO", player), clickType -> {
|
||||||
filter.setFilter(true);
|
filter.setFilter(true);
|
||||||
if(useHooks) {
|
|
||||||
injectable.onFilterApply(this);
|
injectable.onFilterApply(this);
|
||||||
}
|
openList(null);
|
||||||
openList(null, publics);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(useHooks) {
|
|
||||||
injectable.onFilterRender(this, inv);
|
injectable.onFilterRender(this, inv);
|
||||||
}
|
|
||||||
|
|
||||||
inv.open();
|
inv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SchematicNode> getFilteredSchematics(boolean publics) {
|
private List<SchematicNode> getFilteredSchematics() {
|
||||||
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(publics ? 0 : user.getId()));
|
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(user.getId()));
|
||||||
nodes.removeIf(node -> {
|
nodes.removeIf(node -> {
|
||||||
if(useHooks) {
|
|
||||||
injectable.onNodeFilter(this, node);
|
injectable.onNodeFilter(this, node);
|
||||||
}
|
|
||||||
return !filter.matches(node);
|
return !filter.matches(node);
|
||||||
});
|
});
|
||||||
if(target.target == Target.DIRECTORY) {
|
if(target.target == Target.DIRECTORY) {
|
||||||
@ -314,29 +301,29 @@ public class SchematicSelector {
|
|||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SchematicNode> getSchematicList(boolean publics, SchematicNode parent) {
|
private List<SchematicNode> getSchematicList(SchematicNode parent) {
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
switch (target.target) {
|
switch (target.target) {
|
||||||
case DIRECTORY:
|
case DIRECTORY:
|
||||||
if(parent == null) {
|
if(parent == null) {
|
||||||
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), null));
|
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(user.getId(), null));
|
||||||
nodes.removeIf(node -> !node.isDir());
|
nodes.removeIf(node -> !node.isDir());
|
||||||
} else {
|
} else {
|
||||||
nodes.addAll(SchematicNode.getSchematicDirectoryInNode(parent.getId()));
|
nodes.addAll(SchematicNode.getSchematicDirectoryInNode(parent.getId()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SCHEMATIC_TYPE:
|
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) {
|
if(target.rank >= 0) {
|
||||||
nodes.removeIf(node -> node.getRank() > target.rank);
|
nodes.removeIf(node -> node.getRank() > target.rank);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
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()) {
|
if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
|
||||||
openList(nodes.get(0), publics);
|
openList(nodes.get(0));
|
||||||
sdoTrigger = true;
|
sdoTrigger = true;
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
@ -369,17 +356,12 @@ public class SchematicSelector {
|
|||||||
return new SelectorTarget(Target.SCHEMATIC_TYPE, type, rank);
|
return new SelectorTarget(Target.SCHEMATIC_TYPE, type, rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SelectorTarget {
|
@AllArgsConstructor
|
||||||
|
static class SelectorTarget {
|
||||||
|
|
||||||
private final Target target;
|
private final Target target;
|
||||||
private final SchematicType type;
|
private final SchematicType type;
|
||||||
private final int rank;
|
private final int rank;
|
||||||
|
|
||||||
private SelectorTarget(Target target, SchematicType type, int rank) {
|
|
||||||
this.target = target;
|
|
||||||
this.type = type;
|
|
||||||
this.rank = rank;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -389,12 +371,10 @@ public class SchematicSelector {
|
|||||||
SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true),
|
SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true),
|
||||||
SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false);
|
SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false);
|
||||||
|
|
||||||
@Getter
|
|
||||||
private String rawName;
|
private String rawName;
|
||||||
@Getter
|
|
||||||
private boolean dirs;
|
private boolean dirs;
|
||||||
|
|
||||||
public String getName(Player player) {
|
private String getName(Player player) {
|
||||||
return Core.MESSAGE.parse(rawName, player);
|
return Core.MESSAGE.parse(rawName, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -421,23 +401,17 @@ public class SchematicSelector {
|
|||||||
|
|
||||||
public boolean matches(SchematicNode node) {
|
public boolean matches(SchematicNode node) {
|
||||||
boolean matches = true;
|
boolean matches = true;
|
||||||
if(!name.isEmpty()) {
|
if(!name.isEmpty() && !node.getName().contains(name)) {
|
||||||
if(!node.getName().contains(name)) {
|
|
||||||
matches = false;
|
matches = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(owner != null) {
|
if(owner != null && node.getOwner() != owner) {
|
||||||
if(node.getOwner() != owner) {
|
|
||||||
matches = false;
|
matches = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(type != null) {
|
if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) {
|
||||||
if(node.isDir() || !node.getType().equals(type.toDB())) {
|
|
||||||
matches = false;
|
matches = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(item != null) {
|
if(item != null) {
|
||||||
String i;
|
String i;
|
||||||
|
@ -19,12 +19,20 @@
|
|||||||
|
|
||||||
package de.steamwar.util;
|
package de.steamwar.util;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import de.steamwar.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public interface SchematicSelectorInjectable {
|
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 onSelectorCreate(SchematicSelector selector) {}
|
||||||
|
|
||||||
default void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent) {}
|
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 boolean onFolderCreate(SchematicSelector selector, String name) {return true;}
|
||||||
|
|
||||||
default void onNodeFilter(SchematicSelector selector, SchematicNode node) {}
|
default void onNodeFilter(SchematicSelector selector, SchematicNode node) {}
|
||||||
|
|
||||||
|
class DefaultSchematicSelectorInjectable implements SchematicSelectorInjectable {}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren