even more fixes
This commit is contained in:
parent
0de6aa0c44
commit
307f636761
|
@ -34,8 +34,8 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'net.bytebuddy:byte-buddy:1.14.3'
|
implementation 'net.bytebuddy:byte-buddy:1.14.3'
|
||||||
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT'
|
||||||
compileOnly 'org.spigotmc:spigot:1.20-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT'
|
||||||
compileOnly 'io.netty:netty-all:4.0.23.Final'
|
compileOnly 'io.netty:netty-all:4.0.23.Final'
|
||||||
compileOnly 'net.kyori:adventure-text-serializer-gson:4.13.0'
|
compileOnly 'net.kyori:adventure-text-serializer-gson:4.13.0'
|
||||||
compileOnly 'com.googlecode.json-simple:json-simple:1.1.1'
|
compileOnly 'com.googlecode.json-simple:json-simple:1.1.1'
|
||||||
|
@ -44,8 +44,8 @@ dependencies {
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
|
||||||
testImplementation 'org.mockito:mockito-core:4.11.0'
|
testImplementation 'org.mockito:mockito-core:4.11.0'
|
||||||
testImplementation 'org.mockito:mockito-inline:4.11.0'
|
testImplementation 'org.mockito:mockito-inline:4.11.0'
|
||||||
testImplementation 'io.netty:netty-common:4.1.77.Final'
|
testImplementation 'io.netty:netty-common:4.1.97.Final'
|
||||||
testImplementation 'io.netty:netty-transport:4.1.77.Final'
|
testImplementation 'io.netty:netty-transport:4.1.97.Final'
|
||||||
testImplementation 'org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT'
|
testImplementation 'org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT'
|
||||||
testImplementation 'net.kyori:adventure-text-serializer-gson:4.13.0'
|
testImplementation 'net.kyori:adventure-text-serializer-gson:4.13.0'
|
||||||
testImplementation 'net.kyori:adventure-text-serializer-plain:4.13.1'
|
testImplementation 'net.kyori:adventure-text-serializer-plain:4.13.1'
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.profile.PlayerProfile;
|
import org.bukkit.profile.PlayerProfile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
|
@ -48,6 +49,9 @@ import java.io.Serializable;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -240,6 +244,24 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||||
return banned;
|
return banned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public BanEntry<PlayerProfile> ban(@Nullable String s, @Nullable Date date, @Nullable String s1) {
|
||||||
|
setBanned(true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public BanEntry<PlayerProfile> ban(@Nullable String s, @Nullable Instant instant, @Nullable String s1) {
|
||||||
|
setBanned(true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public BanEntry<PlayerProfile> ban(@Nullable String s, @Nullable Duration duration, @Nullable String s1) {
|
||||||
|
setBanned(true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void setBanned(boolean banned) {
|
public void setBanned(boolean banned) {
|
||||||
this.banned = banned;
|
this.banned = banned;
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,8 +179,8 @@ public class StructureCache {
|
||||||
DynamicType.Builder<?> baseBuilder = ByteBuddyFactory.getInstance()
|
DynamicType.Builder<?> baseBuilder = ByteBuddyFactory.getInstance()
|
||||||
.createSubclass(MinecraftReflection.getPacketDataSerializerClass())
|
.createSubclass(MinecraftReflection.getPacketDataSerializerClass())
|
||||||
.name(MinecraftMethods.class.getPackage().getName() + ".ProtocolLibTricksNmsDataSerializerBase")
|
.name(MinecraftMethods.class.getPackage().getName() + ".ProtocolLibTricksNmsDataSerializerBase")
|
||||||
.method(ElementMatchers.returns(MinecraftReflection.getNBTCompoundClass())
|
.method(ElementMatchers.takesArguments(MinecraftReflection.getNBTReadLimiterClass())
|
||||||
.and(ElementMatchers.takesArguments(MinecraftReflection.getNBTReadLimiterClass())))
|
.and(ElementMatchers.returns(ElementMatchers.isSubTypeOf(MinecraftReflection.getNBTBaseClass()))))
|
||||||
.intercept(FixedValue.value(compound))
|
.intercept(FixedValue.value(compound))
|
||||||
.method(ElementMatchers.returns(MinecraftReflection.getIChatBaseComponentClass()))
|
.method(ElementMatchers.returns(MinecraftReflection.getIChatBaseComponentClass()))
|
||||||
.intercept(FixedValue.value(textCompound))
|
.intercept(FixedValue.value(textCompound))
|
||||||
|
|
|
@ -171,7 +171,7 @@ public final class MinecraftMethods {
|
||||||
.method(ElementMatchers.not(ElementMatchers.isDeclaredBy(Object.class)))
|
.method(ElementMatchers.not(ElementMatchers.isDeclaredBy(Object.class)))
|
||||||
.intercept(MethodDelegation.to(new Object() {
|
.intercept(MethodDelegation.to(new Object() {
|
||||||
@RuntimeType
|
@RuntimeType
|
||||||
public Object delegate(@SuperCall Callable<?> zuper, @Origin Method method) throws Exception {
|
public Object delegate(@SuperCall(nullIfImpossible = true) Callable<?> zuper, @Origin Method method) throws Exception {
|
||||||
if (method.getName().contains("read")) {
|
if (method.getName().contains("read")) {
|
||||||
throw new ReadMethodException();
|
throw new ReadMethodException();
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,8 @@ public final class MinecraftMethods {
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructs a new decorated serializer
|
// constructs a new decorated serializer
|
||||||
Object decoratedSerializer = decoratedDataSerializerAccessor.invoke(Unpooled.EMPTY_BUFFER);
|
Object serializerBacking = decoratedDataSerializerAccessor.invoke(Unpooled.EMPTY_BUFFER);
|
||||||
|
Object decoratedSerializer = decoratedDataSerializerAccessor.invoke(serializerBacking);
|
||||||
|
|
||||||
// find all methods which might be the read or write methods
|
// find all methods which might be the read or write methods
|
||||||
List<Method> candidates = FuzzyReflection
|
List<Method> candidates = FuzzyReflection
|
||||||
|
|
|
@ -1115,7 +1115,6 @@ public class BukkitConverters {
|
||||||
static MethodAccessor getSoundEffect = null;
|
static MethodAccessor getSoundEffect = null;
|
||||||
static FieldAccessor soundKey = null;
|
static FieldAccessor soundKey = null;
|
||||||
|
|
||||||
static MethodAccessor getSoundEffectByKey = null;
|
|
||||||
static MethodAccessor getSoundEffectBySound = null;
|
static MethodAccessor getSoundEffectBySound = null;
|
||||||
static MethodAccessor getSoundByEffect = null;
|
static MethodAccessor getSoundByEffect = null;
|
||||||
|
|
||||||
|
@ -1124,16 +1123,10 @@ public class BukkitConverters {
|
||||||
public static EquivalentConverter<Sound> getSoundConverter() {
|
public static EquivalentConverter<Sound> getSoundConverter() {
|
||||||
// Try to create sound converter for new versions greater 1.16.4
|
// Try to create sound converter for new versions greater 1.16.4
|
||||||
if (MinecraftVersion.NETHER_UPDATE_4.atOrAbove()) {
|
if (MinecraftVersion.NETHER_UPDATE_4.atOrAbove()) {
|
||||||
if (getSoundEffectByKey == null || getSoundEffectBySound == null || getSoundByEffect == null) {
|
if (getSoundEffectBySound == null || getSoundByEffect == null) {
|
||||||
Class<?> craftSound = MinecraftReflection.getCraftSoundClass();
|
Class<?> craftSound = MinecraftReflection.getCraftSoundClass();
|
||||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(craftSound, true);
|
FuzzyReflection fuzzy = FuzzyReflection.fromClass(craftSound, true);
|
||||||
|
|
||||||
getSoundEffectByKey = Accessors.getMethodAccessor(fuzzy.getMethodByReturnTypeAndParameters(
|
|
||||||
"getSoundEffect",
|
|
||||||
MinecraftReflection.getSoundEffectClass(),
|
|
||||||
String.class
|
|
||||||
));
|
|
||||||
|
|
||||||
getSoundEffectBySound = Accessors.getMethodAccessor(fuzzy.getMethodByReturnTypeAndParameters(
|
getSoundEffectBySound = Accessors.getMethodAccessor(fuzzy.getMethodByReturnTypeAndParameters(
|
||||||
"getSoundEffect",
|
"getSoundEffect",
|
||||||
MinecraftReflection.getSoundEffectClass(),
|
MinecraftReflection.getSoundEffectClass(),
|
||||||
|
|
|
@ -2,24 +2,45 @@ package com.comphenix.protocol;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflectionTestUtil;
|
import com.comphenix.protocol.utility.MinecraftReflectionTestUtil;
|
||||||
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
|
import net.minecraft.commands.CommandDispatcher;
|
||||||
import net.minecraft.core.IRegistry;
|
import net.minecraft.core.IRegistry;
|
||||||
|
import net.minecraft.core.IRegistryCustom;
|
||||||
|
import net.minecraft.core.LayeredRegistryAccess;
|
||||||
|
import net.minecraft.resources.RegistryDataLoader;
|
||||||
|
import net.minecraft.server.DataPackResources;
|
||||||
import net.minecraft.server.DispenserRegistry;
|
import net.minecraft.server.DispenserRegistry;
|
||||||
|
import net.minecraft.server.RegistryLayer;
|
||||||
|
import net.minecraft.server.WorldLoader;
|
||||||
import net.minecraft.server.level.WorldServer;
|
import net.minecraft.server.level.WorldServer;
|
||||||
|
import net.minecraft.server.packs.EnumResourcePackType;
|
||||||
|
import net.minecraft.server.packs.repository.ResourcePackLoader;
|
||||||
|
import net.minecraft.server.packs.repository.ResourcePackRepository;
|
||||||
|
import net.minecraft.server.packs.repository.ResourcePackSourceVanilla;
|
||||||
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
|
import net.minecraft.world.flag.FeatureFlagSet;
|
||||||
|
import net.minecraft.world.flag.FeatureFlags;
|
||||||
|
import net.minecraft.world.item.enchantment.Enchantments;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.craftbukkit.v1_20_R2.CraftLootTable;
|
||||||
import org.bukkit.World;
|
import org.bukkit.craftbukkit.v1_20_R2.CraftRegistry;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemFactory;
|
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemFactory;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers;
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.util.Versioning;
|
import org.bukkit.craftbukkit.v1_20_R2.util.Versioning;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.spigotmc.SpigotWorldConfig;
|
import org.spigotmc.SpigotWorldConfig;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -69,8 +90,30 @@ public class BukkitInitialization {
|
||||||
|
|
||||||
instance.setPackage();
|
instance.setPackage();
|
||||||
|
|
||||||
SharedConstants.a();
|
// Minecraft Data Init
|
||||||
DispenserRegistry.a();
|
SharedConstants.a(); // .tryDetectVersion()
|
||||||
|
DispenserRegistry.a(); // .bootStrap()
|
||||||
|
|
||||||
|
ResourcePackRepository resourcePackRepository = ResourcePackSourceVanilla.c(); // .createVanillaTrustedRepository()
|
||||||
|
resourcePackRepository.a(); // .reload()
|
||||||
|
|
||||||
|
ResourceManager resourceManager = new ResourceManager(
|
||||||
|
EnumResourcePackType.b /* SERVER_DATA */,
|
||||||
|
resourcePackRepository.c() /* getAvailablePacks() */ .stream().map(ResourcePackLoader::e /* openFull() */).collect(Collectors.toList()));
|
||||||
|
LayeredRegistryAccess<RegistryLayer> layeredRegistryAccess = RegistryLayer.a(); // .createRegistryAccess()
|
||||||
|
layeredRegistryAccess = WorldLoader.b(resourceManager, layeredRegistryAccess, RegistryLayer.b /* WORLDGEN */, RegistryDataLoader.a /* WORLDGEN_REGISTRIES */); // .loadAndReplaceLayer()
|
||||||
|
IRegistryCustom.Dimension registryCustom = layeredRegistryAccess.a().c(); // .compositeAccess().freeze()
|
||||||
|
|
||||||
|
DataPackResources dataPackResources = DataPackResources.a(
|
||||||
|
resourceManager,
|
||||||
|
registryCustom,
|
||||||
|
FeatureFlags.d.a() /* REGISTRY.allFlags() */,
|
||||||
|
CommandDispatcher.ServerType.b /* DEDICATED */,
|
||||||
|
0,
|
||||||
|
MoreExecutors.directExecutor(),
|
||||||
|
MoreExecutors.directExecutor()
|
||||||
|
).join();
|
||||||
|
dataPackResources.a(registryCustom); // .updateRegistryTags()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IRegistry.class.getName();
|
IRegistry.class.getName();
|
||||||
|
@ -89,11 +132,19 @@ public class BukkitInitialization {
|
||||||
when(mockedServer.getVersion()).thenReturn(serverVersion + " (MC: " + releaseTarget + ")");
|
when(mockedServer.getVersion()).thenReturn(serverVersion + " (MC: " + releaseTarget + ")");
|
||||||
when(mockedServer.getBukkitVersion()).thenReturn(Versioning.getBukkitVersion());
|
when(mockedServer.getBukkitVersion()).thenReturn(Versioning.getBukkitVersion());
|
||||||
|
|
||||||
when(mockedServer.getItemFactory()).thenReturn(CraftItemFactory.instance());
|
|
||||||
when(mockedServer.isPrimaryThread()).thenReturn(true);
|
when(mockedServer.isPrimaryThread()).thenReturn(true);
|
||||||
|
when(mockedServer.getItemFactory()).thenReturn(CraftItemFactory.instance());
|
||||||
|
when(mockedServer.getUnsafe()).thenReturn(CraftMagicNumbers.INSTANCE);
|
||||||
|
when(mockedServer.getLootTable(any())).thenAnswer(invocation -> {
|
||||||
|
NamespacedKey key = invocation.getArgument(0);
|
||||||
|
return new CraftLootTable(key, dataPackResources.b() /* .getLootData() */ .getLootTable(CraftNamespacedKey.toMinecraft(key)));
|
||||||
|
});
|
||||||
|
when(mockedServer.getRegistry(any())).thenAnswer(invocation -> {
|
||||||
|
Class<Keyed> registryType = invocation.getArgument(0);
|
||||||
|
return CraftRegistry.createRegistry(registryType, registryCustom);
|
||||||
|
});
|
||||||
|
|
||||||
WorldServer nmsWorld = mock(WorldServer.class);
|
WorldServer nmsWorld = mock(WorldServer.class);
|
||||||
|
|
||||||
SpigotWorldConfig mockWorldConfig = mock(SpigotWorldConfig.class);
|
SpigotWorldConfig mockWorldConfig = mock(SpigotWorldConfig.class);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -109,8 +160,13 @@ public class BukkitInitialization {
|
||||||
List<World> worlds = Collections.singletonList(world);
|
List<World> worlds = Collections.singletonList(world);
|
||||||
when(mockedServer.getWorlds()).thenReturn(worlds);
|
when(mockedServer.getWorlds()).thenReturn(worlds);
|
||||||
|
|
||||||
// Inject this fake server
|
// Inject this fake server & our registry (must happen after server set)
|
||||||
Bukkit.setServer(mockedServer);
|
Bukkit.setServer(mockedServer);
|
||||||
|
CraftRegistry.setMinecraftRegistry(registryCustom);
|
||||||
|
|
||||||
|
// Init Enchantments
|
||||||
|
Enchantments.A.getClass();
|
||||||
|
Enchantment.stopAcceptingRegistrations();
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -503,7 +503,7 @@ public class PacketContainerTest {
|
||||||
|
|
||||||
WrappedRegistry registry = WrappedRegistry.getRegistry(MinecraftReflection.getMobEffectListClass());
|
WrappedRegistry registry = WrappedRegistry.getRegistry(MinecraftReflection.getMobEffectListClass());
|
||||||
Object effectList = assertInstanceOf(MobEffectList.class, packet.getStructures().read(0).getHandle());
|
Object effectList = assertInstanceOf(MobEffectList.class, packet.getStructures().read(0).getHandle());
|
||||||
assertEquals(effect.getType().getId(), registry.getId(effectList));
|
assertEquals(effect.getType().getId(), registry.getId(effectList) + 1); // +1 is correct, see CraftPotionEffectType
|
||||||
|
|
||||||
int e = 0;
|
int e = 0;
|
||||||
if (effect.isAmbient()) {
|
if (effect.isAmbient()) {
|
||||||
|
|
Loading…
Reference in New Issue