From 64d2724c4ee5d4c39f6ce4fea2c86db2e06199aa Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jun 2022 21:38:48 +0200 Subject: [PATCH 1/4] Some 1.19 fixes --- .../de/steamwar/core/FlatteningWrapper14.java | 4 +- .../src/de/steamwar/core/ChatWrapper19.java | 38 ++++++++++++++++++ .../src/de/steamwar/core/ChatWrapper8.java | 39 +++++++++++++++++++ .../comphenix/tinyprotocol/TinyProtocol.java | 8 ++-- .../src/de/steamwar/core/ChatWrapper.java | 27 +++++++++++++ .../src/de/steamwar/core/Core.java | 4 +- 6 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java create mode 100644 SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java create mode 100644 SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java diff --git a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index b903db6..31214ef 100644 --- a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -222,11 +222,9 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper } private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0); - private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class); - @Override public void setScoreboardTitle(Object packet, String title) { - scoreboardName.set(packet, chatComponentConstructor.invoke(title)); + scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(title)); } private static final Class scoreActionEnum = Reflection.getClass("{nms.server}.ScoreboardServer$Action"); diff --git a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java new file mode 100644 index 0000000..8be810b --- /dev/null +++ b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java @@ -0,0 +1,38 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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 com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import net.minecraft.network.chat.IChatMutableComponent; +import net.minecraft.network.chat.contents.LiteralContents; + +public class ChatWrapper19 implements ChatWrapper { + @Override + public Object stringToChatComponent(String text) { + return IChatMutableComponent.a(new LiteralContents(text)); + } + + private static final Reflection.FieldAccessor getName = Reflection.getField(TinyProtocol.PACKET_LOGIN_IN_START, String.class, 0); + @Override + public String getNameByLoginPacket(Object packet) { + return getName.get(packet); + } +} diff --git a/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java b/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java new file mode 100644 index 0000000..7d02dfd --- /dev/null +++ b/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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 com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import com.mojang.authlib.GameProfile; + +public class ChatWrapper8 implements ChatWrapper { + + private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class); + @Override + public Object stringToChatComponent(String text) { + return chatComponentConstructor.invoke(text); + } + + private static final Reflection.FieldAccessor getGameProfile = Reflection.getField(TinyProtocol.PACKET_LOGIN_IN_START, GameProfile.class, 0); + @Override + public String getNameByLoginPacket(Object packet) { + return getGameProfile.get(packet).getName(); + } +} diff --git a/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index cb63ee0..6951a9a 100644 --- a/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -4,7 +4,7 @@ import com.comphenix.tinyprotocol.Reflection.FieldAccessor; import com.comphenix.tinyprotocol.Reflection.MethodInvoker; import com.google.common.collect.Lists; import com.google.common.collect.MapMaker; -import com.mojang.authlib.GameProfile; +import de.steamwar.core.ChatWrapper; import de.steamwar.core.Core; import io.netty.channel.*; import org.bukkit.Bukkit; @@ -48,8 +48,7 @@ public class TinyProtocol { private static final FieldAccessor getNetworkMarkers = Reflection.getField(serverConnectionClass, Collection.class, 1); // Packets we have to intercept - private static final Class PACKET_LOGIN_IN_START = Reflection.getClass("{nms.network.protocol.login}.PacketLoginInStart"); - private static final FieldAccessor getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0); + public static final Class PACKET_LOGIN_IN_START = Reflection.getClass("{nms.network.protocol.login}.PacketLoginInStart"); // Speedup channel lookup private final Map channelLookup = new MapMaker().weakValues().makeMap(); @@ -404,8 +403,7 @@ public class TinyProtocol { private void handleLoginStart(Channel channel, Object packet) { if (PACKET_LOGIN_IN_START.isInstance(packet)) { - GameProfile profile = getGameProfile.get(packet); - channelLookup.put(profile.getName(), channel); + channelLookup.put(ChatWrapper.impl.getNameByLoginPacket(packet), channel); } } } diff --git a/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java b/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java new file mode 100644 index 0000000..eeddd1c --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java @@ -0,0 +1,27 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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 interface ChatWrapper { + ChatWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); + + Object stringToChatComponent(String text); + String getNameByLoginPacket(Object packet); +} diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 111d344..c18e6f9 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -49,7 +49,9 @@ public class Core extends JavaPlugin{ private static final int VERSION; static{ String packageName = Bukkit.getServer().getClass().getPackage().getName(); - if(packageName.contains("1_18")) + if(packageName.contains("1_19")) + VERSION = 19; + else if(packageName.contains("1_18")) VERSION = 18; else if(packageName.contains("1_15")) VERSION = 15; From 3552acd4731bb7142509c6f578a013be7a8b423f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Jun 2022 20:49:29 +0200 Subject: [PATCH 2/4] Fix 1.19 --- CommonCore | 2 +- SpigotCore_Main/src/de/steamwar/core/Core.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CommonCore b/CommonCore index 919c4d5..492894c 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 919c4d525ea39756b24bd961bb72d8d58bdd5bd4 +Subproject commit 492894ca8d41ee0bde4dcb9d520db5f7478c50c7 diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index c18e6f9..da903be 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -122,7 +122,8 @@ public class Core extends JavaPlugin{ Bukkit.getPluginManager().registerEvents(new WorldLoadEvent(), this); getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver()); getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge"); - AuthlibInjector.inject(); + if(Core.getVersion() < 19) + AuthlibInjector.inject(); TinyProtocol.init(); try { getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine()); From bc5f099b3b1bb2c66a1286e79ad9d8713451a877 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 13 Jun 2022 20:53:27 +0200 Subject: [PATCH 3/4] Fix Java 8 Properties --- .../src/de/steamwar/message/Message.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/message/Message.java b/SpigotCore_Main/src/de/steamwar/message/Message.java index 6835e8b..095e2d6 100644 --- a/SpigotCore_Main/src/de/steamwar/message/Message.java +++ b/SpigotCore_Main/src/de/steamwar/message/Message.java @@ -20,7 +20,6 @@ package de.steamwar.message; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.WorldOfColorWrapper; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.ClickEvent; @@ -30,12 +29,15 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.util.Locale; import java.util.ResourceBundle; public class Message { + private static final int JDK_VERSION = Integer.parseInt(System.getProperty("java.version").split("\\.")[1]); + private final String resourceBundleName; private final ClassLoader classLoader; @@ -68,12 +70,19 @@ public class Message { ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleName, locale, classLoader); String pattern = ""; if(prefixed) - pattern = resourceBundle.getObject("PREFIX") + " "; - pattern += (String)resourceBundle.getObject(message); + pattern = fromRB(resourceBundle, "PREFIX") + " "; + pattern += fromRB(resourceBundle, message); return new MessageFormat(pattern, locale).format(params); } + private String fromRB(ResourceBundle bundle, String key) { + String result = bundle.getString(key); + if(JDK_VERSION < 9) + result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); + return result; + } + private Locale getLocale(Player player){ return SteamwarUser.get(player).getLocale(); } From 4bbdc93a440452a62761fef2356b59e3c975e231 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 13 Jun 2022 21:09:47 +0200 Subject: [PATCH 4/4] Fix Java 8 Properties --- SpigotCore_Main/src/de/steamwar/message/Message.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/message/Message.java b/SpigotCore_Main/src/de/steamwar/message/Message.java index 095e2d6..f78fa78 100644 --- a/SpigotCore_Main/src/de/steamwar/message/Message.java +++ b/SpigotCore_Main/src/de/steamwar/message/Message.java @@ -20,6 +20,7 @@ package de.steamwar.message; import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.ClickEvent; @@ -35,9 +36,6 @@ import java.util.Locale; import java.util.ResourceBundle; public class Message { - - private static final int JDK_VERSION = Integer.parseInt(System.getProperty("java.version").split("\\.")[1]); - private final String resourceBundleName; private final ClassLoader classLoader; @@ -78,7 +76,7 @@ public class Message { private String fromRB(ResourceBundle bundle, String key) { String result = bundle.getString(key); - if(JDK_VERSION < 9) + if(Core.getVersion() < 12) result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); return result; }