making authlib injector multiversional
Dieser Commit ist enthalten in:
Ursprung
a9ed7441f1
Commit
6f116804b7
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -17,31 +17,19 @@
|
||||
* 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 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<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)));
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* 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.GameProfile;
|
In neuem Issue referenzieren
Einen Benutzer sperren