SPIGOT-7011, SPIGOT-7065: Overhaul of structures

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2022-07-01 20:41:04 +10:00
parent 8bf76d9868
commit 230282ea44
11 changed files with 397 additions and 57 deletions

View File

@@ -30,6 +30,7 @@ public abstract class AbstractTestingBase {
public static final List<Material> INVALIDATED_MATERIALS;
public static final DataPackResources DATA_PACK;
public static final IRegistryCustom.Dimension REGISTRY_CUSTOM;
static {
SharedConstants.tryDetectVersion();
@@ -37,11 +38,11 @@ public abstract class AbstractTestingBase {
// Set up resource manager
ResourceManager resourceManager = new ResourceManager(EnumResourcePackType.SERVER_DATA, Collections.singletonList(new ResourcePackVanilla(ResourcePackSourceVanilla.BUILT_IN_METADATA, "minecraft")));
// add tags and loot tables for unit tests
IRegistryCustom.Dimension registry = IRegistryCustom.builtinCopy().freeze();
REGISTRY_CUSTOM = IRegistryCustom.builtinCopy().freeze();
// Register vanilla pack
DATA_PACK = DataPackResources.loadResources(resourceManager, registry, CommandDispatcher.ServerType.DEDICATED, 0, MoreExecutors.directExecutor(), MoreExecutors.directExecutor()).join();
DATA_PACK = DataPackResources.loadResources(resourceManager, REGISTRY_CUSTOM, CommandDispatcher.ServerType.DEDICATED, 0, MoreExecutors.directExecutor(), MoreExecutors.directExecutor()).join();
// Bind tags
DATA_PACK.updateRegistryTags(registry);
DATA_PACK.updateRegistryTags(REGISTRY_CUSTOM);
DummyServer.setup();
DummyEnchantments.setup();

View File

@@ -10,6 +10,7 @@ import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Server;
import org.bukkit.craftbukkit.CraftLootTable;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.inventory.CraftItemFactory;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
@@ -97,6 +98,14 @@ public final class DummyServer implements InvocationHandler {
}
}
);
methods.put(Server.class.getMethod("getRegistry", Class.class),
new MethodHandler() {
@Override
public Object handle(DummyServer server, Object[] args) {
return CraftRegistry.createRegistry((Class) args[0], AbstractTestingBase.REGISTRY_CUSTOM);
}
}
);
Bukkit.setServer(Proxy.getProxyClass(Server.class.getClassLoader(), Server.class).asSubclass(Server.class).getConstructor(InvocationHandler.class).newInstance(new DummyServer()));
} catch (Throwable t) {
throw new Error(t);