From d830eb6f47e89e4fbc8dfcd2388e769e53f03828 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 02:03:23 +0200 Subject: [PATCH 1/7] Little Skull Patch --- SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java index adf1b9c..d31f937 100644 --- a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java +++ b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java @@ -19,7 +19,9 @@ package de.steamwar.inventory; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; @@ -269,7 +271,12 @@ class SWItem_14 { ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); SkullMeta headmeta = (SkullMeta) head.getItemMeta(); assert headmeta != null; - headmeta.setOwner(player); + Player p = Bukkit.getPlayer(player); + if (p != null) { + headmeta.setOwningPlayer(p); + } else { + headmeta.setOwner(player); + } headmeta.setDisplayName(player); head.setItemMeta(headmeta); return head; From 24f605daf2713ae4e685960e5003a349553922c1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 02:04:37 +0200 Subject: [PATCH 2/7] Minor Fix --- SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java index d31f937..08b3fee 100644 --- a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java +++ b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java @@ -271,7 +271,7 @@ class SWItem_14 { ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); SkullMeta headmeta = (SkullMeta) head.getItemMeta(); assert headmeta != null; - Player p = Bukkit.getPlayer(player); + Player p = Bukkit.getPlayerExact(player); if (p != null) { headmeta.setOwningPlayer(p); } else { From 6c2d9d067f07330ac702ab3fcadf465d0de1645a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 12:02:12 +0200 Subject: [PATCH 3/7] Even more Cache --- SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java index 08b3fee..623dd20 100644 --- a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java +++ b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java @@ -21,7 +21,6 @@ package de.steamwar.inventory; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; @@ -271,12 +270,7 @@ class SWItem_14 { ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); SkullMeta headmeta = (SkullMeta) head.getItemMeta(); assert headmeta != null; - Player p = Bukkit.getPlayerExact(player); - if (p != null) { - headmeta.setOwningPlayer(p); - } else { - headmeta.setOwner(player); - } + headmeta.setOwningPlayer(Bukkit.getOfflinePlayer(player)); headmeta.setDisplayName(player); head.setItemMeta(headmeta); return head; From f4e77fb6fc0ff2d9187668f8912b5c863a0f14c7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 12:28:55 +0200 Subject: [PATCH 4/7] Speedy UUID Lookup --- .../steamwar/authlib/AuthlibInjector_15.java | 33 ++++++++++ .../de/steamwar/authlib/AuthlibInjector.java | 46 ++++++++++++++ .../SteamwarGameProfileRepository.java | 61 +++++++++++++++++++ .../src/de/steamwar/core/Core.java | 2 + 4 files changed, 142 insertions(+) create mode 100644 SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java create mode 100644 SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java create mode 100644 SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java diff --git a/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java b/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java new file mode 100644 index 0000000..9864a31 --- /dev/null +++ b/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java @@ -0,0 +1,33 @@ +/* + * 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.authlib; + +import net.minecraft.server.v1_15_R1.MinecraftServer; + +public class AuthlibInjector_15 { + + static Class getMinecraftClass() { + return MinecraftServer.class; + } + + static Object getMinecraftServerInstance() { + return MinecraftServer.getServer(); + } +} diff --git a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java new file mode 100644 index 0000000..b96f71c --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.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.authlib; + +import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository; +import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; + +import java.lang.reflect.Field; + +public class AuthlibInjector { + + public static void inject() { + if(Core.getVersion() < 15) { + return; + } + try { + Class minecraftServerClass = VersionedCallable.call(new VersionedCallable<>(() -> AuthlibInjector_15.getMinecraftClass(), 15)); + Field repo = minecraftServerClass.getDeclaredField("gameProfileRepository"); + repo.setAccessible(true); + Object instance = VersionedCallable.call(new VersionedCallable<>(() -> AuthlibInjector_15.getMinecraftServerInstance(), 15)); + repo.set(instance, new SteamwarGameProfileRepository((YggdrasilGameProfileRepository) repo.get(instance))); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java b/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java new file mode 100644 index 0000000..20bcc9c --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java @@ -0,0 +1,61 @@ +/* + * 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.authlib; + +import com.mojang.authlib.Agent; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.GameProfileRepository; +import com.mojang.authlib.ProfileLookupCallback; +import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository; +import de.steamwar.sql.SteamwarUser; + +import java.util.ArrayList; +import java.util.List; + +public class SteamwarGameProfileRepository implements GameProfileRepository { + + private final YggdrasilGameProfileRepository fallback; + + public SteamwarGameProfileRepository(YggdrasilGameProfileRepository repository) { + fallback = repository; + } + + @Override + public void findProfilesByNames(String[] strings, Agent agent, ProfileLookupCallback profileLookupCallback) { + System.out.println("Call!!"); + if(agent == Agent.SCROLLS) { + fallback.findProfilesByNames(strings, agent, profileLookupCallback); + } else { + List unknownNames = new ArrayList<>(); + for (String name:strings) { + SteamwarUser user = SteamwarUser.get(name); + if(user == null) { + unknownNames.add(name); + continue; + } + + profileLookupCallback.onProfileLookupSucceeded(new GameProfile(user.getUUID(), user.getUserName())); + } + if(!unknownNames.isEmpty()) { + fallback.findProfilesByNames(unknownNames.toArray(new String[0]), agent, profileLookupCallback); + } + } + } +} diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index d9c59df..62f8849 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -19,6 +19,7 @@ package de.steamwar.core; +import de.steamwar.authlib.AuthlibInjector; import de.steamwar.comms.BungeeReceiver; import de.steamwar.core.events.ChattingEvent; import de.steamwar.core.events.ChunkListener; @@ -64,6 +65,7 @@ public class Core extends JavaPlugin{ ErrorLogger.init(); getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver()); getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge"); + AuthlibInjector.inject(); } @Override From c41a7d40404efe0d7b587ae42ad6082c8f5da00f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 12:30:09 +0200 Subject: [PATCH 5/7] Remove Debug Message --- .../src/de/steamwar/authlib/SteamwarGameProfileRepository.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java b/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java index 20bcc9c..3a4ebae 100644 --- a/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java +++ b/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java @@ -39,7 +39,6 @@ public class SteamwarGameProfileRepository implements GameProfileRepository { @Override public void findProfilesByNames(String[] strings, Agent agent, ProfileLookupCallback profileLookupCallback) { - System.out.println("Call!!"); if(agent == Agent.SCROLLS) { fallback.findProfilesByNames(strings, agent, profileLookupCallback); } else { From 1c3318d5fdb60f021cb8349069999d6d4db720a0 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 20:16:38 +0200 Subject: [PATCH 6/7] Fix Version --- SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java index b96f71c..dcb6ea2 100644 --- a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java +++ b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java @@ -28,9 +28,10 @@ import java.lang.reflect.Field; public class AuthlibInjector { public static void inject() { - if(Core.getVersion() < 15) { + if(Core.getVersion() != 15) { return; } + try { Class minecraftServerClass = VersionedCallable.call(new VersionedCallable<>(() -> AuthlibInjector_15.getMinecraftClass(), 15)); Field repo = minecraftServerClass.getDeclaredField("gameProfileRepository"); From 76cdbda4e7259516af99153b6691d18262ed886c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 20:17:10 +0200 Subject: [PATCH 7/7] Fix Version --- SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java index dcb6ea2..f12bd3d 100644 --- a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java +++ b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java @@ -28,7 +28,7 @@ import java.lang.reflect.Field; public class AuthlibInjector { public static void inject() { - if(Core.getVersion() != 15) { + if (Core.getVersion() != 15) { return; }