SteamWar/SpigotCore
Archiviert
13
0

Fixing SchemNode Translation Layer

Dieser Commit ist enthalten in:
Chaoscaot 2021-03-02 19:17:33 +01:00
Ursprung 77f1e48c6e
Commit bdfc5e8b0e
3 geänderte Dateien mit 91 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -83,6 +83,24 @@ public class CheckedSchematic {
return lastDeclined; return lastDeclined;
} }
public static List<CheckedSchematic> getLastDeclined(UUID uuid){
List<CheckedSchematic> lastDeclined = new LinkedList<>();
try{
ResultSet lastRS = SQL.select("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC", SteamwarUser.get(uuid).getId());
while(lastRS.next()){
int node = lastRS.getInt("NodeId");
int validator = lastRS.getInt("Validator");
Timestamp startTime = lastRS.getTimestamp("StartTime");
Timestamp endTime = lastRS.getTimestamp("EndTime");
String declineReason = lastRS.getString("DeclineReason");
lastDeclined.add(new CheckedSchematic(node, validator, startTime, endTime, declineReason, false));
}
}catch(SQLException e){
Bukkit.getLogger().log(Level.SEVERE, "getLastDeclined failed", e);
}
return lastDeclined;
}
public void remove() { public void remove() {
SQL.update("DELETE FROM CheckedSchematic WHERE NodeId", node); SQL.update("DELETE FROM CheckedSchematic WHERE NodeId", node);
} }

Datei anzeigen

