Hotfix SWUser Init
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-02-23 17:20:21 +01:00
Ursprung 95b46f3a9a
Commit 3778d6c1f9

Datei anzeigen

@ -81,27 +81,27 @@ public class SteamwarUser {
SteamwarUser user = usersByName.get(userName.toLowerCase()); SteamwarUser user = usersByName.get(userName.toLowerCase());
if(user != null) if(user != null)
return user; return user;
return byName.select(userName); return loadPunishments(byName.select(userName));
} }
public static SteamwarUser get(UUID uuid){ public static SteamwarUser get(UUID uuid){
SteamwarUser user = usersByUUID.get(uuid); SteamwarUser user = usersByUUID.get(uuid);
if(user != null) if(user != null)
return user; return user;
return byUUID.select(uuid); return loadPunishments(byUUID.select(uuid));
} }
public static SteamwarUser get(int id) { public static SteamwarUser get(int id) {
SteamwarUser user = usersById.get(id); SteamwarUser user = usersById.get(id);
if(user != null) if(user != null)
return user; return user;
return byID.select(id); return loadPunishments(byID.select(id));
} }
public static SteamwarUser get(Long discordId) { public static SteamwarUser get(Long discordId) {
if(usersByDiscord.containsKey(discordId)) if(usersByDiscord.containsKey(discordId))
return usersByDiscord.get(discordId); return usersByDiscord.get(discordId);
return byDiscord.select(discordId); return loadPunishments(byDiscord.select(discordId));
} }
public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer<UUID> newPlayer, BiConsumer<String, String> nameUpdate) { public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer<UUID> newPlayer, BiConsumer<String, String> nameUpdate) {
@ -123,11 +123,11 @@ public class SteamwarUser {
} }
public static List<SteamwarUser> getServerTeam() { public static List<SteamwarUser> getServerTeam() {
return getServerTeam.listSelect(); return loadPunishments(getServerTeam.listSelect());
} }
public static List<SteamwarUser> getTeam(int teamId) { public static List<SteamwarUser> getTeam(int teamId) {
return byTeam.listSelect(teamId); return loadPunishments(byTeam.listSelect(teamId));
} }
public static void batchCache(Set<Integer> ids) { public static void batchCache(Set<Integer> ids) {
@ -140,6 +140,16 @@ public class SteamwarUser {
} }
} }
private static List<SteamwarUser> loadPunishments(List<SteamwarUser> users) {
users.forEach(user -> user.punishments = Punishment.getPunishmentsOfPlayer(user.getId()));
return users;
}
private static SteamwarUser loadPunishments(SteamwarUser user) {
user.punishments = Punishment.getPunishmentsOfPlayer(user.getId());
return user;
}
@Getter @Getter
@Field(keys = {Table.PRIMARY}, autoincrement = true) @Field(keys = {Table.PRIMARY}, autoincrement = true)
private final int id; private final int id;
@ -165,7 +175,7 @@ public class SteamwarUser {
@Field(keys = {"discordId"}, nullable = true) @Field(keys = {"discordId"}, nullable = true)
private Long discordId; private Long discordId;
private final Map<Punishment.PunishmentType, Punishment> punishments; private Map<Punishment.PunishmentType, Punishment> punishments;
public SteamwarUser(int id, UUID uuid, String userName, UserGroup userGroup, int team, boolean leader, Locale locale, boolean manualLocale, Long discordId) { public SteamwarUser(int id, UUID uuid, String userName, UserGroup userGroup, int team, boolean leader, Locale locale, boolean manualLocale, Long discordId) {
this.id = id; this.id = id;
@ -184,7 +194,6 @@ public class SteamwarUser {
if (this.discordId != null) { if (this.discordId != null) {
usersByDiscord.put(discordId, this); usersByDiscord.put(discordId, this);
} }
punishments = Punishment.getPunishmentsOfPlayer(id); //TODO load always on Subservers?
} }
public UUID getUUID() { public UUID getUUID() {