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 Map<Punishment.PunishmentType, Punishment> punishments = null;
private Set<UserPerm> permissions = 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) { 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;
@ -224,6 +225,16 @@ public class SteamwarUser {
return permissions.contains(perm); return permissions.contains(perm);
} }
public Set<UserPerm> perms() {
initPerms();
return permissions;
}
public UserPerm.Prefix prefix() {
initPerms();
return prefix;
}
public double getOnlinetime() { public double getOnlinetime() {
return getPlaytime.select(rs -> { return getPlaytime.select(rs -> {
if (rs.next() && rs.getBigDecimal("Playtime") != null) if (rs.next() && rs.getBigDecimal("Playtime") != null)
@ -287,5 +298,6 @@ public class SteamwarUser {
return; return;
permissions = UserPerm.getPerms(id); 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.SqlTypeMapper;
import de.steamwar.sql.internal.Table; import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Set; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public enum UserPerm { public enum UserPerm {
PREFIX_NONE, // special value, not stored in database
PREFIX_YOUTUBER, PREFIX_YOUTUBER,
PREFIX_GUIDE, PREFIX_GUIDE,
PREFIX_BUILDER, PREFIX_BUILDER,
@ -37,13 +39,29 @@ public enum UserPerm {
PREFIX_DEVELOPER, PREFIX_DEVELOPER,
PREFIX_ADMIN, PREFIX_ADMIN,
RESTRICTED_MODS,
TEAM, TEAM,
BUILD, BUILD,
CHECK, CHECK,
MODERATION; MODERATION,
ADMINISTRATION;
public static final Map<UserPerm, Prefix> prefixes;
public static final Prefix emptyPrefix;
static { static {
SqlTypeMapper.nameEnumMapper(UserPerm.class); 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"); 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()); 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 @AllArgsConstructor
private static class UserPermTable { private static class UserPermTable {
@Field(keys = {Table.PRIMARY}) @Field(keys = {Table.PRIMARY})