@ -48,7 +48,10 @@ public class Schematic {
} }
public static Schematic getSchemFromDB(String schemName, int schemOwner){ public static Schematic getSchemFromDB(String schemName, int schemOwner){
return new Schematic(SchematicNode.getSchematicNode(schemOwner, schemName, 0)); SchematicNode node = SchematicNode.getSchematicNode(schemOwner, schemName, (Integer) null);
if(node == null)
return null;
return new Schematic(node);
} }
public static Schematic getSchemFromDB(int schemID){ public static Schematic getSchemFromDB(int schemID){
@ -62,7 +65,9 @@ public class Schematic {
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){ public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(schemOwner, 0); List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(schemOwner, 0);
List<Schematic> schematics = new ArrayList<>(); List<Schematic> schematics = new ArrayList<>();
nodes.forEach(node1 -> schematics.add(new Schematic(node1))); nodes.forEach(node1 -> {
if (!node1.isDir()) schematics.add(new Schematic(node1));
});
return schematics; return schematics;
} }

Datei anzeigen

@ -33,39 +33,42 @@ import java.util.*;
public class SchematicNode { public class SchematicNode {
public static SchematicNode createSchematic(int owner, String name, int parent) { public static SchematicNode createSchematic(int owner, String name, Integer parent) {
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), ""); return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
} }
public static SchematicNode createSchematicDirectory(int owner, String name, int parent) { public static SchematicNode createSchematicDirectory(int owner, String name, Integer parent) {
return createSchematicNode(owner, name, parent, null, ""); return createSchematicNode(owner, name, parent, null, "");
} }
public static SchematicNode createSchematicNode(int owner, String name, int parent, String type, String item) { public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) {
if(parent == 0)
parent = null;
SQL.update("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)", SQL.update("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)",
name, owner, parent, type, item); name, owner, parent, type, item);
return getSchematicNode(owner, name, type, parent); return getSchematicNode(owner, name, parent);
} }
public static SchematicNode getSchematicNode(int owner, String name, String type, int parent) { public static SchematicNode getSchematicNode(int owner, String name, Integer parent) {
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ? AND NodeType = ?", owner, name, parent, type); if(parent != null && parent == 0)
try { parent = null;
if(!set.next()) ResultSet set;
return null; if(parent == null) {
return new SchematicNode(set); set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL", owner, name);
}catch (SQLException e) { }else {
throw new SecurityException("Failed to load Schemnodes", e); set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent);
} }
}
public static SchematicNode getSchematicNode(int owner, String name, int parent) {
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, parent);
try { try {
while (set.next()) { while (set.next()) {
SchematicNode node = new SchematicNode(set); SchematicNode node = new SchematicNode(set);
if(!node.isDir()) if(!node.isDir())
return node; 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; return null;
}catch (SQLException e) { }catch (SQLException e) {
throw new SecurityException("Failed to load Schemnodes", e); throw new SecurityException("Failed to load Schemnodes", e);
@ -76,8 +79,15 @@ public class SchematicNode {
return getSchematicNode(owner, name, parent.getId()); return getSchematicNode(owner, name, parent.getId());
} }
public static List<SchematicNode> getSchematicNodeInNode(int parent) { public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode = ?", parent); if(parent != null && parent == 0)
parent = null;
ResultSet set;
if(parent == null) {
set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode is NULL");
}else {
set = SQL.select("SELECT * FROM SchematicNode WHERE ParentNode = ?", parent);
}
try { try {
List<SchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
while (set.next()) while (set.next())
@ -92,12 +102,19 @@ public class SchematicNode {
return getSchematicNodeInNode(parent.getId()); return getSchematicNodeInNode(parent.getId());
} }
public static SchematicNode getSchematicDirectory(int owner, String name, SchematicNode parent) { public static SchematicNode getSchematicDirectory(String name, SchematicNode parent) {
return getSchematicDirectory(owner, name, parent.getId()); return getSchematicDirectory(name, parent.getId());
} }
public static SchematicNode getSchematicDirectory(int owner, String name, int parent) { public static SchematicNode getSchematicDirectory(String name, Integer parent) {
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?", owner, name, 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);
}else {
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
}
try { try {
while (set.next()) { while (set.next()) {
SchematicNode node = new SchematicNode(set); SchematicNode node = new SchematicNode(set);
@ -110,8 +127,15 @@ public class SchematicNode {
} }
} }
public static SchematicNode getSchematicInParent(String name, int parent) { public static SchematicNode getSchematicInParent(String name, Integer parent) {
ResultSet set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, 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);
}else {
set = SQL.select("SELECT * FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?", name, parent);
}
try { try {
while (set.next()) { while (set.next()) {
SchematicNode node = new SchematicNode(set); SchematicNode node = new SchematicNode(set);
@ -159,7 +183,9 @@ public class SchematicNode {
} }
} }
public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, int parent) { public static List<SchematicNode> getSchematicsOfType(int owner, String schemType, Integer parent) {
if(parent != null && parent == 0)
parent = null;
List<SchematicNode> schems = getAllSchematicsOfType(owner, schemType); List<SchematicNode> schems = getAllSchematicsOfType(owner, schemType);
Map<Integer, SchematicNode> nodesInParent = new LinkedHashMap<>(); Map<Integer, SchematicNode> nodesInParent = new LinkedHashMap<>();
for (SchematicNode schematicNode : schems) { for (SchematicNode schematicNode : schems) {
@ -172,8 +198,8 @@ public class SchematicNode {
return new ArrayList<>(nodesInParent.values()); return new ArrayList<>(nodesInParent.values());
} }
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, int parent) { public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
if(parent != 0) { if(parent != null && parent != 0) {
SchematicNode node = SchematicNode.getSchematicNode(parent); SchematicNode node = SchematicNode.getSchematicNode(parent);
boolean isAdded = false; boolean isAdded = false;
while (node.getId() != 0) { while (node.getId() != 0) {
@ -187,8 +213,8 @@ public class SchematicNode {
} }
if(isAdded) if(isAdded)
return getSchematicNodeInNode(parent); return getSchematicNodeInNode(parent);
} } else {
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 = ? ) AND s.ParentNode = ? GROUP BY s.NodeId ORDER BY s.NodeName", user, user, parent); 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);
try{ try{
List<SchematicNode> nodes = new ArrayList<>(); List<SchematicNode> nodes = new ArrayList<>();
while(set.next()) while(set.next())
@ -198,6 +224,8 @@ public class SchematicNode {
throw new SecurityException("Failed listing schematics", e); throw new SecurityException("Failed listing schematics", e);
} }
} }
return null;
}
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) { 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 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);
@ -231,7 +259,7 @@ public class SchematicNode {
if(type != null) { if(type != null) {
isDir = false; isDir = false;
rank = set.getInt("NodeRank"); rank = set.getInt("NodeRank");
schemFormat = set.getBoolean("SchemFormat"); schemFormat = set.getBoolean("NodeFormat");
}else { }else {
isDir = true; isDir = true;
} }
@ -417,7 +445,7 @@ public class SchematicNode {
} }
private void updateDatabase(Blob blob, boolean newFormat) { private void updateDatabase(Blob blob, boolean newFormat) {
SQL.update("UPDATE SchematicNode SET NodeData = ?, SchemFormat = ? WHERE NodeId = ?", blob, newFormat, id); SQL.update("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?", blob, newFormat, id);
schemFormat = newFormat; schemFormat = newFormat;
} }
} }