Commits vergleichen

..

30 Commits

Autor SHA1 Nachricht Datum
e351352a29 Update CC
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2024-08-06 18:48:35 +02:00
076fa8ad78 Merge remote-tracking branch 'origin/master' into multitool/main
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
# Conflicts:
#	src/de/steamwar/sql/EventFight.java
#	src/de/steamwar/sql/Referee.java
2024-08-06 18:20:54 +02:00
ebbf314e6f Fix SteamWar user in Teamlist 2024-08-06 18:19:17 +02:00
d93b846c1f Add new Referee Stuff
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2024-03-15 22:38:53 +01:00
97e19990b5 Update CommonCore
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2024-03-14 22:26:54 +01:00
187c2ea292 Merge remote-tracking branch 'origin/master' into multitool/main
# Conflicts:
#	src/de/steamwar/sql/Event.java
#	src/de/steamwar/sql/EventFight.java
#	src/de/steamwar/sql/SteamwarUser.java
2024-03-14 22:20:56 +01:00
53d629970a Reorder Userperms
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2024-01-06 22:45:58 +01:00
a28c9b4e04 Merge branch 'multitool/public' into multitool/main
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-23 17:42:24 +01:00
69e2f9da6a Fix
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-23 17:42:16 +01:00
6aefb79e78 Add Login
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-23 17:04:10 +01:00
bf2af5b45b Merge branch 'passwords' into multitool/public
# Conflicts:
#	src/de/steamwar/sql/SteamwarUser.java
2023-12-17 17:23:30 +01:00
3dbbd70a80 Merge branch 'passwords' into multitool/public
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-17 16:39:08 +01:00
1755d5a99a Merge branch 'master' into multitool/public
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-12-11 18:37:17 +01:00
61985fb806 Updates
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-11-12 22:44:30 +01:00
fa04945595 Updates
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-11-03 20:30:29 +01:00
Chaoscaot
9b22e77f9b
Open to Public
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-09-06 23:07:32 +02:00
Chaoscaot
66fc131803
Update to UserPerms
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-08-30 00:56:27 +02:00
Chaoscaot
661b75db00
Merge branch 'master' into multitool/main
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-08-30 00:24:51 +02:00
Chaoscaot
c0bad2eb42
Merge remote-tracking branch 'origin/user-perm' into multitool/user-perm
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
# Conflicts:
#	src/de/steamwar/sql/SteamwarUser.java
2023-08-29 18:08:24 +02:00
Chaoscaot
e604991cfd
Merge branch 'master' into multitool
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2023-08-29 17:58:50 +02:00
Chaoscaot
02581ec36b Remove Punishments and Update
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-06-04 09:22:02 +02:00
Chaoscaot
3e064f7e4c Merge CommonCore Master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-04-10 12:58:17 +02:00
Chaoscaot
6c60cc3ce6 Merge branch 'master' into multitool
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
# Conflicts:
#	src/de/steamwar/sql/Event.java
#	src/de/steamwar/sql/EventFight.java
#	src/de/steamwar/sql/Mod.java
#	src/de/steamwar/sql/SteamwarUser.java
#	src/de/steamwar/sql/Team.java
2023-04-10 12:53:40 +02:00
Chaoscaot
4c136b45ca Update CommonCore 2023-01-15 16:50:19 +01:00
Chaoscaot
e9d7e9738c Merge remote-tracking branch 'origin/master' into multitool 2023-01-15 16:46:44 +01:00
Chaoscaot
975ebf4f33 Add Mod Routes
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2023-01-14 11:59:49 +01:00
Chaoscaot
4b5ea06616 Add return of ? team
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2022-12-30 19:08:20 +01:00
Chaoscaot
c98687a9d5 Some uncommited Stuff
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2022-12-30 18:37:18 +01:00
Chaoscaot
fdcd81d21e Add Fight Delete
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2022-12-24 14:38:17 +01:00
Chaoscaot
eef38de3c0 Changes for MultiTool
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2022-12-23 23:19:28 +01:00
14 geänderte Dateien mit 186 neuen und 188 gelöschten Zeilen

4
build.gradle Ausführbare Datei → Normale Datei
Datei anzeigen

