forked from SteamWar/SteamWar
Refactor Authlib integration and adjust entity handling for 1.21 compatibility
This commit is contained in:
@@ -21,6 +21,12 @@ package de.steamwar.core;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.command.*;
|
||||
import de.steamwar.core.authlib.SteamwarGameProfileRepository;
|
||||
import de.steamwar.core.events.AntiNocom;
|
||||
import de.steamwar.core.events.ChattingEvent;
|
||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||
import de.steamwar.core.events.WorldLoadEvent;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.command.SWTypeMapperCreator;
|
||||
import de.steamwar.command.TabCompletionCache;
|
||||
@@ -110,6 +116,9 @@ public class Core extends JavaPlugin {
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new NetworkReceiver());
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
|
||||
|
||||
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,40 +0,0 @@
|
||||
/*
|
||||
* 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 de.steamwar.Reflection;
|
||||
import com.mojang.authlib.GameProfileRepository;
|
||||
import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.MaxVersion;
|
||||
import de.steamwar.linkage.api.Enable;
|
||||
|
||||
@Linked
|
||||
@MaxVersion(18)
|
||||
public class AuthlibInjector implements Enable {
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
+5
-35
@@ -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;
|
||||
@@ -82,7 +79,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;
|
||||
@@ -117,10 +114,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);
|
||||
|
||||
Reference in New Issue
Block a user