Refactor Authlib integration and adjust entity handling for 1.21 compatibility
All checks were successful
SteamWarCI Build successful
All checks were successful
SteamWarCI Build successful
This commit is contained in:
@ -37,4 +37,6 @@ dependencies {
|
||||
|
||||
compileOnly(libs.paperapi21)
|
||||
compileOnly(libs.nms21)
|
||||
compileOnly(libs.authlib2)
|
||||
compileOnly(libs.datafixer)
|
||||
}
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class ProtocolWrapper21 implements ProtocolWrapper {
|
||||
@Override
|
||||
public void setEquipmentPacketStack(Object packet, Object slot, Object stack) {
|
||||
ClientboundSetEquipmentPacket setEquipmentPacket = (ClientboundSetEquipmentPacket) packet;
|
||||
setEquipmentPacket.getSlots().add(Pair.of((EquipmentSlot) slot, (ItemStack) stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode) {
|
||||
if(action == PlayerInfoAction.REMOVE)
|
||||
return new ClientboundPlayerInfoRemovePacket(Collections.singletonList(profile.getId()));
|
||||
|
||||
return new ClientboundPlayerInfoUpdatePacket(action == PlayerInfoAction.ADD ?
|
||||
EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE) : EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE),
|
||||
Collections.singletonList(new ClientboundPlayerInfoUpdatePacket.Entry(profile.getId(), profile, false, 0, GameType.byId(mode.getValue()), null, false, 0, null)));
|
||||
}
|
||||
}
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -40,4 +41,9 @@ public class TrickyTrialsWrapper21 implements TrickyTrialsWrapper {
|
||||
public Material getTurtleScute() {
|
||||
return Material.TURTLE_SCUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(Property property) {
|
||||
return property.value();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core.authlib;
|
||||
|
||||
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;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SteamwarGameProfileRepository21 extends SteamwarGameProfileRepository {
|
||||
private static final GameProfileRepository fallback;
|
||||
private static final Reflection.Field<Services> 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.profileRepository();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findProfilesByNames(String[] strings, ProfileLookupCallback profileLookupCallback) {
|
||||
List<String> 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]), profileLookupCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GameProfile> findProfileByName(String s) {
|
||||
return fallback.findProfileByName(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject() {
|
||||
Services newServices = new Services(current.sessionService(), current.servicesKeySet(), this, current.profileCache(), current.paperConfigurations());
|
||||
field.set(MinecraftServer.getServer(), newServices);
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,9 @@
|
||||
|
||||
package de.steamwar.entity;
|
||||
|
||||
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.PositionMoveRotation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
@ -31,4 +33,21 @@ public class PacketConstructor21 implements PacketConstructor{
|
||||
PositionMoveRotation rot = new PositionMoveRotation(new Vec3(x, y, z), Vec3.ZERO, pitch, yaw);
|
||||
return new ClientboundTeleportEntityPacket(entityId, rot, Collections.emptySet(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createRPlayerSpawn(RPlayer player) {
|
||||
return new ClientboundAddEntityPacket(
|
||||
player.entityId,
|
||||
player.uuid,
|
||||
player.x,
|
||||
player.y,
|
||||
player.z,
|
||||
player.yaw,
|
||||
player.pitch,
|
||||
EntityType.PLAYER,
|
||||
0,
|
||||
Vec3.ZERO,
|
||||
player.headYaw
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -40,4 +41,9 @@ public class TrickyTrialsWrapper8 implements TrickyTrialsWrapper {
|
||||
public Material getTurtleScute() {
|
||||
return Material.STONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(Property property) {
|
||||
return property.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SteamwarGameProfileRepository8 extends SteamwarGameProfileRepository {
|
||||
|
||||
private static final GameProfileRepository fallback;
|
||||
|
||||
private static final Object minecraftServer;
|
||||
private static final Reflection.Field<?> gameProfile;
|
||||
|
||||
static {
|
||||
Class<?> minecraftServerClass = Reflection.getClass("net.minecraft.server.MinecraftServer");
|
||||
Class<?> gpr = Reflection.getClass("com.mojang.authlib.GameProfileRepository");
|
||||
gameProfile = Reflection.getField(minecraftServerClass, gpr, 0);
|
||||
minecraftServer = Reflection.getTypedMethod(minecraftServerClass, "getServer", minecraftServerClass).invoke(null);
|
||||
fallback = (GameProfileRepository) gameProfile.get(minecraftServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject() {
|
||||
gameProfile.set(minecraftServer, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findProfilesByNames(String[] strings, Agent agent, ProfileLookupCallback profileLookupCallback) {
|
||||
if(agent == Agent.SCROLLS) {
|
||||
fallback.findProfilesByNames(strings, agent, profileLookupCallback);
|
||||
} else {
|
||||
List<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,7 @@ package de.steamwar.core;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.command.*;
|
||||
import de.steamwar.core.authlib.AuthlibInjector;
|
||||
import de.steamwar.core.authlib.SteamwarGameProfileRepository;
|
||||
import de.steamwar.core.events.AntiNocom;
|
||||
import de.steamwar.core.events.ChattingEvent;
|
||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||
@ -97,8 +97,8 @@ public class Core extends JavaPlugin {
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new NetworkReceiver());
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
|
||||
|
||||
if(Core.getVersion() < 19)
|
||||
AuthlibInjector.inject();
|
||||
if (Core.getVersion() != 20)
|
||||
SteamwarGameProfileRepository.impl.inject();
|
||||
|
||||
TinyProtocol.init();
|
||||
CheckpointUtils.signalHandler();
|
||||
|
||||
@ -19,11 +19,10 @@
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
|
||||
public interface TrickyTrialsWrapper {
|
||||
TrickyTrialsWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
|
||||
@ -33,4 +32,6 @@ public interface TrickyTrialsWrapper {
|
||||
Enchantment getUnbreakingEnchantment();
|
||||
|
||||
Material getTurtleScute();
|
||||
|
||||
String getValue(Property property);
|
||||
}
|
||||
|
||||
@ -1,35 +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.core.authlib;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import com.mojang.authlib.GameProfileRepository;
|
||||
import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository;
|
||||
|
||||
public class AuthlibInjector {
|
||||
private AuthlibInjector() {}
|
||||
|
||||
public static void inject() {
|
||||
Class<?> minecraftServerClass = Reflection.getClass("net.minecraft.server.MinecraftServer");
|
||||
Reflection.Field<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)));
|
||||
}
|
||||
}
|
||||
@ -19,42 +19,12 @@
|
||||
|
||||
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 com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.VersionDependent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public abstract class SteamwarGameProfileRepository implements GameProfileRepository {
|
||||
public static final SteamwarGameProfileRepository impl = VersionDependent.getVersionImpl(Core.getInstance());
|
||||
|
||||
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) {
|
||||
if(agent == Agent.SCROLLS) {
|
||||
fallback.findProfilesByNames(strings, agent, profileLookupCallback);
|
||||
} else {
|
||||
List<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract void inject();
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@ import de.steamwar.core.Core;
|
||||
import de.steamwar.core.VersionDependent;
|
||||
|
||||
public interface PacketConstructor {
|
||||
public static final PacketConstructor impl = VersionDependent.getVersionImpl(Core.getInstance());
|
||||
PacketConstructor impl = VersionDependent.getVersionImpl(Core.getInstance());
|
||||
|
||||
Object teleportPacket(int entityId, double x, double y, double z, float yaw, float pitch);
|
||||
Object createRPlayerSpawn(RPlayer player);
|
||||
}
|
||||
|
||||
@ -58,9 +58,9 @@ public class REntity {
|
||||
protected double y;
|
||||
@Getter
|
||||
protected double z;
|
||||
private byte yaw;
|
||||
private byte pitch;
|
||||
private byte headYaw;
|
||||
protected byte yaw;
|
||||
protected byte pitch;
|
||||
protected byte headYaw;
|
||||
|
||||
@Getter
|
||||
private boolean hidden;
|
||||
|
||||
@ -22,10 +22,7 @@ package de.steamwar.entity;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.BountifulWrapper;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.FlatteningWrapper;
|
||||
import de.steamwar.core.ProtocolWrapper;
|
||||
import de.steamwar.core.*;
|
||||
import de.steamwar.network.CoreNetworkHandler;
|
||||
import de.steamwar.network.NetworkSender;
|
||||
import de.steamwar.network.packets.common.PlayerSkinRequestPacket;
|
||||
@ -81,7 +78,7 @@ public class RPlayer extends REntity {
|
||||
NetworkSender.sendOrQueue(new PlayerSkinRequestPacket(actualUUID));
|
||||
return new Property("textures", null, null);
|
||||
});
|
||||
if (skinData.getValue() != null) {
|
||||
if (TrickyTrialsWrapper.impl.getValue(skinData) != null) {
|
||||
GameProfile gameProfile = new GameProfile(uuid, name);
|
||||
gameProfile.getProperties().put("textures", skinData);
|
||||
return gameProfile;
|
||||
@ -116,10 +113,21 @@ public class RPlayer extends REntity {
|
||||
packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, saved, GameMode.CREATIVE));
|
||||
}
|
||||
|
||||
private static final Class<?> namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket");
|
||||
private static final Function<REntity, Object> namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0);
|
||||
private static final Reflection.Field<UUID> namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0);
|
||||
private static Class<?> namedSpawnPacket = null;
|
||||
private static Function<REntity, Object> namedSpawnPacketGenerator = null;
|
||||
private static Reflection.Field<UUID> namedSpawnUUID = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket");
|
||||
namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0);
|
||||
namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0);
|
||||
} catch (IllegalArgumentException e) { }
|
||||
}
|
||||
|
||||
private Object getNamedSpawnPacket() {
|
||||
if (Core.getVersion() >= 21) return PacketConstructor.impl.createRPlayerSpawn(this);
|
||||
|
||||
Object packet = namedSpawnPacketGenerator.apply(this);
|
||||
namedSpawnUUID.set(packet, uuid);
|
||||
FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet);
|
||||
|
||||
@ -113,6 +113,7 @@ dependencyResolutionManagement {
|
||||
library("paperapi", "io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
|
||||
library("paperapi21", "io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
|
||||
library("authlib", "com.mojang:authlib:1.5.25")
|
||||
library("authlib2", "com.mojang:authlib:6.0.58")
|
||||
library("datafixer", "com.mojang:datafixerupper:4.0.26")
|
||||
library("brigadier", "com.mojang:brigadier:1.0.18")
|
||||
library("anvilgui", "net.wesjd:anvilgui:1.10.6-SNAPSHOT")
|
||||
|
||||
Reference in New Issue
Block a user