diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 2d8ad28..70f36e8 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -158,6 +158,7 @@ public class BungeeCore extends Plugin { new SessionManager(); new SpigotReceiver(); new TablistManager(); + new SettingsChangedListener(); getProxy().getScheduler().schedule(this, () -> { SteamwarUser.clearCache(); diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 95f6a89..36940fb 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -61,6 +61,14 @@ public class ConnectionListener extends BasicListener { ProxiedPlayer player = event.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (!user.isManualLocale()) { + Locale locale = player.getLocale(); + if (locale == null) { + locale = Locale.getDefault(); + } + user.setLocale(locale, false); + } + player.removeGroups("Admin", "team"); if(user.getUserGroup().isAdminGroup()) diff --git a/src/de/steamwar/bungeecore/listeners/SettingsChangedListener.java b/src/de/steamwar/bungeecore/listeners/SettingsChangedListener.java new file mode 100644 index 0000000..b0620eb --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/SettingsChangedListener.java @@ -0,0 +1,46 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.bungeecore.listeners; + +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.SettingsChangedEvent; +import net.md_5.bungee.event.EventHandler; + +import java.util.Locale; + +public class SettingsChangedListener extends BasicListener { + + @EventHandler + public void onSettingsChanged(SettingsChangedEvent event) { + ProxiedPlayer player = event.getPlayer(); + SteamwarUser steamwarUser = SteamwarUser.get(player); + + if (steamwarUser.isManualLocale()) + return; + + Locale locale = player.getLocale(); + if (locale == null) { + locale = Locale.getDefault(); + } + + steamwarUser.setLocale(locale, false); + } +} diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 6bb88e5..6ca6b9e 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -389,9 +389,13 @@ public class SteamwarUser { } public void setLocale(Locale locale, boolean manualLocale) { + if (this.locale.equals(locale) && this.manualLocale == manualLocale) + return; + boolean needsUpdate = !this.locale.equals(locale); this.locale = locale; this.manualLocale = manualLocale; updateLocale.update(locale.getLanguage(), manualLocale, id); - new LocaleInvalidationPacket(id).send(getPlayer()); + if (needsUpdate) + new LocaleInvalidationPacket(id).send(getPlayer()); } }