Updated UserPerms
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2023-08-29 17:46:46 +02:00
Ursprung 96d55a7ac6
Commit fc1e7c60d7
2 geänderte Dateien mit 39 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -169,6 +169,7 @@ public class SteamwarUser {
private Map<Punishment.PunishmentType, Punishment> punishments = null;
private Set<UserPerm> permissions = null;
private UserPerm.Prefix prefix = null;
public SteamwarUser(int id, UUID uuid, String userName, UserGroup userGroup, int team, boolean leader, Locale locale, boolean manualLocale, Long discordId) {
this.id = id;
@ -224,6 +225,16 @@ public class SteamwarUser {
return permissions.contains(perm);
}
public Set<UserPerm> perms() {
initPerms();
return permissions;
}
public UserPerm.Prefix prefix() {
initPerms();
return prefix;
}
public double getOnlinetime() {
return getPlaytime.select(rs -> {
if (rs.next() && rs.getBigDecimal("Playtime") != null)
@ -287,5 +298,6 @@ public class SteamwarUser {
return;
permissions = UserPerm.getPerms(id);
prefix = permissions.stream().filter(UserPerm.prefixes::containsKey).findAny().map(UserPerm.prefixes::get).orElse(UserPerm.emptyPrefix);
}
}

Datei anzeigen

@ -24,11 +24,13 @@ import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.SqlTypeMapper;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
public enum UserPerm {
PREFIX_NONE, // special value, not stored in database
PREFIX_YOUTUBER,
PREFIX_GUIDE,
PREFIX_BUILDER,
@ -37,13 +39,29 @@ public enum UserPerm {
PREFIX_DEVELOPER,
PREFIX_ADMIN,
RESTRICTED_MODS,
TEAM,
BUILD,
CHECK,
MODERATION;
MODERATION,
ADMINISTRATION;
public static final Map<UserPerm, Prefix> prefixes;
public static final Prefix emptyPrefix;
static {
SqlTypeMapper.nameEnumMapper(UserPerm.class);
Map<UserPerm, Prefix> p = new EnumMap<>(UserPerm.class);
emptyPrefix = new Prefix("§7", "");
p.put(PREFIX_NONE, emptyPrefix);
p.put(PREFIX_YOUTUBER, new Prefix("§5", "YT"));
p.put(PREFIX_GUIDE, new Prefix("§f", "Guide"));
p.put(PREFIX_BUILDER, new Prefix("§2", "Arch"));
p.put(PREFIX_SUPPORTER, new Prefix("§9", "Sup"));
p.put(PREFIX_MODERATOR, new Prefix("§6", "Mod"));
p.put(PREFIX_DEVELOPER, new Prefix("§b", "Dev"));
p.put(PREFIX_ADMIN, new Prefix("§4", "Admin"));
prefixes = Collections.unmodifiableMap(p);
}
private static final Table<UserPermTable> table = new Table<>(UserPermTable.class, "UserPerm");
@ -53,6 +71,13 @@ public enum UserPerm {
return getPerms.listSelect(user).stream().map(up -> up.perm).collect(Collectors.toSet());
}
@Getter
@AllArgsConstructor
public static class Prefix {
private final String colorCode;
private final String chatPrefix;
}
@AllArgsConstructor
private static class UserPermTable {
@Field(keys = {Table.PRIMARY})