From be90e4dcddd0d45e7e93d5b03e1a1f208005d89f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 15 Jan 2023 16:02:27 +0100 Subject: [PATCH] Fix player join 1.8 to 1.10 --- SpigotCore_12/build.gradle | 1 + .../steamwar/core/LocaleChangeWrapper12.java | 34 +++++++++++++++++++ .../steamwar/core/LocaleChangeWrapper8.java | 24 +++++++++++++ .../src/de/steamwar/core/Core.java | 3 ++ .../de/steamwar/core/LocaleChangeWrapper.java | 26 ++++++++++++++ .../core/events/PlayerJoinedEvent.java | 10 ------ 6 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 SpigotCore_12/src/de/steamwar/core/LocaleChangeWrapper12.java create mode 100644 SpigotCore_8/src/de/steamwar/core/LocaleChangeWrapper8.java create mode 100644 SpigotCore_Main/src/de/steamwar/core/LocaleChangeWrapper.java diff --git a/SpigotCore_12/build.gradle b/SpigotCore_12/build.gradle index 571fa60..bcb1529 100644 --- a/SpigotCore_12/build.gradle +++ b/SpigotCore_12/build.gradle @@ -43,6 +43,7 @@ sourceSets { } dependencies { + compileOnly project(':CommonCore') compileOnly project(":SpigotCore_Main") compileOnly swdep("Spigot-1.12") diff --git a/SpigotCore_12/src/de/steamwar/core/LocaleChangeWrapper12.java b/SpigotCore_12/src/de/steamwar/core/LocaleChangeWrapper12.java new file mode 100644 index 0000000..152751c --- /dev/null +++ b/SpigotCore_12/src/de/steamwar/core/LocaleChangeWrapper12.java @@ -0,0 +1,34 @@ +/* + * 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.core; + +import de.steamwar.sql.SteamwarUser; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerLocaleChangeEvent; + +import java.util.Locale; + +public class LocaleChangeWrapper12 implements LocaleChangeWrapper { + + @EventHandler + private void onLocale(PlayerLocaleChangeEvent event) { + SteamwarUser.get(event.getPlayer().getUniqueId()).setLocale(Locale.forLanguageTag(event.getLocale()), false); + } +} diff --git a/SpigotCore_8/src/de/steamwar/core/LocaleChangeWrapper8.java b/SpigotCore_8/src/de/steamwar/core/LocaleChangeWrapper8.java new file mode 100644 index 0000000..ddee9c6 --- /dev/null +++ b/SpigotCore_8/src/de/steamwar/core/LocaleChangeWrapper8.java @@ -0,0 +1,24 @@ +/* + * 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.core; + +public class LocaleChangeWrapper8 implements LocaleChangeWrapper { + // Event not available in 1.8-1.10 +} diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 7c76ebc..bc7e957 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -110,6 +110,9 @@ public class Core extends JavaPlugin{ Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this); Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this); Bukkit.getPluginManager().registerEvents(new WorldLoadEvent(), this); + if(!Statement.productionDatabase()) { + Bukkit.getPluginManager().registerEvents(LocaleChangeWrapper.impl, this); + } getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new NetworkReceiver()); getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge"); if(Core.getVersion() < 19) diff --git a/SpigotCore_Main/src/de/steamwar/core/LocaleChangeWrapper.java b/SpigotCore_Main/src/de/steamwar/core/LocaleChangeWrapper.java new file mode 100644 index 0000000..6db67b7 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/core/LocaleChangeWrapper.java @@ -0,0 +1,26 @@ +/* + * 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.core; + +import org.bukkit.event.Listener; + +public interface LocaleChangeWrapper extends Listener { + LocaleChangeWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); +} diff --git a/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java b/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java index 4d0f776..aae2000 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java @@ -27,11 +27,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerLocaleChangeEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.Locale; - public class PlayerJoinedEvent implements Listener{ @@ -51,13 +48,6 @@ public class PlayerJoinedEvent implements Listener{ event.setJoinMessage("§a§l» §r" + player.getDisplayName()); } - - @EventHandler - private void onLocale(PlayerLocaleChangeEvent event) { - if(!Statement.productionDatabase()) { - SteamwarUser.get(event.getPlayer().getUniqueId()).setLocale(Locale.forLanguageTag(event.getLocale()), false); - } - } @EventHandler private void onQuit(PlayerQuitEvent event) { -- 2.39.2