SteamWar/SpigotCore
Archiviert
13
0

Schematic Nodes #90

Zusammengeführt
Lixfel hat 48 Commits von schematic-node nach master 2021-11-20 13:12:32 +01:00 zusammengeführt
Nur Änderungen aus Commit c274c5e1d0 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -19,11 +19,11 @@
package de.steamwar.sql;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class SchematicMember {
Chaoscaot markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Da das einfach (auch in anderen Systemen) nur unnötig viele Änderungen provoziert, obwohl sich häufig eigentlich nichts ändert: Behalte diesen alten Namen (und ggf. je nachdem, wie weit möglich) die alte API bei. Also NodeMember als SchematicMember lassen.

Da das einfach (auch in anderen Systemen) nur unnötig viele Änderungen provoziert, obwohl sich häufig eigentlich nichts ändert: Behalte diesen alten Namen (und ggf. je nachdem, wie weit möglich) die alte API bei. Also NodeMember als SchematicMember lassen.
Veraltet
Review

????

????
@ -34,44 +34,23 @@ public class SchematicMember {
}
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){
this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId(), true);
}
private void updateDB(){
SQL.update("INSERT INTO SchemMember (SchemName, SchemOwner, Member) VALUES (?, ?, ?)", schemName, schemOwner, member);
this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId());
}
public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){
return getSchemMemberFromDB(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId());
}
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);
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 getSchemMemberFromDB(String schemName, int schemOwner, int schemMember) {
return new SchematicMember(NodeMember.getNodeMember(SchematicNode.getSchematicNode(schemOwner, schemName, 0).getOwner(), schemMember));
}
public static SchematicMember getMemberBySchematic(String schemName, int schemMember){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND Member = ?", schemName, schemMember);
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);
}
return new SchematicMember(NodeMember.getSchematics(schemMember).stream().filter(member1 -> SchematicNode.getSchematicNode(member1.getNode()).getName().equals(schemName)).limit(1).collect(Collectors.toList()).get(0));
}
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){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner);
try {
List<SchematicMember> schematicMembers = new ArrayList<>();
while(schematicMember.next()){
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);
}
Set<NodeMember> members = NodeMember.getNodeMembers(SchematicNode.getSchematicNode(schemOwner, schemName, 0).getId());
List<SchematicMember> retMembers = new ArrayList<>();
members.forEach(member1 -> retMembers.add(new SchematicMember(member1)));
return retMembers;
}
public static List<SchematicMember> getAccessibleSchems(UUID schemMember){
@ -97,33 +69,24 @@ public class SchematicMember {
}
public static List<SchematicMember> getAccessibleSchems(int schemMember){
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE Member = ?", schemMember);
try {
List<SchematicMember> schematicMembers = new ArrayList<>();
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);
}
List<SchematicMember> members = new ArrayList<>();
NodeMember.getSchematics(schemMember).forEach(member1 -> members.add(new SchematicMember(member1)));
return members;
}
public int getSchemOwner() {
return schemOwner;
return SchematicNode.getSchematicNode(member.getNode()).getOwner();
}
public String getSchemName() {
return schemName;
return SchematicNode.getSchematicNode(member.getNode()).getName();
}
public int getMember() {
return member;
return member.getMember();
}
public void remove(){
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ? AND Member = ?", schemOwner, schemName, member);
member.delete();
}
}