forked from SteamWar/SteamWar
Merge pull request 'SW Prefix Implementation' (#383) from Jaki/SteamWar:main into main
Reviewed-on: SteamWar/SteamWar#383 Reviewed-by: YoyoNow <yoyonow@noreply.localhost>
This commit is contained in:
@@ -175,6 +175,9 @@ class SteamwarUser(id: EntityID<Int>) : IntEntity(id) {
|
||||
leaderInternal = false
|
||||
}
|
||||
|
||||
fun hasTeam() =
|
||||
team != 0
|
||||
|
||||
private var leaderInternal by SteamwarUserTable.leader
|
||||
var leader: Boolean
|
||||
get() = leaderInternal
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -493,6 +493,16 @@ TEAM_INFO_TEAM = §7Team §e{0} §8[§{1}{2}§8]
|
||||
TEAM_INFO_LEADER = §7Leader ({0})§8: {1}
|
||||
TEAM_INFO_MEMBER = §7Member ({0})§8: {1}
|
||||
TEAM_INFO_EVENTS = §7Events ({0})§8: §e{1}
|
||||
#Server Team
|
||||
TEAM_INFO_SW_USAGE = §8/§7team info §8[§eSW§8|§eSteamWar§8]
|
||||
TEAM_INFO_SW_HEADER = §eSteam§8War Server Team
|
||||
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 = §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
|
||||
|
||||
@@ -465,6 +465,15 @@ TEAM_INFO_TEAM = §7Team §e{0} §8[§{1}{2}§8]
|
||||
TEAM_INFO_LEADER = §7Leader ({0})§8: {1}
|
||||
TEAM_INFO_MEMBER = §7Member ({0})§8: {1}
|
||||
TEAM_INFO_EVENTS = §7Events ({0})§8: §e{1}
|
||||
#Server Team
|
||||
TEAM_INFO_SW_USAGE = §8/§7team info §8[§eSW§8|§eSteamWar§8]
|
||||
TEAM_INFO_SW_HEADER = §eSteam§8War Serverteam
|
||||
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 = §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();
|
||||
|
||||
@@ -27,14 +27,12 @@ import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.messages.Chatter;
|
||||
import de.steamwar.messages.Message;
|
||||
import de.steamwar.messages.PlayerChatter;
|
||||
import de.steamwar.sql.Event;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.Team;
|
||||
import de.steamwar.sql.TeamTeilnahme;
|
||||
import de.steamwar.sql.*;
|
||||
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;
|
||||
@@ -51,6 +49,9 @@ import static de.steamwar.persistent.Storage.teamInvitations;
|
||||
@Linked
|
||||
public class TeamCommand extends SWCommand {
|
||||
|
||||
public static final String STEAM_WAR = "SteamWar";
|
||||
public static final String SW = "SW";
|
||||
|
||||
public TeamCommand() {
|
||||
super("team");
|
||||
}
|
||||
@@ -324,26 +325,63 @@ public class TeamCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Register(value = "info", description = "TEAM_INFO_SW_USAGE")
|
||||
public void infoServerTeam(Chatter sender, @StaticValue({SW, STEAM_WAR}) String __) {
|
||||
sender.system("TEAM_INFO_SW_HEADER");
|
||||
|
||||
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(),
|
||||
entry.getKey().size(), memberList);
|
||||
});
|
||||
}
|
||||
|
||||
private String getMemberList(List<SteamwarUser> users, boolean leaders) {
|
||||
return users.stream()
|
||||
.filter(user -> user.isLeader() == leaders)
|
||||
.map(user -> {
|
||||
StringBuilder st = new StringBuilder();
|
||||
if (VelocityCore.getProxy().getPlayer(user.getUUID()).isPresent()) {
|
||||
if (!StreamingCommand.isNotStreaming(user)) {
|
||||
st.append("§5");
|
||||
} else {
|
||||
st.append("§a");
|
||||
return getMemberList(users.stream().filter(u -> u.isLeader() == leaders));
|
||||
}
|
||||
} else {
|
||||
st.append("§e");
|
||||
}
|
||||
st.append(user.getUserName());
|
||||
return st.toString();
|
||||
})
|
||||
|
||||
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 "§e"; // Offline
|
||||
}
|
||||
|
||||
@Register(value = "prefix", description = "TEAM_PREFIX_USAGE")
|
||||
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, @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(value = "canUseTeamPrefix", local = true)
|
||||
public TypeValidator<Chatter> canUseTeamPrefixValidator() {
|
||||
return (sender, value, messageSender) -> {
|
||||
SteamwarUser user = value.user();
|
||||
|
||||
return user.hasPerm(UserPerm.TEAM)
|
||||
&& user.getTeam() != 0
|
||||
&& user.prefix() != UserPerm.emptyPrefix;
|
||||
};
|
||||
}
|
||||
|
||||
@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;
|
||||
@@ -532,6 +570,9 @@ public class TeamCommand extends SWCommand {
|
||||
return new TypeMapper<Team>() {
|
||||
@Override
|
||||
public Team map(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
if ((s.equalsIgnoreCase(SW) || s.equalsIgnoreCase(STEAM_WAR))) {
|
||||
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;
|
||||
@@ -176,19 +177,21 @@ public class ChatListener extends BasicListener {
|
||||
final String coloredMessage = user.hasPerm(UserPerm.COLOR_CHAT) ? message.replace('&', '§') : message;
|
||||
if (chatFilter(sender, coloredMessage)) return;
|
||||
|
||||
boolean useSwPrefix = useSwPrefix(user);
|
||||
|
||||
boolean noReceiver = true;
|
||||
for (Chatter player : receivers.getChatters()) {
|
||||
if (player.chatShown()) {
|
||||
chatToReciever(player, msgReceiver, user, format, coloredMessage);
|
||||
chatToReciever(player, msgReceiver, user, format, coloredMessage, useSwPrefix);
|
||||
if (sender.user().getId() != player.user().getId()) noReceiver = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (format.equals("CHAT_GLOBAL")) {
|
||||
DiscordBot.withBot(bot -> chatToReciever(bot.getIngameChat(), msgReceiver, user, format, coloredMessage));
|
||||
DiscordBot.withBot(bot -> chatToReciever(bot.getIngameChat(), msgReceiver, user, format, coloredMessage, useSwPrefix));
|
||||
} else if (format.equals("CHAT_SERVERTEAM")) {
|
||||
DiscordBot.withBot(bot -> chatToReciever(bot.getServerTeamChat(), msgReceiver, user, "CHAT_GLOBAL", coloredMessage));
|
||||
DiscordBot.withBot(bot -> chatToReciever(bot.getServerTeamChat(), msgReceiver, user, "CHAT_GLOBAL", coloredMessage, useSwPrefix));
|
||||
} else if (noReceiver) {
|
||||
sender.system("CHAT_NO_RECEIVER");
|
||||
}
|
||||
@@ -239,20 +242,45 @@ public class ChatListener extends BasicListener {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void chatToReciever(Chatter receiver, Chatter msgReceiver, SteamwarUser sender, String format, String message) {
|
||||
private static void chatToReciever(Chatter receiver, Chatter msgReceiver, SteamwarUser sender, String format, String message, boolean useSwPrefix) {
|
||||
UserPerm.Prefix prefix = sender.prefix();
|
||||
|
||||
String teamPrefix = "";
|
||||
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() + " ";
|
||||
}
|
||||
|
||||
String chatColorCode = sender.hasPerm(UserPerm.TEAM) ? "§f" : "§7";
|
||||
receiver.prefixless(format,
|
||||
sender,
|
||||
msgReceiver == null ? receiver : msgReceiver,
|
||||
highlightMentions(message, chatColorCode, receiver),
|
||||
sender.getTeam() == 0 ? "" : "§" + Team.byId(sender.getTeam()).getTeamColor() + Team.byId(sender.getTeam()).getTeamKuerzel() + " ",
|
||||
teamPrefix,
|
||||
"",
|
||||
prefix.getColorCode(),
|
||||
prefix == UserPerm.emptyPrefix ? "§f" : prefix.getColorCode(),
|
||||
prefix.getChatPrefix().length() == 0 ? "§f" : prefix.getChatPrefix() + " ",
|
||||
chatColorCode);
|
||||
}
|
||||
|
||||
private static boolean useSwPrefix(SteamwarUser user) {
|
||||
if (!user.hasPerm(UserPerm.TEAM)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UserPerm.Prefix prefix = user.prefix();
|
||||
|
||||
boolean hasTeamPrefix = user.getTeam() != 0;
|
||||
boolean hasSwPrefix = prefix != UserPerm.emptyPrefix;
|
||||
|
||||
if (!hasSwPrefix) return false;
|
||||
if (!hasTeamPrefix) return true;
|
||||
|
||||
return SteamwarPrefix.usesSWPrefix(user);
|
||||
}
|
||||
|
||||
private static boolean filteredCommand(Chatter sender, String message) {
|
||||
String command = message.split(" ", 2)[0];
|
||||
if (command.startsWith("/") && command.contains(":")) {
|
||||
|
||||
@@ -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