geforkt von SteamWar/BungeeCore
Update!
Dieser Commit ist enthalten in:
Ursprung
763a27e7ba
Commit
5576d1e3ca
@ -72,7 +72,7 @@ public class CheckCommand extends BasicCommand {
|
||||
}, 10, 10, TimeUnit.MINUTES);
|
||||
}
|
||||
public static void sendReminder(ProxiedPlayer player) {
|
||||
List<Schematic> schematics = getSchemsToCheck();
|
||||
List<SchematicNode> schematics = getSchemsToCheck();
|
||||
if(schematics.size() != currentCheckers.size())
|
||||
Message.send("CHECK_REMINDER", player, "CHECK_REMINDER_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size());
|
||||
}
|
||||
@ -230,8 +230,8 @@ public class CheckCommand extends BasicCommand {
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
||||
BauCommand.stopBauserver(checker);
|
||||
|
||||
ArenaMode mode = ArenaMode.getByCheckSchemType(schematic.getSchemType().toDB());
|
||||
SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID());
|
||||
ArenaMode mode = ArenaMode.getBySchemType(schematic.getSchemtype());
|
||||
SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getId(), 0);
|
||||
currentCheckers.put(checker.getUniqueId(), this);
|
||||
currentSchems.put(schematic.getId(), this);
|
||||
for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getId()))
|
||||
|
@ -1,27 +1,31 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.sql;
|
||||
|
||||
import java.sql.Blob;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class SchematicNode {
|
||||
|
||||
@ -41,52 +45,26 @@ public class SchematicNode {
|
||||
return getSchematicNode(owner, name, parent);
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name);
|
||||
}else {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent);
|
||||
}
|
||||
try {
|
||||
while (set.next()) {
|
||||
SchematicNode node = new SchematicNode(set);
|
||||
if(!node.isDir())
|
||||
return node;
|
||||
}
|
||||
List<SchematicNode> nodes = getSchematicNodeInNode(parent);
|
||||
for (SchematicNode node:nodes) {
|
||||
if(!node.isDir() && node.name.equals(name) && NodeMember.getNodeMember(node.getId(), owner) != null)
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}catch (SQLException e) {
|
||||
throw new SecurityException("Failed to load Schemnodes", e);
|
||||
}
|
||||
}
|
||||
private Timestamp lastUpdate;
|
||||
|
||||
public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) {
|
||||
return getSchematicNode(owner, name, parent.getId());
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode is NULL");
|
||||
private SchematicNode(ResultSet set) throws SQLException {
|
||||
id = set.getInt("NodeId");
|
||||
owner = set.getInt("NodeOwner");
|
||||
name = set.getString("NodeName");
|
||||
parent = set.getInt("ParentNode");
|
||||
item = set.getString("NodeItem");
|
||||
type = set.getString("NodeType");
|
||||
lastUpdate = set.getTimestamp("LastUpdate");
|
||||
if (type != null) {
|
||||
isDir = false;
|
||||
rank = set.getInt("NodeRank");
|
||||
schemFormat = set.getBoolean("NodeFormat");
|
||||
} else {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode = ?", parent);
|
||||
}
|
||||
try {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while (set.next())
|
||||
nodes.add(new SchematicNode(set));
|
||||
return nodes;
|
||||
}catch (SQLException e) {
|
||||
throw new SecurityException("Failed to load Schemnodes", e);
|
||||
isDir = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,14 +76,58 @@ public class SchematicNode {
|
||||
return getSchematicDirectory(name, parent.getId());
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||
if (parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if (parent == null) {
|
||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name);
|
||||
} else {
|
||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent);
|
||||
}
|
||||
try {
|
||||
while (set.next()) {
|
||||
SchematicNode node = new SchematicNode(set);
|
||||
return node;
|
||||
}
|
||||
List<SchematicNode> nodes = getSchematicNodeInNode(parent);
|
||||
for (SchematicNode node:nodes) {
|
||||
if (node.name.equals(name) && NodeMember.getNodeMember(node.getId(), owner) != null)
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}catch (SQLException e) {
|
||||
throw new SecurityException("Failed to load Schemnodes", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL");
|
||||
}else {
|
||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?", parent);
|
||||
}
|
||||
try {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while (set.next())
|
||||
nodes.add(new SchematicNode(set));
|
||||
return nodes;
|
||||
}catch (SQLException e) {
|
||||
throw new SecurityException("Failed to load Schemnodes", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent);
|
||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent);
|
||||
}else {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||
}
|
||||
try {
|
||||
while (set.next()) {
|
||||
@ -124,9 +146,9 @@ public class SchematicNode {
|
||||
parent = null;
|
||||
ResultSet set;
|
||||
if(parent == null) {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name, parent);
|
||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL", name);
|
||||
}else {
|
||||
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||
set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
|
||||
}
|
||||
try {
|
||||
while (set.next()) {
|
||||
@ -141,7 +163,7 @@ public class SchematicNode {
|
||||
}
|
||||
|
||||
public static SchematicNode getSchematicNode(int id) {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeId = ?", id);
|
||||
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?", id);
|
||||
try {
|
||||
if (!set.next())
|
||||
return null;
|
||||
@ -151,8 +173,22 @@ public class SchematicNode {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, Integer parent) {
|
||||
List<SchematicNode> schems = getAllSchematicsAccessibleByUser(owner);
|
||||
schems.removeIf(node -> !node.getType().equals(schemType));
|
||||
Map<Integer, SchematicNode> nodesInParent = new LinkedHashMap<>();
|
||||
for (SchematicNode schematicNode : schems) {
|
||||
SchematicNode currentNode = schematicNode;
|
||||
while (currentNode.getParent() != parent) {
|
||||
currentNode = currentNode.getParentNode();
|
||||
}
|
||||
nodesInParent.putIfAbsent(currentNode.getId(), currentNode);
|
||||
}
|
||||
return new ArrayList<>(nodesInParent.values());
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType);
|
||||
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?", owner, schemType);
|
||||
try {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while (set.next())
|
||||
@ -164,7 +200,7 @@ public class SchematicNode {
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeType = ?", schemType);
|
||||
ResultSet set = SQL.select("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?", schemType);
|
||||
try {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while (set.next())
|
||||
@ -175,19 +211,18 @@ public class SchematicNode {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, Integer parent) {
|
||||
if(parent != null && parent == 0)
|
||||
parent = null;
|
||||
List<SchematicNode> schems = getAllSchematicsOfType(owner, schemType);
|
||||
Map<Integer, SchematicNode> nodesInParent = new LinkedHashMap<>();
|
||||
for (SchematicNode schematicNode : schems) {
|
||||
SchematicNode currentNode = schematicNode;
|
||||
while (currentNode.getParent() != parent) {
|
||||
currentNode = currentNode.getParentNode();
|
||||
public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) {
|
||||
List<SchematicNode> finalList = new ArrayList<>();
|
||||
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(parent);
|
||||
nodes.forEach(node -> {
|
||||
if (node.isDir()) {
|
||||
finalList.addAll(deepGet(node.getId(), filter));
|
||||
} else {
|
||||
if (filter.test(node))
|
||||
finalList.add(node);
|
||||
}
|
||||
nodesInParent.putIfAbsent(currentNode.getId(), currentNode);
|
||||
}
|
||||
return new ArrayList<>(nodesInParent.values());
|
||||
});
|
||||
return finalList;
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||
@ -206,7 +241,7 @@ public class SchematicNode {
|
||||
if(isAdded)
|
||||
return getSchematicNodeInNode(parent);
|
||||
} else {
|
||||
ResultSet set = SQL.select("SELECT * FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND s.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName", user, user);
|
||||
ResultSet set = SQL.select("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 = ?) AND s.ParentNode is NULL GROUP BY s.NodeId ORDER BY s.NodeName", user, user);
|
||||
try{
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while(set.next())
|
||||
@ -216,11 +251,11 @@ public class SchematicNode {
|
||||
throw new SecurityException("Failed listing schematics", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||
ResultSet set = SQL.select("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode FROM SchematicNode s LEFT JOIN NodeMember nm ON nm.NodeId = s.NodeId WHERE s.NodeOwner = ? OR nm.UserId = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user);
|
||||
ResultSet set = SQL.select("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 nm ON nm.NodeId = s.NodeId WHERE s.NodeOwner = ? OR nm.UserId = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user);
|
||||
try{
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
while(set.next())
|
||||
@ -234,26 +269,35 @@ public class SchematicNode {
|
||||
private final int id;
|
||||
private final int owner;
|
||||
private String name;
|
||||
private int parent;
|
||||
private Integer parent;
|
||||
private String item;
|
||||
private String type;
|
||||
private boolean schemFormat;
|
||||
private int rank;
|
||||
private boolean isDir;
|
||||
private final boolean isDir;
|
||||
|
||||
private SchematicNode(ResultSet set) throws SQLException {
|
||||
id = set.getInt("NodeId");
|
||||
owner = set.getInt("NodeOwner");
|
||||
name = set.getString("NodeName");
|
||||
parent = set.getInt("ParentNode");
|
||||
item = set.getString("NodeItem");
|
||||
type = set.getString("NodeType");
|
||||
if(type != null) {
|
||||
isDir = false;
|
||||
rank = set.getInt("NodeRank");
|
||||
schemFormat = set.getBoolean("NodeFormat");
|
||||
public static List<SchematicNode> filterSchems(int user, Predicate<SchematicNode> filter) {
|
||||
List<SchematicNode> finalList = new ArrayList<>();
|
||||
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user, null);
|
||||
nodes.forEach(node -> {
|
||||
if (node.isDir()) {
|
||||
finalList.addAll(deepGet(node.getId(), filter));
|
||||
} else {
|
||||
isDir = true;
|
||||
if (filter.test(node))
|
||||
finalList.add(node);
|
||||
}
|
||||
});
|
||||
return finalList;
|
||||
}
|
||||
|
||||
public static Integer countNodes() {
|
||||
ResultSet set = SQL.select("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
||||
try {
|
||||
if (set.next())
|
||||
return set.getInt("count");
|
||||
return 0;
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Failed listing schematics", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,7 +318,7 @@ public class SchematicNode {
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public int getParent() {
|
||||
public Integer getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@ -345,9 +389,33 @@ public class SchematicNode {
|
||||
return NodeMember.getNodeMembers(id);
|
||||
}
|
||||
|
||||
public Timestamp getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
public String generateBreadcrumbs(SteamwarUser user) {
|
||||
return generateBreadcrumbs("/", user);
|
||||
}
|
||||
|
||||
public String generateBreadcrumbs(String split, SteamwarUser user) {
|
||||
StringBuilder builder = new StringBuilder(getName());
|
||||
SchematicNode currentNode = this;
|
||||
if (currentNode.isDir()) builder.append("/");
|
||||
while (currentNode.getParentNode() != null) {
|
||||
currentNode = currentNode.getParentNode();
|
||||
builder.insert(0, split)
|
||||
.insert(0, currentNode.getName());
|
||||
if (currentNode.getMembers().stream().anyMatch(member -> member.getMember() == user.getId())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void updateDB() {
|
||||
SQL.update("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?",
|
||||
name, owner, parent, item, type, rank, id);
|
||||
name, owner, parent == 0 ? null : parent, item, type, rank, id);
|
||||
this.lastUpdate = Timestamp.from(Instant.now());
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
@ -356,4 +424,9 @@ public class SchematicNode {
|
||||
}
|
||||
SQL.update("DELETE FROM SchematicNode WHERE NodeId = ?", id);
|
||||
}
|
||||
|
||||
private void updateDatabase(Blob blob, boolean newFormat) {
|
||||
SQL.update("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?", blob, newFormat, id);
|
||||
schemFormat = newFormat;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren