SteamWar/SpigotCore
Archiviert
13
0

WIP Standalone SpigotCore
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-02-01 16:36:19 +01:00
Ursprung 877aaea1df
Commit 846147b521
12 geänderte Dateien mit 455 neuen und 275 gelöschten Zeilen

Datei anzeigen

@ -19,8 +19,6 @@
package de.steamwar.sql;
import java.util.function.BiConsumer;
public class EventFight {
public static EventFight get(int fightID) {
@ -33,27 +31,23 @@ public class EventFight {
private final int teamRed;
private final int kampfleiter;
private final int ergebnis;
private final BiConsumer<EventFight, Integer> setErgebnis;
private final BiConsumer<EventFight, Integer> setFight;
public EventFight(int eventID, int fightID, int teamBlue, int teamRed, int kampfleiter, int ergebnis, BiConsumer<EventFight, Integer> setErgebnis, BiConsumer<EventFight, Integer> setFight) {
public EventFight(int eventID, int fightID, int teamBlue, int teamRed, int kampfleiter, int ergebnis) {
this.eventID = eventID;
this.fightID = fightID;
this.teamBlue = teamBlue;
this.teamRed = teamRed;
this.kampfleiter = kampfleiter;
this.ergebnis = ergebnis;
this.setErgebnis = setErgebnis;
this.setFight = setFight;
}
public void setErgebnis(int winner){
setErgebnis.accept(this, winner);
public void setErgebnis(int winner) {
Provider.impl.setEventFightResult(this, winner);
}
public void setFight(int fight){
public void setFight(int fight) {
//Fight.FightID, not EventFight.FightID
setFight.accept(this, fight);
Provider.impl.setEventFightFightID(this, fight);
}
public int getTeamBlue() {

Datei anzeigen

@ -19,56 +19,36 @@
package de.steamwar.sql;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
public class NodeMember {
private static final Statement getNodeMember = new Statement("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?");
private static final Statement getNodeMembers = new Statement("SELECT * FROM NodeMember WHERE NodeId = ?");
private static final Statement getSchematics = new Statement("SELECT * FROM NodeMember WHERE UserId = ?");
private static final Statement createNodeMember = new Statement("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)");
private static final Statement deleteNodeMember = new Statement("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?");
public static NodeMember getNodeMember(int node, int member) {
return getNodeMember.select(rs -> {
if(!rs.next())
return null;
return new NodeMember(rs);
}, node, member);
return Provider.impl.getNodeMember(node, member);
}
public static Set<NodeMember> getNodeMembers(int node) {
return getNodeMembers.select(rs -> {
Set<NodeMember> members = new HashSet<>();
while (rs.next())
members.add(new NodeMember(rs));
return members;
}, node);
return Provider.impl.getNodeMembers(node);
}
public static Set<NodeMember> getSchematics(int member) {
return getSchematics.select(rs -> {
Set<NodeMember> members = new HashSet<>();
while (rs.next())
members.add(new NodeMember(rs));
return members;
}, member);
return Provider.impl.getMemberSchematics(member);
}
public static NodeMember createNodeMember(int node, int member) {
createNodeMember.update(node, member);
Provider.impl.createNodeMember(node, member);
return getNodeMember(node, member);
}
final int node;
final int member;
private final int node;
private final int member;
private final Consumer<NodeMember> delete;
private NodeMember(ResultSet set) throws SQLException {
node = set.getInt("NodeId");
member = set.getInt("UserId");
public NodeMember(int node, int member, Consumer<NodeMember> delete) {
this.node = node;
this.member = member;
this.delete = delete;
}
public int getNode() {
@ -80,6 +60,6 @@ public class NodeMember {
}
public void delete() {
deleteNodeMember.update(node, member);
delete.accept(this);
}
}

Datei anzeigen

@ -23,19 +23,31 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import java.io.StringReader;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class PersonalKit {
private static final Statement getKits = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ?");
private static final Statement getKit = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?");
private static final Statement getKitInUse = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND InUse = 1");
private static final Statement delete = new Statement("DELETE FROM `PersonalKit` WHERE UserID = ? AND GameMode = ? AND Name = ?");
private static final Statement update = new Statement("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor, InUse) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor), Name = VALUES(Name), InUse = VALUES(InUse)");
public static List<PersonalKit> get(int userID, String gamemode){
return Provider.impl.getKits(userID, gamemode);
}
public static PersonalKit get(int userID, String gamemode, String name) {
return Provider.impl.getKit(userID, gamemode, name);
}
public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){
if(armor == null) {
armor = new ItemStack[]{null, null, null, null};
}
PersonalKit kit = new PersonalKit(userID, name, gamemode, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor), true);
Provider.impl.updateKit(kit);
return kit;
}
public static PersonalKit getKitInUse(int userID, String gamemode) {
return Provider.impl.getKitInUse(userID, gamemode);
}
private final int userID;
private String name;
@ -44,49 +56,13 @@ public class PersonalKit {
private String armor;
private boolean inUse;
private PersonalKit(ResultSet rs) throws SQLException {
userID = rs.getInt("UserID");
gamemode = rs.getString("GameMode");
inventory = rs.getString("Inventory");
armor = rs.getString("Armor");
name = rs.getString("Name");
inUse = rs.getBoolean("InUse");
}
public static List<PersonalKit> get(int userID, String gamemode){
return getKits.select(rs -> {
List<PersonalKit> list = new ArrayList<>();
while (rs.next())
list.add(new PersonalKit(rs));
return list;
}, userID, gamemode);
}
public static PersonalKit get(int userID, String gamemode, String name) {
return getKit.select(rs -> {
if(rs.next())
return new PersonalKit(rs);
return null;
}, userID, gamemode, name);
}
public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){
if(armor == null) {
armor = new ItemStack[]{null, null, null, null};
}
update.update(userID, gamemode, name, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor), true);
return get(userID, gamemode, name);
}
public static PersonalKit getKitInUse(int userID, String gamemode) {
return getKitInUse.select(rs -> {
if(!rs.next())
return null;
PersonalKit kit = new PersonalKit(rs);
while (rs.next())
new PersonalKit(rs).setUse(false); //TODO: Violation of integrity, should not be necessary?
return kit;
}, userID, gamemode);
public PersonalKit(int userID, String name, String gamemode, String inventory, String armor, boolean inUse) {
this.userID = userID;
this.name = name;
this.gamemode = gamemode;
this.inventory = inventory;
this.armor = armor;
this.inUse = inUse;
}
public ItemStack[] getInventory(){
@ -107,6 +83,18 @@ public class PersonalKit {
return name;
}
public String getGamemode() {
return gamemode;
}
public String getRawInventory() {
return inventory;
}
public String getRawArmor() {
return armor;
}
public boolean isInUse() {
return inUse;
}
@ -120,32 +108,32 @@ public class PersonalKit {
private void setUse(boolean inUse) {
this.inUse = inUse;
updateDB();
Provider.impl.updateKit(this);
}
public void setName(String name) {
this.name = name;
updateDB();
Provider.impl.updateKit(this);
}
public void setInventory(ItemStack[] inventory) {
this.inventory = saveInvConfig("Inventory", inventory);
updateDB();
Provider.impl.updateKit(this);
}
public void setArmor(ItemStack[] armor) {
this.armor = saveInvConfig("Armor", armor);
updateDB();
Provider.impl.updateKit(this);
}
public void setContainer(ItemStack[] inventory, ItemStack[] armor) {
this.armor = saveInvConfig("Armor", armor);
this.inventory = saveInvConfig("Inventory", inventory);
updateDB();
Provider.impl.updateKit(this);
}
public void delete() {
delete.update(userID, gamemode, name);
Provider.impl.deleteKit(this);
}
private static String saveInvConfig(String name, ItemStack[] inv) {
@ -154,8 +142,4 @@ public class PersonalKit {
return armorConfig.saveToString();
}
private void updateDB() {
update.update(userID, gamemode, name, inventory, armor, inUse);
}
}

Datei anzeigen

@ -24,6 +24,9 @@ import de.steamwar.core.Core;
import java.io.InputStream;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
public interface Provider {
@ -40,6 +43,8 @@ public interface Provider {
Event getEvent(int eventID);
EventFight getEventFight(int fightID);
void setEventFightResult(EventFight fight, int winner);
void setEventFightFightID(EventFight fight, int fightID);
int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock);
void getReplay(int fightID, Consumer<InputStream> reader);
@ -48,4 +53,31 @@ public interface Provider {
void createFightPlayer(int fightID, int userID, boolean blue, String kit, int kills, boolean isOut);
void createDownloadLink(int nodeId, String hash);
NodeMember getNodeMember(int node, int member);
Set<NodeMember> getNodeMembers(int node);
Set<NodeMember> getMemberSchematics(int member);
void createNodeMember(int node, int member);
List<PersonalKit> getKits(int userID, String gamemode);
PersonalKit getKit(int userID, String gamemode, String name);
void updateKit(PersonalKit kit);
void deleteKit(PersonalKit kit);
PersonalKit getKitInUse(int userID, String gamemode);
Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type);
Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user);
SteamwarUser getUserByName(String userName);
SteamwarUser getUserByUUID(UUID uuid);
SteamwarUser getUserByID(int id);
void logException(String server, String message, String stacktrace);
Team getTeam(int id);
List<Integer> getTeamMembers(Team team);
String getConfig(int player, String config);
void updatePlayerConfig(int id, String config, String value);
void removePlayerConfig(int id, String config);
}

Datei anzeigen

@ -22,33 +22,21 @@ package de.steamwar.sql;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Date;
import java.util.Map;
import java.util.function.Consumer;
public class Punishment {
private static final Statement getPunishment = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
private static final Statement getPunishments = new Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)");
public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
return getPunishment.select(rs -> {
if (rs.next())
return new Punishment(rs);
return null;
}, user, type.name());
return Provider.impl.getPunishmentOfPlayer(user, type);
}
public static Map<PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
return getPunishments.select(rs -> {
Map<PunishmentType, Punishment> punishments = new HashMap<>();
while (rs.next())
punishments.put(PunishmentType.valueOf(rs.getString("Type")), new Punishment(rs));
return punishments;
}, user);
return Provider.impl.getPunishmentsOfPlayer(user);
}
public static boolean isPunished(SteamwarUser user, Punishment.PunishmentType type, Consumer<Punishment> callback) {
@ -61,24 +49,23 @@ public class Punishment {
}
}
private final Timestamp startTime;
private Timestamp endTime;
private final PunishmentType type;
private final int user;
private final int id;
private String reason;
private final int punisher;
private boolean perma;
private Punishment(ResultSet set) throws SQLException {
user = set.getInt("UserId");
reason = set.getString("Reason");
type = PunishmentType.valueOf(set.getString("Type"));
startTime = set.getTimestamp("StartTime");
endTime = set.getTimestamp("EndTime");
punisher = set.getInt("Punisher");
perma = set.getBoolean("Perma");
id = set.getInt("PunishmentId");
private final int user;
private final int punisher;
private final PunishmentType type;
private final Timestamp startTime;
private final Timestamp endTime;
private final boolean perma;
private final String reason;
public Punishment(int user, int punisher, PunishmentType type, Timestamp startTime, Timestamp endTime, boolean perma, String reason) {
this.user = user;
this.punisher = punisher;
this.type = type;
this.startTime = startTime;
this.endTime = endTime;
this.perma = perma;
this.reason = reason;
}
public Timestamp getStartTime() {

Datei anzeigen

@ -23,22 +23,21 @@ import java.io.InputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.function.Consumer;
public class SQLProvider implements Provider {
private static final Statement getMember = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
private static final Statement getBauMember = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
@Override
public BauweltMember getBauMember(int ownerID, int memberID) {
return getMember.select(rs -> rs.next() ? newBauweltMember(rs) : null, ownerID, memberID);
return getBauMember.select(rs -> rs.next() ? newBauweltMember(rs) : null, ownerID, memberID);
}
private static final Statement getMembers = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ?");
private static final Statement getBauMembers = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ?");
@Override
public List<BauweltMember> getMembers(int bauweltID) {
return getMembers.select(rs -> {
return getBauMembers.select(rs -> {
List<BauweltMember> members = new ArrayList<>();
while(rs.next())
members.add(newBauweltMember(rs));
@ -102,20 +101,26 @@ public class SQLProvider implements Provider {
}
private static final Statement getEventFight = new Statement("SELECT * FROM EventFight WHERE FightID = ?");
private static final Statement setEventFightResult = new Statement("UPDATE EventFight SET Ergebnis = ? WHERE FightID = ?");
private static final Statement setEventFightFightID = new Statement("UPDATE EventFight SET Fight = ? WHERE FightID = ?");
@Override
public EventFight getEventFight(int fightID) {
return getEventFight.select(rs -> {
rs.next();
return new EventFight(
rs.getInt("EventID"), rs.getInt("FightID"), rs.getInt("TeamBlue"), rs.getInt("TeamRed"), rs.getInt("Kampfleiter"), rs.getInt("Ergebnis"),
(eventFight, winner) -> setEventFightResult.update(winner, eventFight.getFightID()),
(eventFight, fight) -> setEventFightFightID.update(fight, eventFight.getFightID())
);
return new EventFight(rs.getInt("EventID"), rs.getInt("FightID"), rs.getInt("TeamBlue"), rs.getInt("TeamRed"), rs.getInt("Kampfleiter"), rs.getInt("Ergebnis"));
}, fightID);
}
private static final Statement setEventFightResult = new Statement("UPDATE EventFight SET Ergebnis = ? WHERE FightID = ?");
@Override
public void setEventFightResult(EventFight fight, int winner) {
setEventFightResult.update(winner, fight.getFightID());
}
private static final Statement setEventFightFightID = new Statement("UPDATE EventFight SET Fight = ? WHERE FightID = ?");
@Override
public void setEventFightFightID(EventFight fight, int fightID) {
setEventFightFightID.update(fight, fight.getFightID());
}
private static final Statement createFight = new Statement("INSERT INTO Fight (GameMode, Server, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition, ReplayLock) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
private static final Statement getLastFightID = new Statement("SELECT LAST_INSERT_ID() AS FightID");
@Override
@ -154,4 +159,199 @@ public class SQLProvider implements Provider {
public void createDownloadLink(int nodeId, String hash) {
createLink.update(nodeId, hash);
}
private static final Statement getNodeMember = new Statement("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?");
@Override
public NodeMember getNodeMember(int node, int member) {
return getNodeMember.select(rs -> {
if(!rs.next())
return null;
return newNodeMember(rs);
}, node, member);
}
private static final Statement getNodeMembers = new Statement("SELECT * FROM NodeMember WHERE NodeId = ?");
@Override
public Set<NodeMember> getNodeMembers(int node) {
return getNodeMembers.select(rs -> {
Set<NodeMember> members = new HashSet<>();
while (rs.next())
members.add(newNodeMember(rs));
return members;
}, node);
}
private static final Statement getSchematics = new Statement("SELECT * FROM NodeMember WHERE UserId = ?");
@Override
public Set<NodeMember> getMemberSchematics(int member) {
return getSchematics.select(rs -> {
Set<NodeMember> members = new HashSet<>();
while (rs.next())
members.add(newNodeMember(rs));
return members;
}, member);
}
private static final Statement deleteNodeMember = new Statement("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?");
private NodeMember newNodeMember(ResultSet rs) throws SQLException {
return new NodeMember(rs.getInt("NodeId"), rs.getInt("UserId"), member -> deleteNodeMember.update(member.getNode(), member.getMember()));
}
private static final Statement createNodeMember = new Statement("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)");
@Override
public void createNodeMember(int node, int member) {
createNodeMember.update(node, member);
}
private static final Statement getKits = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ?");
@Override
public List<PersonalKit> getKits(int userID, String gamemode) {
return getKits.select(rs -> {
List<PersonalKit> list = new ArrayList<>();
while (rs.next())
list.add(newPersonalKit(rs));
return list;
}, userID, gamemode);
}
private static final Statement getKit = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?");
@Override
public PersonalKit getKit(int userID, String gamemode, String name) {
return getKit.select(rs -> {
if(rs.next())
return newPersonalKit(rs);
return null;
}, userID, gamemode, name);
}
private PersonalKit newPersonalKit(ResultSet rs) throws SQLException {
return new PersonalKit(rs.getInt("UserID"), rs.getString("Name"), rs.getString("GameMode"), rs.getString("Inventory"), rs.getString("Armor"), rs.getBoolean("InUse"));
}
private static final Statement updateKit = new Statement("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor, InUse) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor), Name = VALUES(Name), InUse = VALUES(InUse)");
@Override
public void updateKit(PersonalKit kit) {
updateKit.update(kit.getUserID(), kit.getGamemode(), kit.getName(), kit.getRawInventory(), kit.getRawArmor(), kit.isInUse());
}
private static final Statement deleteKit = new Statement("DELETE FROM `PersonalKit` WHERE UserID = ? AND GameMode = ? AND Name = ?");
@Override
public void deleteKit(PersonalKit kit) {
deleteKit.update(kit.getUserID(), kit.getGamemode(), kit.getName());
}
private static final Statement getKitInUse = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND InUse = 1");
@Override
public PersonalKit getKitInUse(int userID, String gamemode) {
return getKitInUse.select(rs -> {
if(rs.next())
return newPersonalKit(rs);
return null;
}, userID, gamemode);
}
private static final Statement getPunishment = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
@Override
public Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type) {
return getPunishment.select(rs -> {
if (rs.next())
return newPunishment(rs);
return null;
}, user, type.name());
}
private Punishment newPunishment(ResultSet rs) throws SQLException {
return new Punishment(rs.getInt("UserId"), rs.getInt("Punisher"), Punishment.PunishmentType.valueOf(rs.getString("Type")), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getBoolean("Perma"), rs.getString("Reason"));
}
private static final Statement getPunishments = new Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)");
@Override
public Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
return getPunishments.select(rs -> {
Map<Punishment.PunishmentType, Punishment> punishments = new HashMap<>();
while (rs.next())
punishments.put(Punishment.PunishmentType.valueOf(rs.getString("Type")), newPunishment(rs));
return punishments;
}, user);
}
private static final Statement getUserName = new Statement("SELECT * FROM UserData WHERE lower(UserName) = ?");
@Override
public SteamwarUser getUserByName(String userName) {
return getUserName.select(rs -> {
if(rs.next())
return newSteamwarUser(rs);
return null;
}, userName.toLowerCase());
}
private static final Statement getUserUUID = new Statement("SELECT * FROM UserData WHERE UUID = ?");
@Override
public SteamwarUser getUserByUUID(UUID uuid) {
return getUserUUID.select(rs -> {
rs.next();
return newSteamwarUser(rs);
}, uuid.toString());
}
private static final Statement getUserId = new Statement("SELECT * FROM UserData WHERE id = ?");
@Override
public SteamwarUser getUserByID(int id) {
return getUserId.select(rs -> {
rs.next();
return newSteamwarUser(rs);
}, id);
}
private SteamwarUser newSteamwarUser(ResultSet rs) throws SQLException {
return new SteamwarUser(rs.getInt("id"), UUID.fromString(rs.getString("UUID")), rs.getString("UserName"), UserGroup.getUsergroup(rs.getString("UserGroup")), rs.getInt("Team"), rs.getBoolean("Bedrock"));
}
private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");
@Override
public void logException(String server, String message, String stacktrace) {
insert.update(server, message, stacktrace);
}
private static final Statement getTeam = new Statement("SELECT * FROM Team WHERE TeamID = ?");
@Override
public Team getTeam(int id) {
return getTeam.select(rs -> {
rs.next();
return new Team(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"));
}, id);
}
private static final Statement getTeamMembers = new Statement("SELECT id FROM UserData WHERE Team = ?");
@Override
public List<Integer> getTeamMembers(Team team) {
return getTeamMembers.select(rs -> {
List<Integer> members = new ArrayList<>();
while(rs.next())
members.add(rs.getInt("id"));
return members;
}, team.getTeamId());
}
private static final Statement getConfig = new Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?");
@Override
public String getConfig(int player, String config) {
return getConfig.select(rs -> {
if(rs.next())
return rs.getString("Value");
return null;
}, player, config);
}
private static final Statement setConfig = new Statement("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)");
@Override
public void updatePlayerConfig(int id, String config, String value) {
setConfig.update(id, config, value);
}
private static final Statement deleteConfig = new Statement("DELETE FROM UserConfig WHERE User = ? AND Config = ?");
@Override
public void removePlayerConfig(int id, String config) {
deleteConfig.update(id, config);
}
}

Datei anzeigen

@ -25,8 +25,6 @@ import org.bukkit.entity.Player;
public class SWException {
private SWException(){}
private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");
public static void log(String message, String stacktrace){
message += "\n";
for(Player player : Bukkit.getOnlinePlayers())
@ -38,6 +36,6 @@ public class SWException {
else
server = Bukkit.getWorlds().get(0).getName();
insert.update(server, message, stacktrace);
Provider.impl.logException(server, message, stacktrace);
}
}

Datei anzeigen

@ -21,12 +21,12 @@ package de.steamwar.sql;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.io.InputStream;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@ -67,9 +67,15 @@ public class StandaloneProvider implements Provider {
@Override
public EventFight getEventFight(int fightID) {
return new EventFight(0, fightID, 0, 0, 0, 0, (eventFight, winner) -> {}, (eventFight, fightId) -> {});
return new EventFight(0, fightID, 0, 0, 0, 0);
}
@Override
public void setEventFightResult(EventFight fight, int winner) {}
@Override
public void setEventFightFightID(EventFight fight, int fightID) {}
@Override
public int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock) {
return 0;
@ -87,5 +93,103 @@ public class StandaloneProvider implements Provider {
@Override
public void createDownloadLink(int nodeId, String hash) {}
@Override
public NodeMember getNodeMember(int node, int member) {
return null;
}
@Override
public Set<NodeMember> getNodeMembers(int node) {
return Collections.emptySet();
}
@Override
public Set<NodeMember> getMemberSchematics(int member) {
return Collections.emptySet();
}
@Override
public void createNodeMember(int node, int member) {}
@Override
public List<PersonalKit> getKits(int userID, String gamemode) {
return Collections.emptyList();
}
@Override
public PersonalKit getKit(int userID, String gamemode, String name) {
return null;
}
@Override
public void updateKit(PersonalKit kit) {}
@Override
public void deleteKit(PersonalKit kit) {}
@Override
public PersonalKit getKitInUse(int userID, String gamemode) {
return null;
}
@Override
public Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type) {
return null;
}
@Override
public Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
return Collections.emptyMap();
}
private int userId = 1;
private final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
@Override
public SteamwarUser getUserByName(String userName) {
Player player = Bukkit.getPlayer(userName);
if(player == null)
return null;
return usersByUUID.computeIfAbsent(player.getUniqueId(), uuid -> new SteamwarUser(userId++, uuid, userName, UserGroup.Member, 0, false));
}
@Override
public SteamwarUser getUserByUUID(UUID uuid) {
return usersByUUID.computeIfAbsent(uuid, uuid1 -> new SteamwarUser(userId++, uuid1, Objects.requireNonNull(Objects.requireNonNull(Bukkit.getOfflinePlayer(uuid1)).getName()), UserGroup.Member, 0, false));
}
@Override
public SteamwarUser getUserByID(int id) {
return usersByUUID.values().stream().filter(user -> user.getId() == id).findAny().get();
}
@Override
public void logException(String server, String message, String stacktrace) {}
@Override
public Team getTeam(int id) {
return new Team(0, "TEST", "TestAlliancePleaseIgnore", "c");
}
@Override
public List<Integer> getTeamMembers(Team team) {
return Collections.emptyList();
}
private final Map<Integer, Map<String, String>> configs = new HashMap<>();
@Override
public String getConfig(int player, String config) {
return configs.computeIfAbsent(player, player1 -> new HashMap<>()).get(config);
}
@Override
public void updatePlayerConfig(int id, String config, String value) {
configs.computeIfAbsent(id, player -> new HashMap<>()).put(config, value);
}
@Override
public void removePlayerConfig(int id, String config) {
configs.computeIfAbsent(id, player -> new HashMap<>()).remove(config);
}
}

Datei anzeigen

@ -23,17 +23,12 @@ import de.steamwar.core.Core;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class SteamwarUser {
private static final Statement getId = new Statement("SELECT * FROM UserData WHERE id = ?");
private static final Statement getUUID = new Statement("SELECT * FROM UserData WHERE UUID = ?");
private static final Statement getName = new Statement("SELECT * FROM UserData WHERE lower(UserName) = ?");
private static final Map<UUID, SteamwarUser> byUUID = new HashMap<>();
private static final Map<String, SteamwarUser> byName = new HashMap<>();
@ -54,21 +49,17 @@ public class SteamwarUser {
private final int team;
private final boolean bedrock;
private SteamwarUser(ResultSet rs){
try {
id = rs.getInt("id");
uuid = java.util.UUID.fromString(rs.getString("UUID"));
userName = rs.getString("UserName");
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
team = rs.getInt("Team");
bedrock = rs.getBoolean("Bedrock");
public SteamwarUser(int id, UUID uuid, String userName, UserGroup userGroup, int team, boolean bedrock) {
this.id = id;
this.uuid = uuid;
this.userName = userName;
this.userGroup = userGroup;
this.team = team;
this.bedrock = bedrock;
byUUID.put(uuid, this);
byName.put(userName.toLowerCase(), this);
byId.put(id, this);
} catch (SQLException e) {
throw new SecurityException("Could not instance User", e);
}
byUUID.put(uuid, this);
byName.put(userName.toLowerCase(), this);
byId.put(id, this);
}
public int getId() {
@ -98,31 +89,21 @@ public class SteamwarUser {
public static SteamwarUser get(String userName){
SteamwarUser user = byName.get(userName.toLowerCase());
if(user == null)
user = getName.select(rs -> {
if(rs.next())
return new SteamwarUser(rs);
return null;
}, userName.toLowerCase());
user = Provider.impl.getUserByName(userName);
return user;
}
public static SteamwarUser get(UUID uuid){
SteamwarUser user = byUUID.get(uuid);
if(user == null)
user = getUUID.select(rs -> {
rs.next();
return new SteamwarUser(rs);
}, uuid.toString());
user = Provider.impl.getUserByUUID(uuid);
return user;
}
public static SteamwarUser get(int id) {
SteamwarUser user = byId.get(id);
if(user == null)
user = getId.select(rs -> {
rs.next();
return new SteamwarUser(rs);
}, id);
user = Provider.impl.getUserByID(id);
return user;
}

Datei anzeigen

@ -19,16 +19,10 @@
package de.steamwar.sql;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class Team {
private static final Statement get = new Statement("SELECT * FROM Team WHERE TeamID = ?");
private static final Statement getMembers = new Statement("SELECT id FROM UserData WHERE Team = ?");
private final int teamId;
private final String teamKuerzel;
private final String teamName;
@ -36,24 +30,17 @@ public class Team {
private static final Team pub = new Team(0, "PUB", "Öffentlich", "8");
private Team(int teamId, String teamKuerzel, String teamName, String teamColor){
public Team(int teamId, String teamKuerzel, String teamName, String teamColor) {
this.teamId = teamId;
this.teamKuerzel = teamKuerzel;
this.teamName = teamName;
this.teamColor = teamColor;
}
private Team(ResultSet rs) throws SQLException {
this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"));
}
public static Team get(int id){
if(id == 0)
return pub;
return get.select(rs -> {
rs.next();
return new Team(rs);
}, id);
return Provider.impl.getTeam(id);
}
public int getTeamId() {
@ -73,11 +60,6 @@ public class Team {
}
public List<Integer> getMembers(){
return getMembers.select(rs -> {
List<Integer> members = new ArrayList<>();
while(rs.next())
members.add(rs.getInt("id"));
return members;
}, teamId);
return Provider.impl.getTeamMembers(this);
}
}

Datei anzeigen

@ -1,54 +0,0 @@
/*
* 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.sql;
import java.sql.ResultSet;
import java.util.HashSet;
import java.util.Set;
public class TeamTeilnahme {
private TeamTeilnahme(){}
private static final Statement byEventTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?");
private static final Statement byEvent = new Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?");
private static final Statement byTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?");
public static boolean nimmtTeil(int teamID, int eventID){
return byEventTeam.select(ResultSet::next, teamID, eventID);
}
public static Set<Team> getTeams(int eventID){
return byEvent.select(rs -> {
Set<Team> teams = new HashSet<>();
while(rs.next())
teams.add(Team.get(rs.getInt("TeamID")));
return teams;
}, eventID);
}
public static Set<Event> getEvents(int teamID){
return byTeam.select(rs -> {
Set<Event> events = new HashSet<>();
while(rs.next())
events.add(Event.get(rs.getInt("EventID")));
return events;
}, teamID);
}
}

Datei anzeigen

@ -24,20 +24,12 @@ import java.util.UUID;
public class UserConfig {
private UserConfig() {}
private static final Statement get = new Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?");
private static final Statement set = new Statement("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)");
private static final Statement delete = new Statement("DELETE FROM UserConfig WHERE User = ? AND Config = ?");
public static String getConfig(UUID player, String config) {
return getConfig(SteamwarUser.get(player).getId(), config);
}
public static String getConfig(int player, String config) {
return get.select(rs -> {
if(rs.next())
return rs.getString("Value");
return null;
}, player, config);
return Provider.impl.getConfig(player, config);
}
public static void updatePlayerConfig(UUID uuid, String config, String value) {
@ -49,7 +41,7 @@ public class UserConfig {
removePlayerConfig(id, config);
return;
}
set.update(id, config, value);
Provider.impl.updatePlayerConfig(id, config, value);
}
public static void removePlayerConfig(UUID uuid, String config) {
@ -57,6 +49,6 @@ public class UserConfig {
}
public static void removePlayerConfig(int id, String config) {
delete.update(id, config);
Provider.impl.removePlayerConfig(id, config);
}
}