/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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 .
*/
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 lombok.AllArgsConstructor;
import lombok.Getter;
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,
PREFIX_SUPPORTER,
PREFIX_MODERATOR,
PREFIX_DEVELOPER,
PREFIX_ADMIN,
RESTRICTED_MODS,
COLOR_CHAT,
TEAM,
TICKET_LOG,
BUILD,
CHECK,
MODERATION,
ADMINISTRATION;
public static final Map prefixes;
public static final Prefix emptyPrefix;
static {
SqlTypeMapper.nameEnumMapper(UserPerm.class);
Map p = new EnumMap<>(UserPerm.class);
emptyPrefix = new Prefix("§7", "");
p.put(PREFIX_NONE, emptyPrefix);
p.put(PREFIX_YOUTUBER, new Prefix("§7", "YT"));
p.put(PREFIX_GUIDE, new Prefix("§a", "Guide"));
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);
}
private static final Table table = new Table<>(UserPermTable.class, "UserPerm");
private static final SelectStatement getPerms = table.selectFields("user");
public static Set getPerms(int user) {
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
public static class UserPermTable {
@Field(keys = {Table.PRIMARY})
private final int user;
@Field(keys = {Table.PRIMARY})
private final UserPerm perm;
}
}