From 08afee6f380156271b671f011d96889aad0dd139 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 2 Apr 2026 10:05:35 +0200 Subject: [PATCH] Add SettingsCommand --- .../SQL/src/de/steamwar/sql/SteamwarUser.kt | 21 +++++- CommonCore/SQL/src/de/steamwar/sql/Team.kt | 2 + .../steamwar/messages/BungeeCore.properties | 13 ++++ .../messages/BungeeCore_de.properties | 2 + .../commands/SetLocaleCommand.java | 41 ---------- .../commands/SettingsCommand.java | 74 +++++++++++++++++++ .../velocitycore/commands/TeamCommand.java | 14 ++-- .../listeners/SettingsChangedListener.java | 2 +- 8 files changed, 117 insertions(+), 52 deletions(-) delete mode 100644 VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java create mode 100644 VelocityCore/src/de/steamwar/velocitycore/commands/SettingsCommand.java diff --git a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.kt b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.kt index b135ab97..6b459a93 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.kt @@ -254,12 +254,27 @@ class SteamwarUser(id: EntityID): IntEntity(id) { punishments[punishment] = Punishment.createPunishment(this@SteamwarUser.id.value, from, punishment, reason, time, perma) } - fun setLocale(locale: Locale?, manualeLocale: Boolean) { - if (locale == null || (this.manualLocale && !manualLocale)) return + fun setJoinLocale(locale: Locale?) { + if (locale == null || this.manualLocale) return + setCurrentLocale(locale) + } + fun setCurrentLocale(locale: Locale?) { + if (locale == null) return useDb { this@SteamwarUser.locale = locale - this@SteamwarUser.manualLocale = manualeLocale + } + } + + fun lockLocale() { + useDb { + this@SteamwarUser.manualLocale = true + } + } + + fun unlockLocale() { + useDb { + this@SteamwarUser.manualLocale = false } } diff --git a/CommonCore/SQL/src/de/steamwar/sql/Team.kt b/CommonCore/SQL/src/de/steamwar/sql/Team.kt index 66614ad2..b0c3febc 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Team.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/Team.kt @@ -36,6 +36,8 @@ object TeamTable : IntIdTable("Team", "TeamID") { class Team(id: EntityID) : IntEntity(id) { companion object : IntEntityClass(TeamTable) { + const val PUBLIC: Int = 0 + private val teamCache = mutableMapOf() @JvmStatic diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 5e619e84..734b00c2 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -17,6 +17,19 @@ # along with this program. If not, see . # +LOCALE = English + +SETTINGS_TITLE = Settings +SETTINGS_LOCALE_ITEM = §fLocale +SETTINGS_LOCALE_CURRENT = §fCurrent locale §e{0}§8. +SETTINGS_LOCALE_LOCKED = §cLocked§f to the current locale§8. +SETTINGS_LOCALE_UNLOCKED = §aChanged§f by Client locale§8. +SETTINGS_PREFIX_ITEM = §fChat prefix +SETTINGS_PREFIX_SELECTED = §a> {0} +SETTINGS_PREFIX_UNSELECTED = §f> {0} +SETTINGS_PREFIX_SW = §eS§8W +SETTINGS_PREFIX_TEAM = §{0}{1} + COMMAND_SYSTEM_ERROR = §cError executing the command! COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===--- diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index ed0edfc4..bf832786 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -17,6 +17,8 @@ # along with this program. If not, see . # +LOCALE = Deutsch + COMMAND_SYSTEM_ERROR = §cFehler beim Ausführen des Befehls! PREFIX=§eSteam§8War» diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java deleted file mode 100644 index 34eefff7..00000000 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 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.velocitycore.commands; - -import de.steamwar.command.SWCommand; -import de.steamwar.linkage.Linked; -import de.steamwar.messages.PlayerChatter; -import de.steamwar.network.packets.server.LocaleInvalidationPacket; -import de.steamwar.velocitycore.network.NetworkSender; - -@Linked -public class SetLocaleCommand extends SWCommand { - - public SetLocaleCommand() { - super("setlocale", "setlanguage"); - } - - @Register - public void genericCommand(PlayerChatter sender) { - sender.user().setLocale(sender.getPlayer().getPlayerSettings().getLocale(), true); - sender.withPlayer(player -> NetworkSender.send(player, new LocaleInvalidationPacket(sender.user().getId()))); - sender.system("LOCK_LOCALE_CHANGED"); - } -} diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/SettingsCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/SettingsCommand.java new file mode 100644 index 00000000..4df7c388 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/SettingsCommand.java @@ -0,0 +1,74 @@ +/* + * 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 . + */ + +package de.steamwar.velocitycore.commands; + +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import de.steamwar.messages.Message; +import de.steamwar.messages.PlayerChatter; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.Team; +import de.steamwar.sql.UserPerm; +import de.steamwar.velocitycore.inventory.SWInventory; +import de.steamwar.velocitycore.inventory.SWItem; + +@Linked +public class SettingsCommand extends SWCommand { + + public SettingsCommand() { + super("settings"); + } + + @Register + public void genericCommand(PlayerChatter sender) { + SWInventory inventory = new SWInventory(sender, 9, new Message("SETTINGS_TITLE")); + SteamwarUser user = sender.user(); + String localeItem = user.getManualLocale() ? "BOOK" : "BOOK_AND_QUILL"; + SWItem localeSwItem = new SWItem(localeItem, new Message("SETTINGS_LOCALE_ITEM")); + localeSwItem.addLore(new Message("SETTINGS_LOCALE_CURRENT", new Message("LOCALE"))); + if (user.getManualLocale()) { + localeSwItem.addLore(new Message("SETTINGS_LOCALE_LOCKED")); + } else { + localeSwItem.addLore(new Message("SETTINGS_LOCALE_UNLOCKED")); + } + inventory.addItem(2, localeSwItem, click -> { + if (user.getManualLocale()) { + user.unlockLocale(); + } else { + user.lockLocale(); + } + genericCommand(sender); + }); + + Team team = Team.byId(user.getTeam()); + String chatPrefixItem = !user.hasPerm(UserPerm.TEAM) ? "BARRIER" : "NAME_TAG"; + SWItem swItem = new SWItem(chatPrefixItem, new Message("SETTINGS_PREFIX_ITEM")); + if (user.hasPerm(UserPerm.TEAM)) { + swItem.addLore(new Message("SETTINGS_PREFIX_SELECTED", new Message("SETTINGS_PREFIX_SW"))); + } + if (user.getTeam() != Team.PUBLIC) { + swItem.addLore(new Message("SETTINGS_PREFIX_UNSELECTED", new Message("SETTINGS_PREFIX_TEAM", team.getTeamColor(), team.getTeamKuerzel()))); + } + inventory.addItem(6, swItem, click -> { + }); + + inventory.open(); + } +} diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java index 16270087..c0981c24 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/TeamCommand.java @@ -60,7 +60,7 @@ public class TeamCommand extends SWCommand { helpMessages(sender, "TEAM_HELP_HEADER", "TEAM_HELP_LIST", "TEAM_HELP_INFO"); SteamwarUser user = sender.user(); - if(user.getTeam() == 0) { + if(user.getTeam() == Team.PUBLIC) { helpMessages(sender, "TEAM_HELP_CREATE", "TEAM_HELP_JOIN"); }else{ helpMessages(sender, "TEAM_HELP_CHAT", "TEAM_HELP_EVENT", "TEAM_HELP_LEAVE"); @@ -162,7 +162,7 @@ public class TeamCommand extends SWCommand { return; } - user.setTeam(0); + user.setTeam(Team.PUBLIC); if(teamSize == 1) team.disband(user); @@ -182,7 +182,7 @@ public class TeamCommand extends SWCommand { if(notDuringEvent(sender)) return; - if(target.getTeam() != 0){ + if(target.getTeam() != Team.PUBLIC){ sender.system("TEAM_INVITE_IN_TEAM"); return; } @@ -218,7 +218,7 @@ public class TeamCommand extends SWCommand { return; } - target.setTeam(0); + target.setTeam(Team.PUBLIC); sender.system("TEAM_REMOVE_REMOVED"); Chatter.of(target).system("TEAM_REMOVE_REMOVED_TARGET"); @@ -493,7 +493,7 @@ public class TeamCommand extends SWCommand { @Validator(value = "isNotInTeam", local = true) public TypeValidator isNotInTeamValidator() { return (sender, value, messageSender) -> { - if (sender.user().getTeam() != 0) { + if (sender.user().getTeam() != Team.PUBLIC) { messageSender.send("TEAM_IN_TEAM"); return false; } @@ -504,7 +504,7 @@ public class TeamCommand extends SWCommand { @Validator(value = "isInTeam", local = true) public TypeValidator isInTeamValidator() { return (sender, value, messageSender) -> { - if (sender.user().getTeam() == 0) { + if (sender.user().getTeam() == Team.PUBLIC) { messageSender.send("TEAM_NOT_IN_TEAM"); return false; } @@ -516,7 +516,7 @@ public class TeamCommand extends SWCommand { public TypeValidator isLeaderValidator() { return (sender, value, messageSender) -> { SteamwarUser user = sender.user(); - if (user.getTeam() == 0) { + if (user.getTeam() == Team.PUBLIC) { messageSender.send("TEAM_NOT_IN_TEAM"); return false; } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/SettingsChangedListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/SettingsChangedListener.java index 49367da6..c4bea322 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/SettingsChangedListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/SettingsChangedListener.java @@ -36,7 +36,7 @@ public class SettingsChangedListener extends BasicListener { VelocityCore.schedule(() -> { Player player = event.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - user.setLocale(event.getPlayerSettings().getLocale(), false); + user.setJoinLocale(event.getPlayerSettings().getLocale()); NetworkSender.send(player, new LocaleInvalidationPacket(user.getId())); }).schedule(); }