SteamWar/SpigotCore
Archiviert
13
0

making authlib injector multiversional

Dieser Commit ist enthalten in:
Lixfel 2021-09-11 02:09:48 +02:00
Ursprung a9ed7441f1
Commit 6f116804b7
4 geänderte Dateien mit 10 neuen und 55 gelöschten Zeilen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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();
}
}

Datei anzeigen

@ -19,7 +19,7 @@
package de.steamwar.core; package de.steamwar.core;
import de.steamwar.authlib.AuthlibInjector; import de.steamwar.core.authlib.AuthlibInjector;
import de.steamwar.comms.BungeeReceiver; import de.steamwar.comms.BungeeReceiver;
import de.steamwar.core.events.ChattingEvent; import de.steamwar.core.events.ChattingEvent;
import de.steamwar.core.events.ChunkListener; import de.steamwar.core.events.ChunkListener;

Datei anzeigen

@ -17,31 +17,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
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 com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import java.lang.reflect.Field;
public class AuthlibInjector { public class AuthlibInjector {
private AuthlibInjector() {}
public static void inject() { public static void inject() {
if (Core.getVersion() != 15) { Class<?> minecraftServerClass = Reflection.getClass("{nms}.MinecraftServer");
return; Reflection.FieldAccessor<GameProfileRepository> 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)));
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();
}
} }
} }

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.authlib; package de.steamwar.core.authlib;
import com.mojang.authlib.Agent; import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;