SteamWar/SpigotCore
Archiviert
13
0

Complete Translation Layer

Dieser Commit ist enthalten in:
Chaoscaot 2021-01-27 13:47:47 +01:00
Ursprung 18c4318df3
Commit c274c5e1d0

Datei anzeigen

@ -19,11 +19,11 @@
package de.steamwar.sql; package de.steamwar.sql;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class SchematicMember { public class SchematicMember {
@ -34,15 +34,11 @@ public class SchematicMember {
} }
public SchematicMember(String schemName, int schemOwner, int schemMember){ public SchematicMember(String schemName, int schemOwner, int schemMember){
this(schemName, schemOwner, schemMember, true); this(NodeMember.getNodeMember(SchematicNode.getSchematicNode(schemOwner, schemName, 0).getId(), schemMember));
} }
public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){ public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){
this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId(), true); this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId());
}
private void updateDB(){
SQL.update("INSERT INTO SchemMember (SchemName, SchemOwner, Member) VALUES (?, ?, ?)", schemName, schemOwner, member);
} }
public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){ public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){
@ -50,28 +46,11 @@ public class SchematicMember {
} }
public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember) { public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember) {
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ? AND Member = ?", schemName, schemOwner, schemMember); return new SchematicMember(NodeMember.getNodeMember(SchematicNode.getSchematicNode(schemOwner, schemName, 0).getOwner(), schemMember));
try {
if(schematicMember == null || !schematicMember.next()){
return null;
}
return new SchematicMember(schemName, schemOwner, schemMember, false);
} catch (SQLException e) {
throw new SecurityException("Could not get schemmember", e);
}
} }
public static SchematicMember getMemberBySchematic(String schemName, int schemMember){ public static SchematicMember getMemberBySchematic(String schemName, int schemMember){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND Member = ?", schemName, schemMember); return new SchematicMember(NodeMember.getSchematics(schemMember).stream().filter(member1 -> SchematicNode.getSchematicNode(member1.getNode()).getName().equals(schemName)).limit(1).collect(Collectors.toList()).get(0));
try {
if(schematicMember == null || !schematicMember.next()){
return null;
}
int schemOwner = schematicMember.getInt("SchemOwner");
return new SchematicMember(schemName, schemOwner, schemMember, false);
} catch (SQLException e) {
throw new SecurityException("Could not get member", e);
}
} }
public static List<SchematicMember> getSchemMembers(String schemName, UUID schemOwner){ public static List<SchematicMember> getSchemMembers(String schemName, UUID schemOwner){
@ -79,17 +58,10 @@ public class SchematicMember {
} }
public static List<SchematicMember> getSchemMembers(String schemName, int schemOwner){ public static List<SchematicMember> getSchemMembers(String schemName, int schemOwner){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner); Set<NodeMember> members = NodeMember.getNodeMembers(SchematicNode.getSchematicNode(schemOwner, schemName, 0).getId());
try { List<SchematicMember> retMembers = new ArrayList<>();
List<SchematicMember> schematicMembers = new ArrayList<>(); members.forEach(member1 -> retMembers.add(new SchematicMember(member1)));
while(schematicMember.next()){ return retMembers;
int schemMember = schematicMember.getInt("Member");
schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false));
}
return schematicMembers;
} catch (SQLException e) {
throw new SecurityException("Could not get schemmembers", e);
}
} }
public static List<SchematicMember> getAccessibleSchems(UUID schemMember){ public static List<SchematicMember> getAccessibleSchems(UUID schemMember){
@ -97,33 +69,24 @@ public class SchematicMember {
} }
public static List<SchematicMember> getAccessibleSchems(int schemMember){ public static List<SchematicMember> getAccessibleSchems(int schemMember){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE Member = ?", schemMember); List<SchematicMember> members = new ArrayList<>();
try { NodeMember.getSchematics(schemMember).forEach(member1 -> members.add(new SchematicMember(member1)));
List<SchematicMember> schematicMembers = new ArrayList<>(); return members;
while(schematicMember.next()){
String schemName = schematicMember.getString("SchemName");
int schemOwner = schematicMember.getInt("SchemOwner");
schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false));
}
return schematicMembers;
} catch (SQLException e) {
throw new SecurityException("Could not get accessible schems", e);
}
} }
public int getSchemOwner() { public int getSchemOwner() {
return schemOwner; return SchematicNode.getSchematicNode(member.getNode()).getOwner();
} }
public String getSchemName() { public String getSchemName() {
return schemName; return SchematicNode.getSchematicNode(member.getNode()).getName();
} }
public int getMember() { public int getMember() {
return member; return member.getMember();
} }
public void remove(){ public void remove(){
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ? AND Member = ?", schemOwner, schemName, member); member.delete();
} }
} }