diff --git a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector_15.java b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector_15.java deleted file mode 100644 index 9864a31..0000000 --- a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector_15.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 62f8849..bba0e3d 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import de.steamwar.authlib.AuthlibInjector; +import de.steamwar.core.authlib.AuthlibInjector; import de.steamwar.comms.BungeeReceiver; import de.steamwar.core.events.ChattingEvent; import de.steamwar.core.events.ChunkListener; diff --git a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java b/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java similarity index 51% rename from SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java rename to SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java index f12bd3d..ace4936 100644 --- a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java +++ b/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java @@ -17,31 +17,19 @@ * along with this program. If not, see . */ -package de.steamwar.authlib; +package de.steamwar.core.authlib; +import com.comphenix.tinyprotocol.Reflection; +import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository; -import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; - -import java.lang.reflect.Field; public class AuthlibInjector { + private 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(); - } + Class minecraftServerClass = Reflection.getClass("{nms}.MinecraftServer"); + Reflection.FieldAccessor gameProfile = Reflection.getField(minecraftServerClass, GameProfileRepository.class, 0); + Object minecraftServer = Reflection.getTypedMethod(minecraftServerClass, "getServer", minecraftServerClass).invoke(null); + gameProfile.set(minecraftServer, new SteamwarGameProfileRepository((YggdrasilGameProfileRepository) gameProfile.get(minecraftServer))); } } diff --git a/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java b/SpigotCore_Main/src/de/steamwar/core/authlib/SteamwarGameProfileRepository.java similarity index 98% rename from SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java rename to SpigotCore_Main/src/de/steamwar/core/authlib/SteamwarGameProfileRepository.java index 3a4ebae..9045de1 100644 --- a/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java +++ b/SpigotCore_Main/src/de/steamwar/core/authlib/SteamwarGameProfileRepository.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.authlib; +package de.steamwar.core.authlib; import com.mojang.authlib.Agent; import com.mojang.authlib.GameProfile;