From 50e86fbf8917c86048519ebcf992d874b2aa8f31 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 20 Dec 2025 11:53:28 +0100 Subject: [PATCH] Add 1.19 impl for SteamwarGameProfileRepository --- SpigotCore/SpigotCore_19/build.gradle.kts | 1 + .../SteamwarGameProfileRepository19.java | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 SpigotCore/SpigotCore_19/src/de/steamwar/core/authlib/SteamwarGameProfileRepository19.java diff --git a/SpigotCore/SpigotCore_19/build.gradle.kts b/SpigotCore/SpigotCore_19/build.gradle.kts index 1d696271..13a4ee47 100644 --- a/SpigotCore/SpigotCore_19/build.gradle.kts +++ b/SpigotCore/SpigotCore_19/build.gradle.kts @@ -22,6 +22,7 @@ plugins { } dependencies { + compileOnly(project(":CommonCore", "default")) compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) compileOnly(project(":SpigotCore:SpigotCore_14", "default")) compileOnly(project(":SpigotCore:SpigotCore_18", "default")) diff --git a/SpigotCore/SpigotCore_19/src/de/steamwar/core/authlib/SteamwarGameProfileRepository19.java b/SpigotCore/SpigotCore_19/src/de/steamwar/core/authlib/SteamwarGameProfileRepository19.java new file mode 100644 index 00000000..c0d90efa --- /dev/null +++ b/SpigotCore/SpigotCore_19/src/de/steamwar/core/authlib/SteamwarGameProfileRepository19.java @@ -0,0 +1,68 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.authlib; + +import com.mojang.authlib.Agent; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.GameProfileRepository; +import com.mojang.authlib.ProfileLookupCallback; +import de.steamwar.Reflection; +import de.steamwar.sql.SteamwarUser; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.Services; + +import java.util.ArrayList; +import java.util.List; + +public class SteamwarGameProfileRepository19 extends SteamwarGameProfileRepository { + private static final GameProfileRepository fallback; + private static final Reflection.Field field; + private static final Services current; + + static { + Class clazz = MinecraftServer.getServer().getClass(); + field = Reflection.getField(clazz, Services.class, 0); + current = field.get(MinecraftServer.getServer()); + fallback = current.c(); + } + + @Override + public void inject() { + Services newServices = new Services(current.a(), current.b(), this, current.d(), current.paperConfigurations()); + field.set(MinecraftServer.getServer(), newServices); + } + + @Override + public void findProfilesByNames(String[] strings, Agent agent, ProfileLookupCallback profileLookupCallback) { + 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); + } + } +}