forked from SteamWar/SteamWar
refactor team prefix handling and improve configuration parsing
This commit is contained in:
@@ -63,11 +63,11 @@ enum class UserPerm {
|
||||
PREFIX_NONE to emptyPrefix,
|
||||
PREFIX_YOUTUBER to Prefix("§x§8§A§2§B§E§5", "CC"), // 8A2BE5
|
||||
PREFIX_GUIDE to Prefix("§x§e§7§6§2§e§d", "Guide"), // E762ED
|
||||
PREFIX_SUPPORTER to Prefix("§x§6§0§9§5§F§B", "Sup"), // 6095FB
|
||||
PREFIX_MODERATOR to Prefix("§x§F§F§A§2§5§C", "Mod"), // FFA25C
|
||||
PREFIX_BUILDER to Prefix("§x§6§0§F§F§6§A", "Arch"), // 60FF6A
|
||||
PREFIX_DEVELOPER to Prefix("§x§0§B§B§C§B§3", "Dev"), // 0BBCB3
|
||||
PREFIX_ADMIN to Prefix("§x§F§F§2§B§2§4", "Admin"), // FF2B24
|
||||
PREFIX_SUPPORTER to Prefix("§x§6§0§9§5§F§B", "Sup", true), // 6095FB
|
||||
PREFIX_MODERATOR to Prefix("§x§F§F§A§2§5§C", "Mod", true), // FFA25C
|
||||
PREFIX_BUILDER to Prefix("§x§6§0§F§F§6§A", "Arch", true), // 60FF6A
|
||||
PREFIX_DEVELOPER to Prefix("§x§0§B§B§C§B§3", "Dev", true), // 0BBCB3
|
||||
PREFIX_ADMIN to Prefix("§x§F§F§2§B§2§4", "Admin", true), // FF2B24
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
@@ -94,5 +94,5 @@ enum class UserPerm {
|
||||
}
|
||||
}
|
||||
|
||||
data class Prefix(val colorCode: String, val chatPrefix: String)
|
||||
data class Prefix(val colorCode: String, val chatPrefix: String, val teamPrefix: Boolean = false)
|
||||
}
|
||||
@@ -500,10 +500,9 @@ TEAM_INFO_SW_RANK = {0} §7({1})§8: {2}
|
||||
|
||||
#TEAM Prefix
|
||||
TEAM_PREFIX_USAGE = §8/§7team prefix §8[§eteam§8|§eSW§8]
|
||||
TEAM_PREFIX_CURRENT_TEAM = §7Current chat prefix§8: §eTeam
|
||||
TEAM_PREFIX_CURRENT_SW = §7Current chat prefix§8: §eSteamWar
|
||||
TEAM_PREFIX_SET_TEAM = §7Your chat prefix is now your §eteam prefix§7.
|
||||
TEAM_PREFIX_SET_SW = §7Your chat prefix is now your §eSteamWar prefix§7.
|
||||
TEAM_PREFIX_CURRENT = §7Current chat prefix§8: §e{0}
|
||||
TEAM_PREFIX_SET = §7Your chat prefix is now your §e{0} prefix§7.
|
||||
TEAM_PREFIX_TEAM = Team
|
||||
|
||||
#Team List
|
||||
TEAM_LIST_NOT_PAGE = §cNo page number entered
|
||||
|
||||
@@ -472,10 +472,8 @@ TEAM_INFO_SW_RANK = {0} §7({1})§8: {2}
|
||||
|
||||
#Team Prefix
|
||||
TEAM_PREFIX_USAGE = §8/§7team prefix §8[§eteam§8|§eSW§8]
|
||||
TEAM_PREFIX_CURRENT_TEAM = §7Aktueller Chatprefix§8: §eTeam
|
||||
TEAM_PREFIX_CURRENT_SW = §7Aktueller Chatprefix§8: §eSteamWar
|
||||
TEAM_PREFIX_SET_TEAM = §7Dein Chatprefix ist jetzt dein §eTeamprefix§7.
|
||||
TEAM_PREFIX_SET_SW = §7Dein Chatprefix ist jetzt dein §eSteamWar-Prefix§7.
|
||||
TEAM_PREFIX_CURRENT = §7Aktueller Chatprefix§8: §e{0}
|
||||
TEAM_PREFIX_SET = §7Dein Chatprefix ist jetzt dein §e{0}prefix§7.
|
||||
|
||||
#Team List
|
||||
TEAM_LIST_NOT_PAGE = §cKeine Seitenzahl angegeben
|
||||
|
||||
@@ -45,6 +45,7 @@ import de.steamwar.velocitycore.commands.TeamCommand;
|
||||
import de.steamwar.velocitycore.discord.DiscordBot;
|
||||
import de.steamwar.velocitycore.discord.DiscordConfig;
|
||||
import de.steamwar.velocitycore.listeners.BasicListener;
|
||||
import de.steamwar.velocitycore.util.SteamwarPrefix;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
@@ -185,6 +186,7 @@ public class VelocityCore implements ReloadablePlugin {
|
||||
schedule(() -> {
|
||||
SteamwarUser.clear();
|
||||
Team.clear();
|
||||
SteamwarPrefix.clearCache();
|
||||
}).repeat(1, TimeUnit.HOURS).schedule();
|
||||
|
||||
DiscordConfig discordConfig = DiscordConfig.load();
|
||||
|
||||
@@ -32,6 +32,7 @@ import de.steamwar.velocitycore.VelocityCore;
|
||||
import de.steamwar.velocitycore.discord.DiscordBot;
|
||||
import de.steamwar.velocitycore.inventory.SWItem;
|
||||
import de.steamwar.velocitycore.inventory.SWListInv;
|
||||
import de.steamwar.velocitycore.util.SteamwarPrefix;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
@@ -47,8 +48,9 @@ import static de.steamwar.persistent.Storage.teamInvitations;
|
||||
|
||||
@Linked
|
||||
public class TeamCommand extends SWCommand {
|
||||
private static final String PREFIX_MODE_CONFIG = "chatprefix";
|
||||
private static final String PREFIX_MODE_SW = "SW";
|
||||
|
||||
public static final String STEAM_WAR = "SteamWar";
|
||||
public static final String SW = "SW";
|
||||
|
||||
public TeamCommand() {
|
||||
super("team");
|
||||
@@ -324,64 +326,52 @@ public class TeamCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "info", description = "TEAM_INFO_SW_USAGE")
|
||||
public void infoServerTeam(Chatter sender, @Mapper(value = "SW_TEAM", local = true) String teamName) {
|
||||
public void infoServerTeam(Chatter sender, @StaticValue({SW, STEAM_WAR}) String __) {
|
||||
sender.system("TEAM_INFO_SW_HEADER");
|
||||
|
||||
UserPerm.prefixes.keySet().stream()
|
||||
.filter(rank -> rank != UserPerm.PREFIX_NONE && rank != UserPerm.PREFIX_YOUTUBER && rank != UserPerm.PREFIX_GUIDE)
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.forEach(rank -> {
|
||||
List<SteamwarUser> users = SteamwarUser.getUsersWithPerm(rank);
|
||||
if (!users.isEmpty()) {
|
||||
UserPerm.Prefix prefix = UserPerm.prefixes.get(rank);
|
||||
String memberList = getMemberList(users);
|
||||
UserPerm.prefixes.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().getTeamPrefix())
|
||||
.sorted(Map.Entry.<UserPerm, UserPerm.Prefix>comparingByKey().reversed())
|
||||
.map(entry -> Map.entry(SteamwarUser.getUsersWithPerm(entry.getKey()), entry.getValue()))
|
||||
.filter(entry -> !entry.getKey().isEmpty())
|
||||
.forEach(entry -> {
|
||||
UserPerm.Prefix prefix = entry.getValue();
|
||||
String memberList = getMemberList(entry.getKey().stream());
|
||||
sender.prefixless("TEAM_INFO_SW_RANK",
|
||||
prefix.getColorCode() + prefix.getChatPrefix(),
|
||||
users.size(), memberList);
|
||||
}
|
||||
entry.getKey().size(), memberList);
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isSWTeamName(String value) {
|
||||
return value != null && (value.equalsIgnoreCase("sw") || value.equalsIgnoreCase("steamwar"));
|
||||
}
|
||||
|
||||
private String getMemberList(List<SteamwarUser> users, boolean leaders) {
|
||||
return getMemberList(users.stream().filter(u -> u.isLeader() == leaders).toList());
|
||||
return getMemberList(users.stream().filter(u -> u.isLeader() == leaders));
|
||||
}
|
||||
|
||||
private String getMemberList(List<SteamwarUser> users) {
|
||||
return users.stream()
|
||||
.map(user -> getUserColor(user) + user.getUserName())
|
||||
private String getMemberList(Stream<SteamwarUser> users) {
|
||||
return users.map(user -> getUserColor(user) + user.getUserName())
|
||||
.collect(Collectors.joining("§8,§r "));
|
||||
}
|
||||
|
||||
private String getUserColor(SteamwarUser user) {
|
||||
if (VelocityCore.getProxy().getPlayer(user.getUUID()).isPresent()) {
|
||||
return StreamingCommand.isNotStreaming(user) ? /*Not Streaming*/ "§a" : /*Streaming*/ "§5";
|
||||
return StreamingCommand.isNotStreaming(user) ? /* Not Streaming */ "§a" : /* Streaming */ "§5";
|
||||
}
|
||||
// Offline
|
||||
return "§e";
|
||||
return "§e"; // Offline
|
||||
}
|
||||
|
||||
@Register(value = "prefix", description = "TEAM_PREFIX_USAGE")
|
||||
public void prefix(@Validator("canUseTeamPrefix") Chatter sender){
|
||||
boolean swPrefix = PREFIX_MODE_SW.equals(UserConfig.getConfig(sender.user().getId(), PREFIX_MODE_CONFIG));
|
||||
sender.system(swPrefix ? "TEAM_PREFIX_CURRENT_SW" : "TEAM_PREFIX_CURRENT_TEAM");
|
||||
public void prefix(@Validator("canUseTeamPrefix") Chatter sender) {
|
||||
boolean swPrefix = SteamwarPrefix.usesSWPrefix(sender.user());
|
||||
sender.system("TEAM_PREFIX_CURRENT", swPrefix ? STEAM_WAR : sender.parse("TEAM_PREFIX_TEAM"));
|
||||
}
|
||||
|
||||
@Register(value = "prefix", description = "TEAM_PREFIX_USAGE")
|
||||
public void prefix(@Validator("canUseTeamPrefix") Chatter sender, PrefixMode mode) {
|
||||
if (mode == PrefixMode.SW) {
|
||||
UserConfig.updatePlayerConfig(sender.user().getId(), PREFIX_MODE_CONFIG, PREFIX_MODE_SW);
|
||||
sender.system("TEAM_PREFIX_SET_SW");
|
||||
} else {
|
||||
UserConfig.updatePlayerConfig(sender.user().getId(), PREFIX_MODE_CONFIG, null);
|
||||
sender.system("TEAM_PREFIX_SET_TEAM");
|
||||
}
|
||||
public void prefix(@Validator("canUseTeamPrefix") Chatter sender, @StaticValue(value = {SW, STEAM_WAR, "Team"}, falseValues = {2}) boolean useSWTeamTag) {
|
||||
SteamwarPrefix.setSWPrefix(sender.user(), useSWTeamTag);
|
||||
sender.system("TEAM_PREFIX_SET", useSWTeamTag ? STEAM_WAR : sender.parse("TEAM_PREFIX_TEAM"));
|
||||
}
|
||||
|
||||
@Validator("canUseTeamPrefix")
|
||||
@Validator(value = "canUseTeamPrefix", local = true)
|
||||
public TypeValidator<Chatter> canUseTeamPrefixValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
SteamwarUser user = value.user();
|
||||
@@ -392,11 +382,6 @@ public class TeamCommand extends SWCommand {
|
||||
};
|
||||
}
|
||||
|
||||
private enum PrefixMode {
|
||||
TEAM,
|
||||
SW
|
||||
}
|
||||
|
||||
@Register("list")
|
||||
public void list(Chatter sender, @Min(intValue = 1) @OptionalValue("1") @ErrorMessage("TEAM_LIST_NOT_PAGE") int page) {
|
||||
final int TEAMS_PER_PAGE = 10;
|
||||
@@ -579,28 +564,13 @@ public class TeamCommand extends SWCommand {
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper(value = "SW_TEAM", local = true)
|
||||
public TypeMapper<String> swTeam() {
|
||||
return new TypeMapper<String>() {
|
||||
@Override
|
||||
public String map(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
return isSWTeamName(s) ? s : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
return List.of("SW", "SteamWar");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ClassMapper(Team.class)
|
||||
@Cached(global = true, cacheDuration = 60)
|
||||
public TypeMapper<Team> team() {
|
||||
return new TypeMapper<Team>() {
|
||||
@Override
|
||||
public Team map(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
if (isSWTeamName(s)) {
|
||||
if ((s.equalsIgnoreCase("sw") || s.equalsIgnoreCase("steamwar"))) {
|
||||
return null;
|
||||
}
|
||||
return Team.get(s);
|
||||
|
||||
@@ -42,6 +42,7 @@ import de.steamwar.velocitycore.VelocityCore;
|
||||
import de.steamwar.velocitycore.commands.PunishmentCommand;
|
||||
import de.steamwar.velocitycore.discord.DiscordBot;
|
||||
import de.steamwar.velocitycore.network.NetworkSender;
|
||||
import de.steamwar.velocitycore.util.SteamwarPrefix;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -60,9 +61,6 @@ public class ChatListener extends BasicListener {
|
||||
|
||||
private static final Set<String> noLogCommands = Set.of("webpw", "webpassword", "web");
|
||||
|
||||
private static final String PREFIX_MODE_CONFIG = "chatprefix";
|
||||
private static final String PREFIX_MODE_SW = "SW";
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void fixCommands(CommandExecuteEvent e) {
|
||||
String command = e.getCommand();
|
||||
@@ -248,18 +246,8 @@ public class ChatListener extends BasicListener {
|
||||
UserPerm.Prefix prefix = sender.prefix();
|
||||
|
||||
String teamPrefix = "";
|
||||
String swPrefix = prefix.getChatPrefix().length() == 0 ? "§f" : prefix.getChatPrefix() + " ";
|
||||
String nameColor = prefix == UserPerm.emptyPrefix ? "§f" : prefix.getColorCode();
|
||||
|
||||
if (sender.hasPerm(UserPerm.TEAM)) {
|
||||
swPrefix = "§f";
|
||||
|
||||
if (useSwPrefix) {
|
||||
swPrefix = "§eS§8W ";
|
||||
} else if (sender.getTeam() != 0) {
|
||||
Team team = Team.byId(sender.getTeam());
|
||||
teamPrefix = "§" + team.getTeamColor() + team.getTeamKuerzel() + " ";
|
||||
}
|
||||
if (sender.hasPerm(UserPerm.TEAM) && useSwPrefix) {
|
||||
teamPrefix = "§eS§8W ";
|
||||
} else if (sender.getTeam() != 0) {
|
||||
Team team = Team.byId(sender.getTeam());
|
||||
teamPrefix = "§" + team.getTeamColor() + team.getTeamKuerzel() + " ";
|
||||
@@ -272,8 +260,8 @@ public class ChatListener extends BasicListener {
|
||||
highlightMentions(message, chatColorCode, receiver),
|
||||
teamPrefix,
|
||||
"",
|
||||
nameColor,
|
||||
swPrefix,
|
||||
prefix == UserPerm.emptyPrefix ? "§f" : prefix.getColorCode(),
|
||||
prefix.getChatPrefix().length() == 0 ? "§f" : prefix.getChatPrefix() + " ",
|
||||
chatColorCode);
|
||||
}
|
||||
|
||||
@@ -290,7 +278,7 @@ public class ChatListener extends BasicListener {
|
||||
if (!hasSwPrefix) return false;
|
||||
if (!hasTeamPrefix) return true;
|
||||
|
||||
return PREFIX_MODE_SW.equals(UserConfig.getConfig(user.getId(), PREFIX_MODE_CONFIG));
|
||||
return SteamwarPrefix.usesSWPrefix(user);
|
||||
}
|
||||
|
||||
private static boolean filteredCommand(Chatter sender, String message) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.velocitycore.util;
|
||||
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class SteamwarPrefix {
|
||||
private static final String PREFIX_MODE_CONFIG = "chatprefix";
|
||||
private static final String PREFIX_MODE_SW = "SW";
|
||||
|
||||
private static final Map<SteamwarUser, Boolean> usesSwPrefix = new HashMap<>();
|
||||
|
||||
public static boolean usesSWPrefix(SteamwarUser user) {
|
||||
return usesSwPrefix.computeIfAbsent(user, u -> PREFIX_MODE_SW.equals(UserConfig.getConfig(u.getId(), PREFIX_MODE_CONFIG)));
|
||||
}
|
||||
|
||||
public static void setSWPrefix(SteamwarUser user, boolean preferSW) {
|
||||
UserConfig.updatePlayerConfig(user.getId(), PREFIX_MODE_CONFIG, preferSW ? PREFIX_MODE_SW : null);
|
||||
usesSwPrefix.put(user, preferSW);
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
usesSwPrefix.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user