@ -44,8 +44,8 @@ ext {
compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 17
targetCompatibility = 17
sourceSets {
main {

0
gradlew vendored Ausführbare Datei → Normale Datei
Datei anzeigen

Datei anzeigen

@ -21,12 +21,13 @@ package de.steamwar.sql;
import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;
@AllArgsConstructor
@ -40,60 +41,66 @@ public class Event {
private static final SelectStatement<Event> byCurrent = new SelectStatement<>(table, "SELECT * FROM Event WHERE Start < now() AND End > now()");
private static final SelectStatement<Event> byId = table.select(Table.PRIMARY);
private static final SelectStatement<Event> byName = table.select("eventName");
private static final SelectStatement<Event> byComing = new SelectStatement<>(table, "SELECT * FROM Event WHERE Start > now()");
private static final SelectStatement<Event> allShort = new SelectStatement<>(table, "SELECT * FROM Event");
private static final Statement create = table.insertFields(true, "eventName", "deadline", "start", "end", "maximumTeamMembers", "publicSchemsOnly");
private static final Statement update = table.update(Table.PRIMARY, "eventName", "deadline", "start", "end", "schemType", "maximumTeamMembers", "publicSchemsOnly");
private static final Statement delete = table.delete(Table.PRIMARY);
private static Event current = null;
public static Event get(){
if(current != null && current.now())
return current;
current = byCurrent.select();
return current;
}
public static Event get(int eventID){
return byId.select(eventID);
}
public static Event get(String eventName) {
return byName.select(eventName);
public static List<Event> getAllShort(){
return allShort.listSelect();
}
public static List<Event> getComing() {
return byComing.listSelect();
public static Event create(String eventName, Timestamp start, Timestamp end){
return get(create.insertGetKey(eventName, start, start, end, 5, false, false));
}
public static void delete(int eventID){
delete.update(eventID);
}
@Getter
@Field(keys = {Table.PRIMARY}, autoincrement = true)
private final int eventID;
@Setter
@Getter
@Field(keys = {"eventName"})
private final String eventName;
private String eventName;
@Setter
@Getter
@Field
private final Timestamp deadline;
private Timestamp deadline;
@Setter
@Getter
@Field
private final Timestamp start;
private Timestamp start;
@Setter
@Getter
@Field
private final Timestamp end;
private Timestamp end;
@Setter
@Getter
@Field
private final int maximumTeamMembers;
private int maximumTeamMembers;
@Setter
@Field(nullable = true)
private final SchematicType schemType;
private SchematicType schemType;
@Setter
@Field
private final boolean publicSchemsOnly;
private boolean publicSchemsOnly;
@Deprecated
@Field
private final boolean spectateSystem;
private boolean spectateSystem;
public boolean publicSchemsOnly() {
return publicSchemsOnly;
}
@Deprecated
public boolean spectateSystem(){
return spectateSystem;
}
@ -102,8 +109,12 @@ public class Event {
return schemType;
}
private boolean now() {
Instant now = Instant.now();
return now.isAfter(start.toInstant()) && now.isBefore(end.toInstant());
@Deprecated
public void setSpectateSystem(boolean spectateSystem) {
this.spectateSystem = spectateSystem;
}
public void update(){
update.update(eventName, deadline, start, end, schemType, maximumTeamMembers, publicSchemsOnly, eventID);
}
}

Datei anzeigen

@ -25,6 +25,10 @@ import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.sql.Timestamp;
import java.util.List;
import java.sql.Timestamp;
import java.util.*;
@ -32,7 +36,7 @@ import java.util.*;
import static java.time.temporal.ChronoUnit.SECONDS;
@AllArgsConstructor
public class EventFight implements Comparable<EventFight> {
public class EventFight {
private static final Table<EventFight> table = new Table<>(EventFight.class);
private static final SelectStatement<EventFight> byId = table.select(Table.PRIMARY);
@ -41,6 +45,10 @@ public class EventFight implements Comparable<EventFight> {
private static final Statement reschedule = table.update(Table.PRIMARY, "StartTime");
private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis");
private static final Statement setFight = table.update(Table.PRIMARY, "Fight");
private static final SelectStatement<EventFight> byEvent = table.selectFields("eventID");
private static final Statement update = table.update(Table.PRIMARY, "startTime", "spielModus", "map", "teamBlue", "teamRed", "spectatePort");
private static final Statement create = table.insertFields(true, "eventID", "startTime", "spielModus", "map", "teamBlue", "teamRed", "spectatePort", "kampfleiter");
private static final Statement delete = table.delete(Table.PRIMARY);
private static final Queue<EventFight> fights = new PriorityQueue<>();
@ -48,47 +56,49 @@ public class EventFight implements Comparable<EventFight> {
return byId.select(fightID);
}
public static void loadAllComingFights() {
fights.clear();
fights.addAll(allComing.listSelect());
public static EventFight create(int eventID, Timestamp startTime, String spielModus, String map, int teamBlue, int teamRed, Integer spectatePort) {
return EventFight.get(create.insertGetKey(eventID, startTime, spielModus, map, teamBlue, teamRed, spectatePort, 0));
}
public static List<EventFight> getEvent(int eventID) {
return event.listSelect(eventID);
}
public static Queue<EventFight> getFights() {
return fights;
public static List<EventFight> getFromEvent(int eventID) {
return byEvent.listSelect(eventID);
}
@Getter
@Field
private final int eventID;
private int eventID;
@Getter
@Field(keys = {Table.PRIMARY}, autoincrement = true)
private final int fightID;
private int fightID;
@Getter
@Setter
@Field
private Timestamp startTime;
@Getter
@Setter
@Field
private final String spielmodus;
private String spielModus;
@Getter
@Setter
@Field
private final String map;
private String map;
@Getter
@Setter
@Field
private final int teamBlue;
private int teamBlue;
@Getter
@Setter
@Field
private final int teamRed;
private int teamRed;
@Getter
@Setter
@Field
@Deprecated
private final int kampfleiter;
private int kampfleiter;
@Getter
@Field
private final int spectatePort;
@Setter
@Field(nullable = true)
private Integer spectatePort;
@Getter
@Field(def = "0")
private int ergebnis;
@ -120,17 +130,11 @@ public class EventFight implements Comparable<EventFight> {
return fightID;
}
@Override
public boolean equals(Object o){
if(o == null)
return false;
if(!(o instanceof EventFight))
return false;
return fightID == ((EventFight) o).fightID;
public void update() {
update.update(startTime, spielModus, map, teamBlue, teamRed, spectatePort, fightID);
}
@Override
public int compareTo(EventFight o) {
return startTime.compareTo(o.startTime);
public void delete() {
delete.update(fightID);
}
}

Datei anzeigen

@ -46,7 +46,6 @@ public class Fight {
fight.initPlayers(fightPlayers);
}
SteamwarUser.batchCache(fightPlayers.stream().map(FightPlayer::getUserID).collect(Collectors.toSet()));
return fights;
}

Datei anzeigen

@ -26,6 +26,7 @@ import lombok.Getter;
import java.util.List;
@AllArgsConstructor
@Getter
public class Mod {
static {
@ -34,46 +35,34 @@ public class Mod {
}
private static final Table<Mod> table = new Table<>(Mod.class, "Mods");
private static final SelectStatement<Mod> get = table.select(Table.PRIMARY);
private static final SelectStatement<Mod> findFirst = new SelectStatement<>(table, "SELECT * FROM Mods WHERE ModType = 0 LIMIT 1");
private static final SelectStatement<Mod> getPageOfType = new SelectStatement<>(table, "SELECT * FROM Mods WHERE ModType = ? ORDER BY ModName DESC LIMIT ?, ?");
private static final Statement insert = table.insert(Table.PRIMARY);
private static final Statement set = table.update(Table.PRIMARY, "ModType");
public static Mod get(String name, Platform platform) {
return get.select(platform, name);
private static final SelectStatement<Mod> select = table.select(Table.PRIMARY);
private static final SelectStatement<Mod> all = new SelectStatement(table, "SELECT * FROM Mods");
private static final SelectStatement<Mod> allUnklassified = new SelectStatement(table, "SELECT * FROM Mods WHERE modType = 0");
private static final Statement update = table.update(Table.PRIMARY, "modType");
public static Mod get(Platform platform, String name) {
return select.select(platform, name);
}
public static Mod getOrCreate(String name, Platform platform) {
Mod mod = get(name, platform);
if(mod != null)
return mod;
insert.update(platform, name);
return new Mod(platform, name, ModType.UNKLASSIFIED);
public static List<Mod> getAll() {
return all.listSelect();
}
public static List<Mod> getAllModsFiltered(int page, int elementsPerPage, Mod.ModType filter) {
return Mod.getPageOfType.listSelect(filter, page * elementsPerPage, elementsPerPage);
public static List<Mod> getAllUnklassified() {
return allUnklassified.listSelect();
}
public static Mod findFirstMod() {
return findFirst.select();
}
@Getter
@Field(keys = {Table.PRIMARY})
private final Platform platform;
@Getter
@Field(keys = {Table.PRIMARY})
private final String modName;
@Getter
@Field(def = "0")
private ModType modType;
public void setModType(Mod.ModType modType) {
set.update(modType, platform, modName);
public void setModType(ModType modType) {
this.modType = modType;
update.update(modType, platform, modName);
}
public enum Platform {

Datei anzeigen

@ -20,9 +20,11 @@
package de.steamwar.sql;
import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -30,13 +32,13 @@ import java.sql.Timestamp;
import java.time.Instant;
@AllArgsConstructor
@Getter
public class NodeDownload {
private static final char[] HEX = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
private static final String LINK_BASE = "https://steamwar.de/download.php?schem=";
private static final Table<NodeDownload> table = new Table<>(NodeDownload.class);
private static final Statement insert = table.insertFields("NodeId", "Link");
private static final SelectStatement<NodeDownload> select = table.selectFields("Link");
private static final SelectStatement<NodeDownload> getId = table.select(Table.PRIMARY);
private static final Statement delete = table.delete(Table.PRIMARY);
@Field(keys = {Table.PRIMARY})
private final int nodeId;
@ -45,25 +47,20 @@ public class NodeDownload {
@Field(def = "CURRENT_TIMESTAMP")
private final Timestamp timestamp;
public static String getLink(SchematicNode schem){
if(schem.isDir())
throw new SecurityException("Can not Download Directorys");
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
throw new SecurityException(e);
public static NodeDownload addCode(SchematicNode node, String link) {
insert.update(node.getId(), link);
return get(node.getId());
}
digest.reset();
digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes());
String hash = base16encode(digest.digest());
insert.update(schem.getId(), hash);
return LINK_BASE + hash;
public static NodeDownload get(int nodeId) {
return getId.select(nodeId);
}
public static String base16encode(byte[] byteArray) {
StringBuilder hexBuffer = new StringBuilder(byteArray.length * 2);
for (byte b : byteArray)
hexBuffer.append(HEX[(b >>> 4) & 0xF]).append(HEX[b & 0xF]);
return hexBuffer.toString();
public static NodeDownload get(String link) {
return select.select(link);
}
public void delete() {
delete.update(nodeId);
}
}

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.sql;
import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
@ -32,6 +33,16 @@ public class Referee {
private static final Table<Referee> table = new Table<>(Referee.class);
private static final SelectStatement<Referee> byEvent = table.selectFields("eventID");
private static final Statement insert = table.insertAll();
private static final Statement delete = table.delete("eventReferee");
public static void add(int eventID, int userID) {
insert.update(eventID, userID);
}
public static void remove(int eventID, int userID) {
delete.update(eventID, userID);
}
public static Set<Integer> get(int eventID) {
return byEvent.listSelect(eventID).stream().map(referee -> referee.userID).collect(Collectors.toSet());

Datei anzeigen

@ -384,7 +384,7 @@ public class SchematicNode {
public int getRank() {
if (isDir())
throw new SecurityException("Node is Directory");
return 0;
return nodeRank;
}
@ -401,7 +401,7 @@ public class SchematicNode {
public SchematicType getSchemtype() {
if (isDir())
throw new SecurityException("Is Directory");
return null;
return nodeType;
}
@ -443,8 +443,25 @@ public class SchematicNode {
return SchemElo.getElo(this, season);
}
public boolean accessibleByUser(int user) {
return NodeMember.getNodeMember(nodeId, user) != null;
public boolean accessibleByUser(SteamwarUser user) {
if (user.getId() == nodeOwner) {
return true;
}
if (parentNode == null) {
return NodeMember.getNodeMember(nodeId, user.getId()) != null;
}
SchematicNode parent = getParentNode();
while (parent != null) {
NodeMember member = NodeMember.getNodeMember(nodeId, user.getId());
if (member != null || (parent.getOwner() == user.getId() && parent.parentNode == null)) {
return true;
}
parent = parent.getParentNode();
}
return false;
}
public Set<NodeMember> getMembers() {
@ -506,6 +523,19 @@ public class SchematicNode {
return builder.toString();
}
public List<Map.Entry<String, Integer>> generateBreadcrumbsMap(SteamwarUser user) {
List<Map.Entry<String, Integer>> map = new ArrayList<>();
Optional<SchematicNode> currentNode = Optional.of(this);
if(currentNode.map(SchematicNode::isDir).orElse(false)) {
map.add(Map.entry(getName(), getId()));
}
while (currentNode.isPresent()) {
currentNode = currentNode.flatMap(schematicNode -> Optional.ofNullable(NodeMember.getNodeMember(schematicNode.getId(), effectiveOwner)).map(NodeMember::getParent).orElse(schematicNode.getOptionalParent())).map(SchematicNode::getSchematicNode);
currentNode.ifPresent(node -> map.add(0, Map.entry(node.getName(), node.getId())));
}
return map;
}
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
public static boolean invalidSchemName(String[] layers) {
for (String layer : layers) {

Datei anzeigen

@ -61,8 +61,9 @@ public class SteamwarUser {
private static final SelectStatement<SteamwarUser> byName = table.selectFields("UserName");
private static final SelectStatement<SteamwarUser> byDiscord = table.selectFields("DiscordId");
private static final SelectStatement<SteamwarUser> byTeam = table.selectFields("Team");
private static final SelectStatement<SteamwarUser> getServerTeam = new SelectStatement<>(table, "SELECT * FROM UserData WHERE UserGroup != 'Member' AND UserGroup != 'YouTuber'");
private static final SelectStatement<SteamwarUser> getUsersWithPerm = new SelectStatement<>(table, "SELECT S.* FROM UserData S JOIN UserPerm P ON S.id = P.User WHERE P.Perm = ?");
private static final SelectStatement<SteamwarUser> getAll = new SelectStatement<>(table, "SELECT * FROM UserData");
private static final Statement updateName = table.update(Table.PRIMARY, "UserName");
private static final Statement updatePassword = table.update(Table.PRIMARY, "Password");
private static final Statement updateLocale = table.update(Table.PRIMARY, "Locale", "ManualLocale");
@ -73,53 +74,26 @@ public class SteamwarUser {
private static final Statement getPlaytime = new Statement("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?");
private static final Statement getFirstjoin = new Statement("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?");
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
private static final Map<Long, SteamwarUser> usersByDiscord = new HashMap<>();
public static void clear() {
usersById.clear();
usersByName.clear();
usersByUUID.clear();
usersByDiscord.clear();
}
public static void invalidate(int userId) {
SteamwarUser user = usersById.remove(userId);
if (user == null)
return;
usersByName.remove(user.getUserName());
usersByUUID.remove(user.getUUID());
usersByDiscord.remove(user.getDiscordId());
}
public static SteamwarUser get(String userName){
SteamwarUser user = usersByName.get(userName.toLowerCase());
if(user != null)
return user;
return byName.select(userName);
}
public static SteamwarUser get(UUID uuid){
SteamwarUser user = usersByUUID.get(uuid);
if(user != null)
return user;
return byUUID.select(uuid);
}
public static SteamwarUser get(int id) {
SteamwarUser user = usersById.get(id);
if(user != null)
return user;
return byID.select(id);
}
public static SteamwarUser get(Long discordId) {
if(usersByDiscord.containsKey(discordId))
return usersByDiscord.get(discordId);
return byDiscord.select(discordId);
}
public static List<SteamwarUser> getAll() {
return getAll.listSelect();
}
public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer<UUID> newPlayer, BiConsumer<String, String> nameUpdate) {
SteamwarUser user = get(uuid);
@ -138,24 +112,14 @@ public class SteamwarUser {
}
}
public static List<SteamwarUser> getServerTeam() {
return getServerTeam.listSelect();
public static List<SteamwarUser> getUsersWithPerm(UserPerm perm) {
return getUsersWithPerm.listSelect(perm);
}
public static List<SteamwarUser> getTeam(int teamId) {
return byTeam.listSelect(teamId);
}
public static void batchCache(Set<Integer> ids) {
ids.removeIf(usersById::containsKey);
if(ids.isEmpty())
return;
try (SelectStatement<SteamwarUser> batch = new SelectStatement<>(table, "SELECT * FROM UserData WHERE id IN (" + ids.stream().map(Object::toString).collect(Collectors.joining(", ")) + ")")) {
batch.listSelect();
}
}
@Getter
@Field(keys = {Table.PRIMARY}, autoincrement = true)
private final int id;
@ -194,13 +158,6 @@ public class SteamwarUser {
this.locale = locale;
this.manualLocale = manualLocale;
this.discordId = discordId != null && discordId != 0 ? discordId : null;
usersById.put(id, this);
usersByName.put(userName.toLowerCase(), this);
usersByUUID.put(uuid, this);
if (this.discordId != null) {
usersByDiscord.put(discordId, this);
}
}
public UUID getUUID() {
@ -291,12 +248,8 @@ public class SteamwarUser {
}
public void setDiscordId(Long discordId) {
usersByDiscord.remove(this.discordId);
this.discordId = discordId;
updateDiscord.update(discordId, id);
if (discordId != null) {
usersByDiscord.put(discordId, this);
}
}
public void setPassword(String password) {

Datei anzeigen

@ -75,20 +75,15 @@ public class Team {
}
public static Team get(int id) {
return teamCache.computeIfAbsent(id, byId::select);
}
public static Team get(String name){
// No cache lookup due to low frequency use
name = name.toLowerCase();
return byName.select(name, name);
if(id == -1)
return new Team(-1, "?", "?", "8", "", 25565, false);
if(id == 0)
return new Team(0, "PUB", "Public", "8", "", 25565, false);
return byId.select(id);
}
public static List<Team> getAll() {
clear();
List<Team> teams = all.listSelect(false);
teams.forEach(team -> teamCache.put(team.getTeamId(), team));
return teams;
return all.listSelect();
}
public List<Integer> getMembers(){

Datei anzeigen

@ -44,7 +44,6 @@ public class Tutorial {
public static List<Tutorial> getPage(int page, int elementsPerPage, boolean released) {
List<Tutorial> tutorials = by_popularity.listSelect(released, page * elementsPerPage, elementsPerPage);
SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet()));
return tutorials;
}

Datei anzeigen

@ -19,10 +19,7 @@
package de.steamwar.sql;
import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.SqlTypeMapper;
import de.steamwar.sql.internal.Table;
import de.steamwar.sql.internal.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
@ -58,9 +55,9 @@ public enum UserPerm {
p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT"));
p.put(PREFIX_GUIDE, new Prefix("§a", "Guide"));
p.put(PREFIX_BUILDER, new Prefix("§e", "Arch"));
p.put(PREFIX_SUPPORTER, new Prefix("§6", "Sup"));
p.put(PREFIX_MODERATOR, new Prefix("§6", "Mod"));
p.put(PREFIX_BUILDER, new Prefix("§e", "Arch"));
p.put(PREFIX_DEVELOPER, new Prefix("§e", "Dev"));
p.put(PREFIX_ADMIN, new Prefix("§e", "Admin"));
prefixes = Collections.unmodifiableMap(p);
@ -68,16 +65,29 @@ public enum UserPerm {
private static final Table<UserPermTable> table = new Table<>(UserPermTable.class, "UserPerm");
private static final SelectStatement<UserPermTable> getPerms = table.selectFields("user");
private static final Statement addPerm = table.insertFields("user", "perm");
private static final Statement removePerm = table.delete(Table.PRIMARY);
public static Set<UserPerm> getPerms(int user) {
return getPerms.listSelect(user).stream().map(up -> up.perm).collect(Collectors.toSet());
}
public static void addPerm(SteamwarUser user, UserPerm perm) {
addPerm.update(user, perm);
}
public static void removePerm(SteamwarUser user, UserPerm perm) {
removePerm.update(user, perm);
}
@Getter
@AllArgsConstructor
public static class Prefix {
private static int ordinalCounter = 0;
private final String colorCode;
private final String chatPrefix;
private final int ordinal = ordinalCounter++;
}
@AllArgsConstructor

Datei anzeigen

@ -47,7 +47,7 @@ public class Statement implements AutoCloseable {
private static final boolean PRODUCTION_DATABASE;
static {
File file = new File(System.getProperty("user.home"), "mysql.properties");
File file = new File(System.getProperty("user.home"), "mysql.api.properties");
MYSQL_MODE = file.exists();
if(MYSQL_MODE) {