Full reflection API refactoring

This commit is contained in:
Marc Baloup 2022-07-08 01:31:45 +02:00
parent 0d64285973
commit 276b1d323a
75 changed files with 2398 additions and 533 deletions

View File

@ -3,6 +3,7 @@ package fr.pandacube.lib.core.util;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
public class ThrowableUtil { public class ThrowableUtil {
@ -24,17 +25,7 @@ public class ThrowableUtil {
/**
* A supplier that can possibly throw a checked exception
*/
@FunctionalInterface
public interface SupplierException<T> {
public T get() throws Exception;
}
/** /**
* Wraps a {@link SupplierException} into a try catch. * Wraps a {@link SupplierException} into a try catch.
@ -46,22 +37,10 @@ public class ThrowableUtil {
try { try {
return supp.get(); return supp.get();
} catch (Exception e) { } catch (Exception e) {
if (e instanceof RuntimeException re) throw uncheck(e, false);
throw re;
throw new RuntimeException(e);
} }
} }
/**
* A runnable that can possibly throw a checked exception
*/
@FunctionalInterface
public interface RunnableException {
public void run() throws Exception;
}
/** /**
* Wraps a {@link RunnableException} into a try catch. * Wraps a {@link RunnableException} into a try catch.
* @param run the {@link RunnableException} to run. * @param run the {@link RunnableException} to run.
@ -71,10 +50,105 @@ public class ThrowableUtil {
try { try {
run.run(); run.run();
} catch (Exception e) { } catch (Exception e) {
if (e instanceof RuntimeException re) throw uncheck(e, false);
throw re;
throw new RuntimeException(e);
} }
} }
/**
* Wraps a {@link SupplierException} into a try catch.
* @param supp the {@link SupplierException} to run and get the value from.
* @return the value returned by the provided supplier.
* @throws RuntimeException if the provided {@link SupplierException} throws a checked exception.
*/
public static <T> T wrapReflectEx(SupplierException<T> supp) {
try {
return supp.get();
} catch (Exception e) {
throw uncheck(e, true);
}
}
/**
* Wraps a {@link RunnableException} into a try catch.
* @param run the {@link RunnableException} to run.
* @throws RuntimeException if the provided {@link RunnableException} throws a checked exception.
*/
public static void wrapReflectEx(RunnableException run) {
try {
run.run();
} catch (Exception e) {
throw uncheck(e, true);
}
}
/**
* A supplier that can possibly throw a checked exception
*/
@FunctionalInterface
public interface SupplierException<T> {
public T get() throws Exception;
}
/**
* A runnable that can possibly throw a checked exception
*/
@FunctionalInterface
public interface RunnableException {
public void run() throws Exception;
}
private static RuntimeException uncheck(Throwable t, boolean convertReflectionExceptionToError) {
if (t instanceof Error er) {
throw er;
}
if (t instanceof RuntimeException re)
return re;
if (convertReflectionExceptionToError) {
Error er = null;
if (t instanceof ClassNotFoundException ce) {
er = new NoClassDefFoundError();
er.initCause(ce);
}
else if (t instanceof IllegalAccessException ce) {
er = new IllegalAccessError();
er.initCause(ce);
}
else if (t instanceof NoSuchFieldException ce) {
er = new NoSuchFieldError();
er.initCause(ce);
}
else if (t instanceof NoSuchMethodException ce) {
er = new NoSuchMethodError();
er.initCause(ce);
}
else if (t instanceof InstantiationException ce) {
er = new InstantiationError();
er.initCause(ce);
}
else if (t instanceof IllegalAccessException ce) {
er = new IllegalAccessError();
er.initCause(ce);
}
if (er != null)
throw er;
if (t instanceof InvocationTargetException ce) {
Throwable cause = ce.getCause();
return uncheck(cause, false);
}
}
return new RuntimeException(t);
}
} }

View File

@ -1,17 +1,18 @@
package fr.pandacube.lib.paper; package fr.pandacube.lib.paper;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.WrapperRegistry;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import fr.pandacube.lib.paper.reflect.ReflectRegistry;
public class PandaLibPaper { public class PandaLibPaper {
private static Plugin plugin; private static Plugin plugin;
public static void init(Plugin plugin) { public static void init(Plugin plugin) {
PandaLibPaper.plugin = plugin; PandaLibPaper.plugin = plugin;
ReflectRegistry.init(); NMSReflect.init();
WrapperRegistry.init();
} }

View File

@ -43,7 +43,7 @@ public class NMSReflect {
private static boolean isInit = false; private static boolean isInit = false;
static void init() { public static void init() {
synchronized (NMSReflect.class) { synchronized (NMSReflect.class) {
if (isInit) if (isInit)

View File

@ -1,501 +0,0 @@
package fr.pandacube.lib.paper.reflect;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.UUID;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.mojang.brigadier.tree.CommandNode;
import fr.pandacube.lib.core.util.Log;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.core.util.Reflect.ReflectClass;
import fr.pandacube.lib.core.util.Reflect.ReflectConstructor;
import fr.pandacube.lib.core.util.Reflect.ReflectField;
import fr.pandacube.lib.core.util.Reflect.ReflectMethod;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
/**
* Collection of static properties to ease access to commonly used server internals and private class members.
*/
public class ReflectRegistry {
public static final class NMS {
public static final class SharedConstants {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.SharedConstants"));
public static final ReflectMethod<?> getCurrentVersion = wrapEx(() -> MAPPING.mojMethod("getCurrentVersion"));
public static final ReflectMethod<?> getProtocolVersion = wrapEx(() -> MAPPING.mojMethod("getProtocolVersion"));
}
public static final class ProgressListener {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.util.ProgressListener"));
}
public static final class WorldVersion {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.WorldVersion"));
}
public static final class DetectedVersion {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.DetectedVersion"));
}
public static final class DedicatedServer {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.DedicatedServer"));
public static final ReflectField<?> vanillaCommandDispatcher = wrapEx(() -> MAPPING.runtimeReflect().field("vanillaCommandDispatcher"));
public static final ReflectMethod<?> getLevelIdName = wrapEx(() -> MAPPING.mojMethod("getLevelIdName"));
public static final ReflectMethod<?> getProperties = wrapEx(() -> MAPPING.mojMethod("getProperties"));
}
public static final class Settings {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.Settings"));
public static final ReflectField<?> properties = wrapEx(() -> MAPPING.mojField("properties"));
}
public static final class DedicatedServerProperties {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.DedicatedServerProperties"));
}
public static final class DedicatedPlayerList {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.DedicatedPlayerList"));
}
public static final class Commands {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.Commands"));
public static final ReflectField<?> dispatcher = wrapEx(() -> MAPPING.mojField("dispatcher"));
}
public static final class Vec3 {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.phys.Vec3"));
}
public static final class Component {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.chat.Component"));
}
public static final class CommandSourceStack {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.CommandSourceStack"));
}
public static final class EntityArgument {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.EntityArgument"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(boolean.class, boolean.class));
}
public static final class EntitySelector {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.selector.EntitySelector"));
public static final ReflectMethod<?> findEntities = wrapEx(() -> MAPPING.mojMethod("findEntities", CommandSourceStack.MAPPING));
public static final ReflectMethod<?> findPlayers = wrapEx(() -> MAPPING.mojMethod("findPlayers", CommandSourceStack.MAPPING));
public static final ReflectMethod<?> findSingleEntity = wrapEx(() -> MAPPING.mojMethod("findSingleEntity", CommandSourceStack.MAPPING));
public static final ReflectMethod<?> findSinglePlayer = wrapEx(() -> MAPPING.mojMethod("findSinglePlayer", CommandSourceStack.MAPPING));
}
public static final class Entity {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.entity.Entity"));
public static final ReflectMethod<?> getBukkitEntity = wrapEx(() -> MAPPING.runtimeReflect().method("getBukkitEntity")); // spigot field
}
public static final class ComponentArgument {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.ComponentArgument"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor());
}
public static final class Vec3Argument {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.Vec3Argument"));
public static final ReflectMethod<?> vec3 = wrapEx(() -> MAPPING.mojMethod("vec3", boolean.class));
}
public static final class Coordinates {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.Coordinates"));
public static final ReflectMethod<?> getPosition = wrapEx(() -> MAPPING.mojMethod("getPosition", CommandSourceStack.MAPPING));
public static final ReflectMethod<?> getBlockPos = wrapEx(() -> MAPPING.mojMethod("getBlockPos", CommandSourceStack.MAPPING));
}
public static final class BlockPosArgument {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.BlockPosArgument"));
public static final ReflectMethod<?> blockPos = wrapEx(() -> MAPPING.mojMethod("blockPos"));
}
public static final class BlockPos {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.core.BlockPos"));
public static final ClassMapping MAPPING_SUPERCLASS = wrapEx(() -> NMSReflect.mojClass("net.minecraft.core.Vec3i"));
public static final ReflectMethod<?> getX = wrapEx(() -> MAPPING_SUPERCLASS.mojMethod("getX")); // these 3 methods are declared in the superclass
public static final ReflectMethod<?> getY = wrapEx(() -> MAPPING_SUPERCLASS.mojMethod("getY")); // so the mapping is only referenced in the superclass
public static final ReflectMethod<?> getZ = wrapEx(() -> MAPPING_SUPERCLASS.mojMethod("getZ"));
}
public static final class ChunkPos {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.ChunkPos"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(int.class, int.class));
}
public static final class ResourceLocationArgument {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.ResourceLocationArgument"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor());
}
public static final class ResourceLocation {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.resources.ResourceLocation"));
}
public static final class GameProfileArgument {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.GameProfileArgument"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor());
}
public static final class Level {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.Level"));
public static final ReflectMethod<?> getGameTime = wrapEx(() -> MAPPING.mojMethod("getGameTime"));
public static final ReflectField<?> paperConfig = wrapEx(() -> MAPPING.runtimeReflect().field("paperConfig")); // paper field
}
public static final class ServerLevel {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.level.ServerLevel"));
public static final ReflectMethod<?> getFreeMapId = wrapEx(() -> MAPPING.mojMethod("getFreeMapId"));
public static final ReflectMethod<?> save = wrapEx(() -> MAPPING.mojMethod("save", ProgressListener.MAPPING, boolean.class, boolean.class));
public static final ReflectMethod<?> getChunkSource = wrapEx(() -> MAPPING.mojMethod("getChunkSource"));
}
public static final class ServerChunkCache {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.level.ServerChunkCache"));
public static final ReflectField<?> chunkMap = wrapEx(() -> MAPPING.mojField("chunkMap"));
}
public static final class ChunkMap {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.level.ChunkMap"));
public static final ReflectField<?> updatingChunks = wrapEx(() -> MAPPING.runtimeReflect().field("updatingChunks")); // spigot/paper field
public static final ReflectField<?> autoSaveQueue = wrapEx(() -> MAPPING.runtimeReflect().field("autoSaveQueue")); // spigot/paper field
public static final ReflectField<?> level = wrapEx(() -> MAPPING.mojField("level"));
public static final ReflectField<?> pendingUnloads = wrapEx(() -> MAPPING.mojField("pendingUnloads"));
public static final ReflectField<?> toDrop = wrapEx(() -> MAPPING.mojField("toDrop"));
}
public static final class ChunkStorage {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.chunk.storage.ChunkStorage"));
public static final ReflectMethod<?> read = wrapEx(() -> MAPPING.mojMethod("read", ChunkPos.MAPPING));
public static final ReflectMethod<?> readSync = wrapEx(() -> MAPPING.runtimeReflect().method("readSync", ChunkPos.MAPPING.runtimeReflect().get())); // spigot/paper method
}
public static final class ServerPlayer {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.level.ServerPlayer"));
public static final ReflectField<?> connection = wrapEx(() -> MAPPING.mojField("connection"));
public static final ReflectMethod<?> hurt = wrapEx(() -> MAPPING.mojMethod("hurt", DamageSource.MAPPING, float.class));
public static final ReflectMethod<?> isTextFilteringEnabled = wrapEx(() -> MAPPING.mojMethod("isTextFilteringEnabled"));
public static final ReflectMethod<?> allowsListing = wrapEx(() -> MAPPING.mojMethod("allowsListing"));
}
public static final class DamageSource {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.damagesource.DamageSource"));
public static final ReflectField<?> OUT_OF_WORLD = wrapEx(() -> MAPPING.mojField("OUT_OF_WORLD"));
}
public static final class ServerGamePacketListenerImpl {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.network.ServerGamePacketListenerImpl"));
public static final ReflectMethod<?> sendPacket = wrapEx(() -> MAPPING.mojMethod("send", NMS.Protocol.Packet.MAPPING));
}
public static final class Protocol {
public static final class Packet {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.Packet"));
}
public static final class ClientboundGameEventPacket {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.game.ClientboundGameEventPacket"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(Type.MAPPING.runtimeClass(), float.class));
public static final ReflectField<?> RAIN_LEVEL_CHANGE = wrapEx(() -> MAPPING.mojField("RAIN_LEVEL_CHANGE"));
public static final ReflectField<?> THUNDER_LEVEL_CHANGE = wrapEx(() -> MAPPING.mojField("THUNDER_LEVEL_CHANGE"));
public static final class Type {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.game.ClientboundGameEventPacket$Type"));
public static final ReflectField<?> TYPES = wrapEx(() -> MAPPING.mojField("TYPES"));
}
}
public static final class ClientboundCustomPayloadPacket {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(ResourceLocation.MAPPING.runtimeClass(), FriendlyByteBuf.MAPPING.runtimeClass()));
public static final ReflectField<?> BRAND = wrapEx(() -> MAPPING.mojField("BRAND"));
}
}
public static final class FriendlyByteBuf {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.FriendlyByteBuf"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(Netty.ByteBuf.REFLECT.get()));
public static final ReflectMethod<?> writeUtf = wrapEx(() -> MAPPING.mojMethod("writeUtf", String.class));
}
public static final class Block {
public static final class BambooBlock {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.block.BambooBlock"));
public static final ReflectField<?> COLLISION_SHAPE = wrapEx(() -> MAPPING.mojField("COLLISION_SHAPE"));
}
}
public static final class AABB {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.phys.AABB"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(double.class, double.class, double.class, double.class, double.class, double.class));
}
public static final class SavedData {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.saveddata.SavedData"));
public static final ReflectMethod<?> setDirty = wrapEx(() -> MAPPING.mojMethod("setDirty"));
}
public static final class MapItemSavedData {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.saveddata.maps.MapItemSavedData"));
public static final ReflectField<?> colors = wrapEx(() -> MAPPING.mojField("colors"));
public static final ReflectField<?> locked = wrapEx(() -> MAPPING.mojField("locked"));
}
public static final class Nbt {
public static final class NbtIo {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.NbtIo"));
public static final ReflectMethod<?> readCompressed = wrapEx(() -> MAPPING.mojMethod("readCompressed", File.class));
public static final ReflectMethod<?> writeCompressed = wrapEx(() -> MAPPING.mojMethod("writeCompressed", CompoundTag.MAPPING, File.class));
}
public static final class Tag {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.Tag"));
public static final ReflectMethod<?> getAsString = wrapEx(() -> MAPPING.mojMethod("getAsString"));
}
public static final class StringTag {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.StringTag"));
}
public static final class CompoundTag {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.CompoundTag"));
public static final ReflectMethod<?> putBoolean = wrapEx(() -> MAPPING.mojMethod("putBoolean", String.class, boolean.class));
public static final ReflectMethod<?> putByte = wrapEx(() -> MAPPING.mojMethod("putByte", String.class, byte.class));
public static final ReflectMethod<?> putByteArray = wrapEx(() -> MAPPING.mojMethod("putByteArray", String.class, byte[].class));
public static final ReflectMethod<?> putByteArray_List = wrapEx(() -> MAPPING.mojMethod("putByteArray", String.class, List.class));
public static final ReflectMethod<?> putDouble = wrapEx(() -> MAPPING.mojMethod("putDouble", String.class, double.class));
public static final ReflectMethod<?> putFloat = wrapEx(() -> MAPPING.mojMethod("putFloat", String.class, float.class));
public static final ReflectMethod<?> putInt = wrapEx(() -> MAPPING.mojMethod("putInt", String.class, int.class));
public static final ReflectMethod<?> putIntArray = wrapEx(() -> MAPPING.mojMethod("putIntArray", String.class, int[].class));
public static final ReflectMethod<?> putIntArray_List = wrapEx(() -> MAPPING.mojMethod("putIntArray", String.class, List.class));
public static final ReflectMethod<?> putString = wrapEx(() -> MAPPING.mojMethod("putString", String.class, String.class));
public static final ReflectMethod<?> putUUID = wrapEx(() -> MAPPING.mojMethod("putUUID", String.class, UUID.class));
public static final ReflectMethod<?> putLong = wrapEx(() -> MAPPING.mojMethod("putLong", String.class, long.class));
public static final ReflectMethod<?> putLongArray = wrapEx(() -> MAPPING.mojMethod("putLongArray", String.class, long[].class));
public static final ReflectMethod<?> putLongArray_List = wrapEx(() -> MAPPING.mojMethod("putLongArray", String.class, List.class));
public static final ReflectMethod<?> putShort = wrapEx(() -> MAPPING.mojMethod("putShort", String.class, short.class));
public static final ReflectMethod<?> put = wrapEx(() -> MAPPING.mojMethod("put", String.class, Tag.MAPPING));
public static final ReflectMethod<?> getTagType = wrapEx(() -> MAPPING.mojMethod("getTagType", String.class));
public static final ReflectMethod<?> getByte = wrapEx(() -> MAPPING.mojMethod("getByte", String.class));
public static final ReflectMethod<?> getShort = wrapEx(() -> MAPPING.mojMethod("getShort", String.class));
public static final ReflectMethod<?> getInt = wrapEx(() -> MAPPING.mojMethod("getInt", String.class));
public static final ReflectMethod<?> getLong = wrapEx(() -> MAPPING.mojMethod("getLong", String.class));
public static final ReflectMethod<?> getFloat = wrapEx(() -> MAPPING.mojMethod("getFloat", String.class));
public static final ReflectMethod<?> getDouble = wrapEx(() -> MAPPING.mojMethod("getDouble", String.class));
public static final ReflectMethod<?> getString = wrapEx(() -> MAPPING.mojMethod("getString", String.class));
public static final ReflectMethod<?> getByteArray = wrapEx(() -> MAPPING.mojMethod("getByteArray", String.class));
public static final ReflectMethod<?> getIntArray = wrapEx(() -> MAPPING.mojMethod("getIntArray", String.class));
public static final ReflectMethod<?> getLongArray = wrapEx(() -> MAPPING.mojMethod("getLongArray", String.class));
public static final ReflectMethod<?> getCompound = wrapEx(() -> MAPPING.mojMethod("getCompound", String.class));
public static final ReflectMethod<?> getBoolean = wrapEx(() -> MAPPING.mojMethod("getBoolean", String.class));
public static final ReflectMethod<?> get = wrapEx(() -> MAPPING.mojMethod("get", String.class));
public static final ReflectMethod<?> getAllKeys = wrapEx(() -> MAPPING.mojMethod("getAllKeys"));
public static final ReflectMethod<?> entries = wrapEx(() -> MAPPING.mojMethod("entries"));
public static final ReflectMethod<?> size = wrapEx(() -> MAPPING.mojMethod("size"));
public static final ReflectMethod<?> contains = wrapEx(() -> MAPPING.mojMethod("contains", String.class));
}
}
}
public static final class OBC {
public static final class CraftServer {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("CraftServer"));
public static final ReflectMethod<?> getServer = wrapEx(() -> REFLECT.method("getServer"));
public static final ReflectMethod<?> getHandle = wrapEx(() -> REFLECT.method("getHandle"));
}
public static final class VanillaCommandWrapper {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("command.VanillaCommandWrapper"));
@SuppressWarnings("unchecked")
public static final ReflectConstructor<? extends Command> CONSTRUTOR =
(ReflectConstructor<? extends Command>) wrapEx(() -> REFLECT.constructor(
NMS.Commands.MAPPING.runtimeClass(),
CommandNode.class
));
public static final ReflectField<?> vanillaCommand = wrapEx(() -> REFLECT.field("vanillaCommand"));
public static final ReflectMethod<?> getListener = wrapEx(() -> REFLECT.method("getListener", CommandSender.class));
}
public static final class CraftNamespacedKey {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("util.CraftNamespacedKey"));
public static final ReflectMethod<?> toMinecraft = wrapEx(() -> REFLECT.method("toMinecraft", NamespacedKey.class));
public static final ReflectMethod<?> fromMinecraft = wrapEx(() -> REFLECT.method("fromMinecraft", NMS.ResourceLocation.MAPPING.runtimeClass()));
}
public static final class CraftVector {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("util.CraftVector"));
public static final ReflectMethod<?> toBukkit_vec3 = wrapEx(() -> REFLECT.method("toBukkit", NMS.Vec3.MAPPING.runtimeClass()));
}
public static final class CraftWorld {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("CraftWorld"));
public static final ReflectMethod<?> getHandle = wrapEx(() -> REFLECT.method("getHandle"));
}
public static final class CraftPlayer {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("entity.CraftPlayer"));
public static final ReflectMethod<?> getHandle = wrapEx(() -> REFLECT.method("getHandle"));
}
public static final class CraftMapView {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("map.CraftMapView"));
public static final ReflectField<?> worldMap = wrapEx(() -> REFLECT.field("worldMap"));
public static final ReflectMethod<?> render = wrapEx(() -> REFLECT.method("render", CraftPlayer.REFLECT.get()));
}
public static final class RenderData {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("map.RenderData"));
public static final ReflectField<?> buffer = wrapEx(() -> REFLECT.field("buffer"));
}
}
public static final class Paper {
public static final class PaperAdventure {
public static final ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.adventure.PaperAdventure"));
public static final ReflectMethod<?> asAdventure = wrapEx(() -> REFLECT.method("asAdventure", NMS.Component.MAPPING.runtimeClass()));
}
public static final class AABBVoxelShape {
public static final ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.voxel.AABBVoxelShape"));
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> REFLECT.constructor(NMS.AABB.MAPPING.runtimeClass()));
}
public static final class QueuedChangesMapLong2Object {
public static final ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object"));
public static final ReflectMethod<?> getVisibleMap = wrapEx(() -> REFLECT.method("getVisibleMap"));
}
public static final class WorldConfiguration {
public static final ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.configuration.WorldConfiguration"));
public static final ReflectField<?> chunks = wrapEx(() -> REFLECT.field("chunks"));
public static final class Chunks {
public static final ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.configuration.WorldConfiguration$Chunks"));
public static final ReflectField<?> autoSavePeriod = wrapEx(() -> REFLECT.field("autoSaveInterval"));
}
}
public static final class FallbackValue_Int {
public static final ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.configuration.type.fallback.FallbackValue$Int"));
public static final ReflectMethod<?> value = wrapEx(() -> REFLECT.method("value"));
}
}
public static final class Brigadier {
public static final class CommandNode {
public static final ReflectClass<?> REFLECT = Reflect.ofClass(com.mojang.brigadier.tree.CommandNode.class);
public static final ReflectMethod<?> removeCommand = wrapEx(() -> REFLECT.method("removeCommand", String.class));
}
}
public static final class Netty {
public static final class ByteBuf {
public static final ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.netty.buffer.ByteBuf"));
}
public static final class Unpooled {
public static final ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.netty.buffer.Unpooled"));
public static final ReflectMethod<?> buffer = wrapEx(() -> REFLECT.method("buffer"));
}
}
/*
* Initialization stuff
*/
public static void init() {
NMSReflect.init();
initRecursively(ReflectRegistry.class);
}
private static void initRecursively(Class<?> cl) {
try {
for (Field f : Reflect.ofClass(cl).get().getDeclaredFields()) {
if (Modifier.isStatic(f.getModifiers()))
f.get(null);
}
} catch (Throwable t) {
if (t instanceof ExceptionInInitializerError eiie && eiie.getCause() != null) {
t = eiie.getCause();
}
Log.severe("Error while initilizing a ReflectRegistry entry at " + cl.getName(), t);
}
for (Class<?> declaredClass : cl.getDeclaredClasses()) {
initRecursively(declaredClass);
}
}
}

View File

@ -20,7 +20,7 @@ public class Type implements Comparable<Type> {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj != null && obj instanceof Type ot && type.equals(ot.type) && arrayDepth == ot.arrayDepth; return obj instanceof Type ot && type.equals(ot.type) && arrayDepth == ot.arrayDepth;
} }
@Override @Override
public int hashCode() { public int hashCode() {

View File

@ -0,0 +1,16 @@
package fr.pandacube.lib.paper.reflect.wrapper;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicate a concrete wrapper class that implements the annotated interface or abstract class, in case there is no
* proper wrapper for a provided runtime object.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ConcreteWrapper {
Class<? extends ReflectWrapper> value();
}

View File

@ -0,0 +1,183 @@
package fr.pandacube.lib.paper.reflect.wrapper;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
import java.util.function.Supplier;
import static fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper.unwrap;
public class ReflectListWrapper<W extends ReflectWrapperI> extends AbstractList<W> implements ReflectWrapperTypedI<List<Object>> {
private final List<Object> wrappedList;
private final Class<W> expectedWrapperClass;
/* package */ ReflectListWrapper(Class<W> expectedWrapperClass) {
this(ArrayList::new, expectedWrapperClass);
}
/* package */
@SuppressWarnings("unchecked")
ReflectListWrapper(Supplier<List<?>> listCreator, Class<W> expectedWrapperClass) {
this((List<Object>) (listCreator == null ? new ArrayList<>() : listCreator.get()), expectedWrapperClass);
}
/* package */ ReflectListWrapper(List<Object> wrappedList, Class<W> expectedWrapperClass) {
this.wrappedList = Objects.requireNonNull(wrappedList);
this.expectedWrapperClass = expectedWrapperClass;
}
@SuppressWarnings("unchecked")
@Override
public Class<List<Object>> __getRuntimeClass() {
return (Class<List<Object>>) wrappedList.getClass();
}
@Override
public List<Object> __getRuntimeInstance() {
return wrappedList;
}
private W wrap(Object el) {
return ReflectWrapper.wrap(el, expectedWrapperClass);
}
@Override
public W get(int index) {
return wrap(wrappedList.get(index));
}
@Override
public int size() {
return wrappedList.size();
}
@Override
public boolean add(W w) {
return wrappedList.add(unwrap(w));
}
@Override
public W set(int index, W element) {
return wrap(wrappedList.set(index, unwrap(element)));
}
@Override
public void add(int index, W element) {
wrappedList.add(index, unwrap(element));
}
@Override
public W remove(int index) {
return wrap(wrappedList.remove(index));
}
@Override
public int indexOf(Object o) {
return wrappedList.indexOf(o instanceof ReflectWrapperI w ? w.__getRuntimeInstance() : o);
}
@Override
public int lastIndexOf(Object o) {
return wrappedList.lastIndexOf(o instanceof ReflectWrapperI w ? w.__getRuntimeInstance() : o);
}
@Override
public void clear() {
wrappedList.clear();
}
@Override
public Iterator<W> iterator() {
return new Iterator<W>() {
final Iterator<Object> wrappedIt = wrappedList.iterator();
@Override
public boolean hasNext() {
return wrappedIt.hasNext();
}
@Override
public W next() {
return wrap(wrappedIt.next());
}
@Override
public void remove() {
wrappedIt.remove();
}
};
}
@Override
public ListIterator<W> listIterator() {
return listIterator(0);
}
@Override
public ListIterator<W> listIterator(int index) {
return new ListIterator<W>() {
final ListIterator<Object> wrappedIt = wrappedList.listIterator(index);
@Override
public boolean hasNext() {
return wrappedIt.hasNext();
}
@Override
public W next() {
return wrap(wrappedIt.next());
}
@Override
public boolean hasPrevious() {
return wrappedIt.hasPrevious();
}
@Override
public W previous() {
return wrap(wrappedIt.previous());
}
@Override
public int nextIndex() {
return wrappedIt.nextIndex();
}
@Override
public int previousIndex() {
return wrappedIt.previousIndex();
}
@Override
public void remove() {
wrappedIt.remove();
}
@Override
public void set(W w) {
wrappedIt.set(unwrap(w));
}
@Override
public void add(W w) {
wrappedIt.add(unwrap(w));
}
};
}
@Override
public List<W> subList(int fromIndex, int toIndex) {
return new ReflectListWrapper<>(wrappedList.subList(fromIndex, toIndex), expectedWrapperClass);
}
@Override
public boolean equals(Object o) {
return wrappedList.equals(o);
}
@Override
public int hashCode() {
return wrappedList.hashCode();
}
}

View File

@ -0,0 +1,111 @@
package fr.pandacube.lib.paper.reflect.wrapper;
import com.google.common.collect.MapMaker;
import fr.pandacube.lib.core.util.Reflect;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public abstract class ReflectWrapper implements ReflectWrapperI {
private static final Map<Object, ReflectWrapperI> objectWrapperCache = new MapMaker().weakKeys().makeMap();
public static Object unwrap(ReflectWrapperI wr) {
return wr == null ? null : wr.__getRuntimeInstance();
}
public static <T> T unwrap(ReflectWrapperTypedI<T> wr) {
return wr == null ? null : wr.__getRuntimeInstance();
}
public static <W extends ReflectWrapperI> W wrap(Object runtimeObj) {
return wrap(runtimeObj, null);
}
public static <W extends ReflectWrapperI> W wrap(Object runtimeObj, Class<W> expectedWrapperClass) {
if (runtimeObj == null)
return null;
synchronized (objectWrapperCache) {
if (objectWrapperCache.containsKey(runtimeObj)) {
ReflectWrapperI wrapper = objectWrapperCache.get(runtimeObj);
if (expectedWrapperClass == null || expectedWrapperClass.isInstance(wrapper)) {
@SuppressWarnings("unchecked")
W wr = (W) wrapper;
return wr;
}
}
Class<?> runtimeClass = runtimeObj.getClass();
Class<?> expectedRuntimeClass = (expectedWrapperClass == null) ? null : WrapperRegistry.getRuntimeClassOfWrapperClass(expectedWrapperClass);
if (expectedRuntimeClass != null && !expectedRuntimeClass.isAssignableFrom(runtimeClass)) {
throw new ClassCastException("Runtime class " + runtimeClass + " is not a sub-class or a sub-interface of expected runtime class " + expectedRuntimeClass + "" +
" (expected wrapper class " + expectedWrapperClass + ").");
}
Class<? extends ReflectWrapperI> wrapperClass = WrapperRegistry.getWrapperOfRuntimeClass(runtimeClass);
if (wrapperClass == null) {
// trying to use the provided expectedWrapperClass
if (expectedWrapperClass == null || expectedRuntimeClass == null) { // implicitly: expectedWrapperClass is null or it has no corresponding runtimeClass
// TODO try to search among all registered wrapper class for one that can support the provided object
throw new IllegalArgumentException("No wrapper available to wrap an instance of runtime class " + runtimeClass + "." +
(expectedWrapperClass != null ? (" Expected wrapper class " + expectedWrapperClass + " is also not valid.") : ""));
}
wrapperClass = expectedWrapperClass;
}
if (expectedWrapperClass != null && !expectedWrapperClass.isAssignableFrom(wrapperClass)) {
throw new ClassCastException("Wrapper class " + wrapperClass + " is not a sub-class or a sub-interface of expected wrapper class" + expectedWrapperClass);
}
Reflect.ReflectConstructor<? extends ReflectWrapperI> constructor = WrapperRegistry.getWrapperConstructorOfWrapperClass(wrapperClass);
if (constructor == null) {
throw new IllegalStateException("Unable to find a constructor to instanciate " + wrapperClass + " to wrap an instance of " + runtimeObj);
}
ReflectWrapperI wrapper = wrapEx(() -> constructor.instanciate(runtimeObj));
// added to cache by constructor
@SuppressWarnings("unchecked")
W wr = (W) wrapper;
return wr;
}
}
public static <W extends ReflectWrapperI> ReflectListWrapper<W> wrapList(List<Object> runtimeList, Class<W> expectedWrapperClass) {
return new ReflectListWrapper<>(runtimeList, expectedWrapperClass);
}
protected final Object reflectObject;
protected ReflectWrapper(Object obj) {
Objects.requireNonNull(obj);
if (!__getRuntimeClass().isInstance(obj)) {
throw new ClassCastException(obj.getClass() + " object is not instanceof " + __getRuntimeClass());
}
reflectObject = obj;
objectWrapperCache.put(obj, this);
}
@Override
public Object __getRuntimeInstance() {
return reflectObject;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ReflectWrapper wr) {
return Objects.equals(reflectObject, wr.reflectObject);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(reflectObject);
}
}

View File

@ -0,0 +1,12 @@
package fr.pandacube.lib.paper.reflect.wrapper;
public interface ReflectWrapperI {
default Class<?> __getRuntimeClass() {
return WrapperRegistry.getRuntimeClassOfWrapperClass(getClass());
}
Object __getRuntimeInstance();
}

View File

@ -0,0 +1,19 @@
package fr.pandacube.lib.paper.reflect.wrapper;
public abstract class ReflectWrapperTyped<T> extends ReflectWrapper implements ReflectWrapperTypedI<T> {
protected ReflectWrapperTyped(Object obj) {
super(obj);
}
@Override
public Class<? extends T> __getRuntimeClass() {
return ReflectWrapperTypedI.super.__getRuntimeClass();
}
@SuppressWarnings("unchecked")
@Override
public T __getRuntimeInstance() {
return (T) super.__getRuntimeInstance();
}
}

View File

@ -0,0 +1,12 @@
package fr.pandacube.lib.paper.reflect.wrapper;
public interface ReflectWrapperTypedI<T> extends ReflectWrapperI {
@SuppressWarnings("unchecked")
@Override
default Class<? extends T> __getRuntimeClass() {
return (Class<? extends T>) ReflectWrapperI.super.__getRuntimeClass();
}
@Override
T __getRuntimeInstance();
}

View File

@ -0,0 +1,236 @@
package fr.pandacube.lib.paper.reflect.wrapper;
import fr.pandacube.lib.core.util.Log;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.core.util.Reflect.ReflectConstructor;
import fr.pandacube.lib.paper.reflect.wrapper.brigadier.CommandNode;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftMapView;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftNamespacedKey;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftPlayer;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftServer;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftVector;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftWorld;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.RenderData;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.VanillaCommandWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.DetectedVersion;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.SharedConstants;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.WorldVersion;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.BlockPosArgument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.CommandSourceStack;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Commands;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.ComponentArgument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Coordinates;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.EntityArgument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.EntitySelector;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.GameProfileArgument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.ResourceLocationArgument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Vec3Argument;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.BlockPos;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.Vec3i;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.NbtIo;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.StringTag;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.Tag;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.FriendlyByteBuf;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.chat.Component;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.ClientboundCustomPayloadPacket;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.ClientboundGameEventPacket;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.Packet;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.resources.ResourceLocation;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ChunkMap;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerChunkCache;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerGamePacketListenerImpl;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerLevel;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerPlayer;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.util.ProgressListener;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.AABB;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ChunkPos;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ChunkStorage;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSource;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Entity;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Level;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.MapItemSavedData;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.SavedData;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Vec3;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block.BambooBlock;
import fr.pandacube.lib.paper.reflect.wrapper.netty.ByteBuf;
import fr.pandacube.lib.paper.reflect.wrapper.netty.Unpooled;
import fr.pandacube.lib.paper.reflect.wrapper.paper.AABBVoxelShape;
import fr.pandacube.lib.paper.reflect.wrapper.paper.PaperAdventure;
import fr.pandacube.lib.paper.reflect.wrapper.paper.QueuedChangesMapLong2Object;
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.FallbackValue_Int;
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.WorldConfiguration;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
public class WrapperRegistry {
public static void init() {
// craftbukkit
initWrapper(CommandNode.class, CommandNode.REFLECT.get());
// craftbukkit
initWrapper(CraftMapView.class, CraftMapView.REFLECT.get());
initWrapper(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get());
initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get());
initWrapper(CraftServer.class, CraftServer.REFLECT.get());
initWrapper(CraftVector.class, CraftVector.REFLECT.get());
initWrapper(CraftWorld.class, CraftWorld.REFLECT.get());
initWrapper(RenderData.class, RenderData.REFLECT.get());
initWrapper(VanillaCommandWrapper.class, VanillaCommandWrapper.REFLECT.get());
// minecraft.commands
initWrapper(BlockPosArgument.class, BlockPosArgument.MAPPING.runtimeClass());
initWrapper(Commands.class, Commands.MAPPING.runtimeClass());
initWrapper(CommandSourceStack.class, CommandSourceStack.MAPPING.runtimeClass());
initWrapper(ComponentArgument.class, ComponentArgument.MAPPING.runtimeClass());
initWrapper(Coordinates.class, Coordinates.MAPPING.runtimeClass());
initWrapper(EntityArgument.class, EntityArgument.MAPPING.runtimeClass());
initWrapper(EntitySelector.class, EntitySelector.MAPPING.runtimeClass());
initWrapper(GameProfileArgument.class, GameProfileArgument.MAPPING.runtimeClass());
initWrapper(ResourceLocationArgument.class, ResourceLocationArgument.MAPPING.runtimeClass());
initWrapper(Vec3Argument.class, Vec3Argument.MAPPING.runtimeClass());
// minecraft.core
initWrapper(BlockPos.class, BlockPos.MAPPING.runtimeClass());
initWrapper(Vec3i.class, Vec3i.MAPPING.runtimeClass());
// minecraft.nbt
initWrapper(CompoundTag.class, CompoundTag.MAPPING.runtimeClass());
initWrapper(NbtIo.class, NbtIo.MAPPING.runtimeClass());
initWrapper(StringTag.class, StringTag.MAPPING.runtimeClass());
initWrapper(Tag.class, Tag.MAPPING.runtimeClass());
// minecraft.network.chat
initWrapper(Component.class, Component.MAPPING.runtimeClass());
// minecraft.network.protocol
initWrapper(ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket.MAPPING.runtimeClass());
initWrapper(ClientboundGameEventPacket.class, ClientboundGameEventPacket.MAPPING.runtimeClass());
initWrapper(ClientboundGameEventPacket.Type.class, ClientboundGameEventPacket.Type.MAPPING.runtimeClass());
initWrapper(Packet.class, Packet.MAPPING.runtimeClass());
// minecraft.network
initWrapper(FriendlyByteBuf.class, FriendlyByteBuf.MAPPING.runtimeClass());
// minecraft.resources
initWrapper(ResourceLocation.class, ResourceLocation.MAPPING.runtimeClass());
// minecraft.server
initWrapper(ChunkMap.class, ChunkMap.MAPPING.runtimeClass());
initWrapper(ServerChunkCache.class, ServerChunkCache.MAPPING.runtimeClass());
initWrapper(ServerGamePacketListenerImpl.class, ServerGamePacketListenerImpl.MAPPING.runtimeClass());
initWrapper(ServerLevel.class, ServerLevel.MAPPING.runtimeClass());
initWrapper(ServerPlayer.class, ServerPlayer.MAPPING.runtimeClass());
// minecraft.util
initWrapper(ProgressListener.class, ProgressListener.MAPPING.runtimeClass());
// minecraft.world.block
initWrapper(BambooBlock.class, BambooBlock.MAPPING.runtimeClass());
// minecraft.world
initWrapper(AABB.class, AABB.MAPPING.runtimeClass());
initWrapper(ChunkPos.class, ChunkPos.MAPPING.runtimeClass());
initWrapper(ChunkStorage.class, ChunkStorage.MAPPING.runtimeClass());
initWrapper(DamageSource.class, DamageSource.MAPPING.runtimeClass());
initWrapper(Entity.class, Entity.MAPPING.runtimeClass());
initWrapper(Level.class, Level.MAPPING.runtimeClass());
initWrapper(MapItemSavedData.class, MapItemSavedData.MAPPING.runtimeClass());
initWrapper(SavedData.class, SavedData.MAPPING.runtimeClass());
initWrapper(Vec3.class, Vec3.MAPPING.runtimeClass());
initWrapper(VoxelShape.class, VoxelShape.MAPPING.runtimeClass());
// minecraft
initWrapper(DetectedVersion.class, DetectedVersion.MAPPING.runtimeClass());
initWrapper(SharedConstants.class, SharedConstants.MAPPING.runtimeClass());
initWrapper(WorldVersion.class, WorldVersion.MAPPING.runtimeClass());
// netty
initWrapper(ByteBuf.class, ByteBuf.REFLECT.get());
initWrapper(Unpooled.class, Unpooled.REFLECT.get());
// paper.configuration
initWrapper(FallbackValue_Int.class, FallbackValue_Int.REFLECT.get());
initWrapper(WorldConfiguration.class, WorldConfiguration.REFLECT.get());
initWrapper(WorldConfiguration.Chunks.class, WorldConfiguration.Chunks.REFLECT.get());
// paper
initWrapper(AABBVoxelShape.class, AABBVoxelShape.REFLECT.get());
initWrapper(PaperAdventure.class, PaperAdventure.REFLECT.get());
initWrapper(QueuedChangesMapLong2Object.class, QueuedChangesMapLong2Object.REFLECT.get());
}
/* package */ static Class<? extends ReflectWrapperI> getWrapperOfRuntimeClass(Class<?> runtime) {
RegistryEntry e = WRAPPER_DATA_BY_RUNTIME_CLASS.get(runtime);
return e == null ? null : e.wrapperClass;
}
/* package */ static Class<?> getRuntimeClassOfWrapperClass(Class<? extends ReflectWrapperI> wrapperClass) {
RegistryEntry e = WRAPPER_DATA_BY_WRAPPER_CLASS.get(wrapperClass);
return e == null ? null : e.runtimeClass;
}
/* package */ static ReflectConstructor<? extends ReflectWrapperI> getWrapperConstructorOfWrapperClass(Class<? extends ReflectWrapperI> wrapperClass) {
RegistryEntry e = WRAPPER_DATA_BY_WRAPPER_CLASS.get(wrapperClass);
return e == null ? null : e.objectWrapperConstructor;
}
private static final Map<Class<?>, RegistryEntry> WRAPPER_DATA_BY_RUNTIME_CLASS = new HashMap<>();
private static final Map<Class<? extends ReflectWrapperI>, RegistryEntry> WRAPPER_DATA_BY_WRAPPER_CLASS = new HashMap<>();
public static void initWrapper(Class<? extends ReflectWrapperI> wrapper, Class<?> runtime) {
Class<? extends ReflectWrapperI> concreteWrapper = wrapper;
ReflectConstructor<? extends ReflectWrapperI> objectWrapperConstructor;
if (wrapper.isInterface() || Modifier.isAbstract(wrapper.getModifiers())) {
ConcreteWrapper concreteWrapperAnnotation = wrapper.getAnnotation(ConcreteWrapper.class);
if (concreteWrapperAnnotation == null || concreteWrapperAnnotation.value() == null) {
Log.severe("The provided non-concrete (interface or abstract class) wrapper " + wrapper + " does not" +
" provide any concrete wrapper.");
return;
}
concreteWrapper = concreteWrapperAnnotation.value();
if (!wrapper.isAssignableFrom(concreteWrapper)) {
Log.severe("The concrete wrapper " + concreteWrapper + " does not extends or implements " + wrapper + ".");
return;
}
}
try {
objectWrapperConstructor = Reflect.ofClass(concreteWrapper).constructor(Object.class);
} catch (NoSuchMethodException e) {
Log.severe("The wrapper " + concreteWrapper + " does not provide a constructor that takes a unique" +
" Object parameter.", e);
return;
}
RegistryEntry e = new RegistryEntry(runtime, wrapper, concreteWrapper, objectWrapperConstructor);
WRAPPER_DATA_BY_RUNTIME_CLASS.put(runtime, e);
WRAPPER_DATA_BY_WRAPPER_CLASS.put(wrapper, e);
if (concreteWrapper != wrapper) {
WRAPPER_DATA_BY_WRAPPER_CLASS.put(concreteWrapper, e);
}
}
private static class RegistryEntry {
Class<?> runtimeClass;
Class<? extends ReflectWrapperI> wrapperClass;
Class<? extends ReflectWrapperI> concreteWrapperClass;
ReflectConstructor<? extends ReflectWrapperI> objectWrapperConstructor;
public RegistryEntry(Class<?> runtimeClass, Class<? extends ReflectWrapperI> wrapperClass, Class<? extends ReflectWrapperI> concreteWrapperClass, ReflectConstructor<? extends ReflectWrapperI> objectWrapperConstructor) {
this.runtimeClass = runtimeClass;
this.wrapperClass = wrapperClass;
this.concreteWrapperClass = concreteWrapperClass;
this.objectWrapperConstructor = objectWrapperConstructor;
}
}
}

View File

@ -0,0 +1,21 @@
package fr.pandacube.lib.paper.reflect.wrapper.brigadier;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class CommandNode<S> extends ReflectWrapperTyped<com.mojang.brigadier.tree.CommandNode<S>> {
public static final Reflect.ReflectClass<?> REFLECT = Reflect.ofClass(com.mojang.brigadier.tree.CommandNode.class);
private static final Reflect.ReflectMethod<?> removeCommand = wrapEx(() -> REFLECT.method("removeCommand", String.class));
public void removeCommand(String cmd) {
wrapReflectEx(() -> removeCommand.invoke(__getRuntimeInstance(), cmd));
}
protected CommandNode(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,37 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.MapItemSavedData;
import org.bukkit.entity.Player;
import org.bukkit.map.MapView;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class CraftMapView extends ReflectWrapperTyped<MapView> {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("map.CraftMapView"));
public static final Reflect.ReflectField<?> worldMap = wrapEx(() -> REFLECT.field("worldMap"));
public static final Reflect.ReflectMethod<?> render = wrapEx(() -> REFLECT.method("render", CraftPlayer.REFLECT.get()));
protected CraftMapView(Object obj) {
super(obj);
}
public RenderData render(Player player) {
return wrap(wrapReflectEx(() -> render.invoke(__getRuntimeInstance(), player)), RenderData.class);
}
public RenderData render(CraftPlayer player) {
return render(unwrap(player));
}
public MapItemSavedData worldMap() {
return wrap(wrapReflectEx(() -> worldMap.getValue(__getRuntimeInstance())), MapItemSavedData.class);
}
public void worldMap(MapItemSavedData data) {
wrapReflectEx(() -> worldMap.setValue(__getRuntimeInstance(), unwrap(data)));
}
}

View File

@ -0,0 +1,28 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.resources.ResourceLocation;
import org.bukkit.NamespacedKey;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class CraftNamespacedKey extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("util.CraftNamespacedKey"));
public static final Reflect.ReflectMethod<?> toMinecraft = wrapEx(() -> REFLECT.method("toMinecraft", NamespacedKey.class));
public static final Reflect.ReflectMethod<?> fromMinecraft = wrapEx(() -> REFLECT.method("fromMinecraft", ResourceLocation.MAPPING.runtimeClass()));
public static ResourceLocation toMinecraft(NamespacedKey key) {
return wrap(wrapReflectEx(() -> toMinecraft.invokeStatic(key)), ResourceLocation.class);
}
public static NamespacedKey fromMinecraft(ResourceLocation key) {
return (NamespacedKey) wrapReflectEx(() -> toMinecraft.invokeStatic(unwrap(key)));
}
protected CraftNamespacedKey(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,23 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerPlayer;
import org.bukkit.entity.Player;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class CraftPlayer extends ReflectWrapperTyped<Player> {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("entity.CraftPlayer"));
public static final Reflect.ReflectMethod<?> getHandle = wrapEx(() -> REFLECT.method("getHandle"));
public ServerPlayer getHandle() {
return wrap(wrapReflectEx(() -> getHandle.invoke(__getRuntimeInstance())), ServerPlayer.class);
}
protected CraftPlayer(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,29 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedPlayerList;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedServer;
import org.bukkit.Server;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class CraftServer extends ReflectWrapperTyped<Server> {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("CraftServer"));
public static final Reflect.ReflectMethod<?> getServer = wrapEx(() -> REFLECT.method("getServer"));
public static final Reflect.ReflectMethod<?> getHandle = wrapEx(() -> REFLECT.method("getHandle"));
public DedicatedServer getServer() {
return wrap(wrapReflectEx(() -> getServer.invoke(__getRuntimeInstance())), DedicatedServer.class);
}
public DedicatedPlayerList getHandle() {
return wrap(wrapReflectEx(() -> getHandle.invoke(__getRuntimeInstance())), DedicatedPlayerList.class);
}
protected CraftServer(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,40 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.BlockPos;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Vec3;
import org.bukkit.util.Vector;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class CraftVector extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("util.CraftVector"));
public static final Reflect.ReflectMethod<?> toBukkit_Vec3 = wrapEx(() -> REFLECT.method("toBukkit", Vec3.MAPPING.runtimeClass()));
public static final Reflect.ReflectMethod<?> toBukkit_BlockPos = wrapEx(() -> REFLECT.method("toBukkit", BlockPos.MAPPING.runtimeClass()));
public static final Reflect.ReflectMethod<?> toNMS = wrapEx(() -> REFLECT.method("toNMS", Vector.class));
public static final Reflect.ReflectMethod<?> toBlockPos = wrapEx(() -> REFLECT.method("toNMS", Vector.class));
public static Vector toBukkit(Vec3 nms) {
return (Vector) wrapReflectEx(() -> toBukkit_Vec3.invokeStatic(unwrap(nms)));
}
public static Vector toBukkit(BlockPos blockPos) {
return (Vector) wrapReflectEx(() -> toBukkit_BlockPos.invokeStatic(unwrap(blockPos)));
}
public static Vec3 toNMS(Vector bukkit) {
return wrap(wrapReflectEx(() -> toNMS.invokeStatic(bukkit)), Vec3.class);
}
public static BlockPos toBlockPos(Vector bukkit) {
return wrap(wrapReflectEx(() -> toBlockPos.invokeStatic(bukkit)), BlockPos.class);
}
protected CraftVector(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,23 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerLevel;
import org.bukkit.World;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class CraftWorld extends ReflectWrapperTyped<World> {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("CraftWorld"));
public static final Reflect.ReflectMethod<?> getHandle = wrapEx(() -> REFLECT.method("getHandle"));
public ServerLevel getHandle() {
return wrap(wrapReflectEx(() -> getHandle.invoke(__getRuntimeInstance())), ServerLevel.class);
}
protected CraftWorld(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,25 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class RenderData extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("map.RenderData"));
private static final Reflect.ReflectField<?> buffer = wrapEx(() -> REFLECT.field("buffer"));
protected RenderData(Object obj) {
super(obj);
}
public byte[] buffer() {
return (byte[]) wrapReflectEx(() -> buffer.getValue(__getRuntimeInstance()));
}
public void buffer(byte[] buff) {
wrapReflectEx(() -> buffer.setValue(__getRuntimeInstance(), buff));
}
}

View File

@ -0,0 +1,37 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import com.mojang.brigadier.tree.CommandNode;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Commands;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class VanillaCommandWrapper extends ReflectWrapperTyped<BukkitCommand> {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("command.VanillaCommandWrapper"));
public static final Reflect.ReflectConstructor<?> CONSTRUTOR = wrapEx(() -> REFLECT.constructor(Commands.MAPPING.runtimeClass(), CommandNode.class));
public static final Reflect.ReflectField<?> vanillaCommand = wrapEx(() -> REFLECT.field("vanillaCommand"));
public static final Reflect.ReflectMethod<?> getListener = wrapEx(() -> REFLECT.method("getListener", CommandSender.class));
public VanillaCommandWrapper(Commands dispatcher, CommandNode<BukkitBrigadierCommandSource> vanillaCommand) {
this(wrapReflectEx(() -> CONSTRUTOR.instanciate(unwrap(dispatcher), vanillaCommand)));
}
@SuppressWarnings("unchecked")
public CommandNode<BukkitBrigadierCommandSource> vanillaCommand() {
return (CommandNode<BukkitBrigadierCommandSource>) wrapReflectEx(() -> vanillaCommand.getValue(__getRuntimeInstance()));
}
public static BukkitBrigadierCommandSource getListener(CommandSender sender) {
return (BukkitBrigadierCommandSource) wrapReflectEx(() -> getListener.invokeStatic(sender));
}
protected VanillaCommandWrapper(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,14 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public class DetectedVersion extends ReflectWrapper implements WorldVersion {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.DetectedVersion"));
protected DetectedVersion(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,31 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class SharedConstants extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.SharedConstants"));
private static final Reflect.ReflectMethod<?> getCurrentVersion = wrapEx(() -> MAPPING.mojMethod("getCurrentVersion"));
private static final Reflect.ReflectMethod<?> getProtocolVersion = wrapEx(() -> MAPPING.mojMethod("getProtocolVersion"));
public static WorldVersion getCurrentVersion() {
return wrap(wrapReflectEx(() -> getCurrentVersion.invokeStatic()), WorldVersion.class);
}
public static int getProtocolVersion() {
return (int) wrapReflectEx(() -> getProtocolVersion.invokeStatic());
}
protected SharedConstants(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,22 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
import fr.pandacube.lib.paper.reflect.wrapper.ConcreteWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperI;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
@ConcreteWrapper(WorldVersion.__concrete.class)
public interface WorldVersion extends ReflectWrapperI {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.WorldVersion"));
public static class __concrete extends ReflectWrapper implements WorldVersion {
private __concrete(Object obj) {
super(obj);
}
}
}

View File

@ -0,0 +1,22 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.mojang.brigadier.arguments.ArgumentType;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class BlockPosArgument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.BlockPosArgument"));
private static final Reflect.ReflectMethod<?> blockPos = wrapEx(() -> MAPPING.mojMethod("blockPos"));
public static ArgumentType<?> blockPos() {
return (ArgumentType<?>) wrapReflectEx(() -> blockPos.invokeStatic());
}
protected BlockPosArgument(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,15 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public class CommandSourceStack extends ReflectWrapperTyped<BukkitBrigadierCommandSource> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.CommandSourceStack"));
protected CommandSourceStack(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,24 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import com.mojang.brigadier.CommandDispatcher;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class Commands extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.Commands"));
public static final Reflect.ReflectField<?> dispatcher = wrapEx(() -> MAPPING.mojField("dispatcher"));
@SuppressWarnings("unchecked")
public CommandDispatcher<BukkitBrigadierCommandSource> dispatcher() {
return (CommandDispatcher<BukkitBrigadierCommandSource>) wrapReflectEx(() -> dispatcher.getValue(__getRuntimeInstance()));
}
protected Commands(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,22 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.mojang.brigadier.arguments.ArgumentType;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ComponentArgument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.ComponentArgument"));
private static final Reflect.ReflectMethod<?> textComponent = wrapEx(() -> MAPPING.mojMethod("textComponent"));
public static ArgumentType<?> textComponent() {
return (ArgumentType<?>) wrapReflectEx(() -> textComponent.invokeStatic());
}
protected ComponentArgument(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,35 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ConcreteWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperI;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.BlockPos;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Vec3;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
import static fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper.wrap;
@ConcreteWrapper(Coordinates.__concrete.class)
public interface Coordinates extends ReflectWrapperI {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.Coordinates"));
public static final Reflect.ReflectMethod<?> getPosition = wrapEx(() -> MAPPING.mojMethod("getPosition", CommandSourceStack.MAPPING));
public static final Reflect.ReflectMethod<?> getBlockPos = wrapEx(() -> MAPPING.mojMethod("getBlockPos", CommandSourceStack.MAPPING));
public default Vec3 getPosition(BukkitBrigadierCommandSource source) {
return wrap(wrapReflectEx(() -> getPosition.invoke(__getRuntimeInstance(), source)), Vec3.class);
}
public default BlockPos getBlockPos(BukkitBrigadierCommandSource source) {
return wrap(wrapReflectEx(() -> getBlockPos.invoke(__getRuntimeInstance(), source)), BlockPos.class);
}
static class __concrete extends ReflectWrapper implements Coordinates {
protected __concrete(Object obj) {
super(obj);
}
}
}

View File

@ -0,0 +1,38 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.mojang.brigadier.arguments.ArgumentType;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class EntityArgument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.EntityArgument"));
private static final Reflect.ReflectMethod<?> entity = wrapEx(() -> MAPPING.mojMethod("entity"));
private static final Reflect.ReflectMethod<?> entities = wrapEx(() -> MAPPING.mojMethod("entities"));
private static final Reflect.ReflectMethod<?> player = wrapEx(() -> MAPPING.mojMethod("player"));
private static final Reflect.ReflectMethod<?> players = wrapEx(() -> MAPPING.mojMethod("players"));
public static ArgumentType<?> entity() {
return (ArgumentType<?>) wrapReflectEx(() -> entity.invokeStatic());
}
public static ArgumentType<?> entities() {
return (ArgumentType<?>) wrapReflectEx(() -> entities.invokeStatic());
}
public static ArgumentType<?> player() {
return (ArgumentType<?>) wrapReflectEx(() -> player.invokeStatic());
}
public static ArgumentType<?> players() {
return (ArgumentType<?>) wrapReflectEx(() -> players.invokeStatic());
}
protected EntityArgument(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,45 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectListWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerPlayer;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Entity;
import java.util.List;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class EntitySelector extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.selector.EntitySelector"));
private static final Reflect.ReflectMethod<?> findEntities = wrapEx(() -> MAPPING.mojMethod("findEntities", CommandSourceStack.MAPPING));
private static final Reflect.ReflectMethod<?> findPlayers = wrapEx(() -> MAPPING.mojMethod("findPlayers", CommandSourceStack.MAPPING));
private static final Reflect.ReflectMethod<?> findSingleEntity = wrapEx(() -> MAPPING.mojMethod("findSingleEntity", CommandSourceStack.MAPPING));
private static final Reflect.ReflectMethod<?> findSinglePlayer = wrapEx(() -> MAPPING.mojMethod("findSinglePlayer", CommandSourceStack.MAPPING));
@SuppressWarnings("unchecked")
public ReflectListWrapper<Entity> findEntities(BukkitBrigadierCommandSource source) {
return wrapList((List<Object>) wrapReflectEx(() -> findEntities.invoke(__getRuntimeInstance(), source)), Entity.class);
}
public Entity findSingleEntity(BukkitBrigadierCommandSource source) {
return wrap(wrapReflectEx(() -> findSingleEntity.invoke(__getRuntimeInstance(), source)), Entity.class);
}
@SuppressWarnings("unchecked")
public ReflectListWrapper<ServerPlayer> findPlayers(BukkitBrigadierCommandSource source) {
return wrapList((List<Object>) wrapReflectEx(() -> findPlayers.invoke(__getRuntimeInstance(), source)), ServerPlayer.class);
}
public ServerPlayer findSinglePlayer(BukkitBrigadierCommandSource source) {
return wrap(wrapReflectEx(() -> findSinglePlayer.invoke(__getRuntimeInstance(), source)), ServerPlayer.class);
}
protected EntitySelector(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,22 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.mojang.brigadier.arguments.ArgumentType;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class GameProfileArgument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.GameProfileArgument"));
private static final Reflect.ReflectMethod<?> gameProfile = wrapEx(() -> MAPPING.mojMethod("gameProfile"));
public static ArgumentType<?> gameProfile() {
return (ArgumentType<?>) wrapReflectEx(() -> gameProfile.invokeStatic());
}
protected GameProfileArgument(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,22 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.mojang.brigadier.arguments.ArgumentType;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ResourceLocationArgument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.ResourceLocationArgument"));
private static final Reflect.ReflectMethod<?> id = wrapEx(() -> MAPPING.mojMethod("id"));
public static ArgumentType<?> id() {
return (ArgumentType<?>) wrapReflectEx(() -> id.invokeStatic());
}
protected ResourceLocationArgument(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,23 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands;
import com.mojang.brigadier.arguments.ArgumentType;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperTyped;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class Vec3Argument extends ReflectWrapperTyped<ArgumentType<?>> {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.commands.arguments.coordinates.Vec3Argument"));
private static final Reflect.ReflectMethod<?> vec3 = wrapEx(() -> MAPPING.mojMethod("vec3", boolean.class));
public static ArgumentType<?> vec3(boolean centerIntegers) {
return (ArgumentType<?>) wrapReflectEx(() -> vec3.invokeStatic(centerIntegers));
}
protected Vec3Argument(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,15 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.core;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public class BlockPos extends Vec3i {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.core.BlockPos"));
protected BlockPos(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,31 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.core;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class Vec3i extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.core.Vec3i"));
public static final Reflect.ReflectMethod<?> getX = wrapEx(() -> MAPPING.mojMethod("getX"));
public static final Reflect.ReflectMethod<?> getY = wrapEx(() -> MAPPING.mojMethod("getY"));
public static final Reflect.ReflectMethod<?> getZ = wrapEx(() -> MAPPING.mojMethod("getZ"));
public int getX() {
return (int) wrapReflectEx(() -> getX.invoke(__getRuntimeInstance()));
}
public int getY() {
return (int) wrapReflectEx(() -> getY.invoke(__getRuntimeInstance()));
}
public int getZ() {
return (int) wrapReflectEx(() -> getZ.invoke(__getRuntimeInstance()));
}
protected Vec3i(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,160 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import fr.pandacube.lib.core.util.Reflect.ReflectMethod;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
public class CompoundTag extends ReflectWrapper implements Tag {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.CompoundTag"));
private static final ReflectMethod<?> putBoolean = wrapEx(() -> MAPPING.mojMethod("putBoolean", String.class, boolean.class));
private static final ReflectMethod<?> putByte = wrapEx(() -> MAPPING.mojMethod("putByte", String.class, byte.class));
private static final ReflectMethod<?> putByteArray = wrapEx(() -> MAPPING.mojMethod("putByteArray", String.class, byte[].class));
private static final ReflectMethod<?> putByteArray_List = wrapEx(() -> MAPPING.mojMethod("putByteArray", String.class, List.class));
private static final ReflectMethod<?> putDouble = wrapEx(() -> MAPPING.mojMethod("putDouble", String.class, double.class));
private static final ReflectMethod<?> putFloat = wrapEx(() -> MAPPING.mojMethod("putFloat", String.class, float.class));
private static final ReflectMethod<?> putInt = wrapEx(() -> MAPPING.mojMethod("putInt", String.class, int.class));
private static final ReflectMethod<?> putIntArray = wrapEx(() -> MAPPING.mojMethod("putIntArray", String.class, int[].class));
private static final ReflectMethod<?> putIntArray_List = wrapEx(() -> MAPPING.mojMethod("putIntArray", String.class, List.class));
private static final ReflectMethod<?> putString = wrapEx(() -> MAPPING.mojMethod("putString", String.class, String.class));
private static final ReflectMethod<?> putUUID = wrapEx(() -> MAPPING.mojMethod("putUUID", String.class, UUID.class));
private static final ReflectMethod<?> putLong = wrapEx(() -> MAPPING.mojMethod("putLong", String.class, long.class));
private static final ReflectMethod<?> putLongArray = wrapEx(() -> MAPPING.mojMethod("putLongArray", String.class, long[].class));
private static final ReflectMethod<?> putLongArray_List = wrapEx(() -> MAPPING.mojMethod("putLongArray", String.class, List.class));
private static final ReflectMethod<?> putShort = wrapEx(() -> MAPPING.mojMethod("putShort", String.class, short.class));
private static final ReflectMethod<?> put = wrapEx(() -> MAPPING.mojMethod("put", String.class, Tag.MAPPING));
private static final ReflectMethod<?> getTagType = wrapEx(() -> MAPPING.mojMethod("getTagType", String.class));
private static final ReflectMethod<?> getByte = wrapEx(() -> MAPPING.mojMethod("getByte", String.class));
private static final ReflectMethod<?> getShort = wrapEx(() -> MAPPING.mojMethod("getShort", String.class));
private static final ReflectMethod<?> getInt = wrapEx(() -> MAPPING.mojMethod("getInt", String.class));
private static final ReflectMethod<?> getLong = wrapEx(() -> MAPPING.mojMethod("getLong", String.class));
private static final ReflectMethod<?> getFloat = wrapEx(() -> MAPPING.mojMethod("getFloat", String.class));
private static final ReflectMethod<?> getDouble = wrapEx(() -> MAPPING.mojMethod("getDouble", String.class));
private static final ReflectMethod<?> getString = wrapEx(() -> MAPPING.mojMethod("getString", String.class));
private static final ReflectMethod<?> getByteArray = wrapEx(() -> MAPPING.mojMethod("getByteArray", String.class));
private static final ReflectMethod<?> getIntArray = wrapEx(() -> MAPPING.mojMethod("getIntArray", String.class));
private static final ReflectMethod<?> getLongArray = wrapEx(() -> MAPPING.mojMethod("getLongArray", String.class));
private static final ReflectMethod<?> getCompound = wrapEx(() -> MAPPING.mojMethod("getCompound", String.class));
private static final ReflectMethod<?> getBoolean = wrapEx(() -> MAPPING.mojMethod("getBoolean", String.class));
private static final ReflectMethod<?> get = wrapEx(() -> MAPPING.mojMethod("get", String.class));
private static final ReflectMethod<?> getAllKeys = wrapEx(() -> MAPPING.mojMethod("getAllKeys"));
private static final ReflectMethod<?> entries = wrapEx(() -> MAPPING.mojMethod("entries"));
private static final ReflectMethod<?> size = wrapEx(() -> MAPPING.mojMethod("size"));
private static final ReflectMethod<?> contains = wrapEx(() -> MAPPING.mojMethod("contains", String.class));
public CompoundTag(Object nms) {
super(nms);
}
public void putBoolean(String key, boolean value) {
wrapReflectEx(() -> putBoolean.invoke(__getRuntimeInstance(), key, value));
}
public void putByte(String key, byte value) {
wrapReflectEx(() -> putByte.invoke(__getRuntimeInstance(), key, value));
}
public void putByteArray(String key, byte[] value) {
wrapReflectEx(() -> putByteArray.invoke(__getRuntimeInstance(), key, value));
}
public void putDouble(String key, double value) {
wrapReflectEx(() -> putDouble.invoke(__getRuntimeInstance(), key, value));
}
public void putFloat(String key, float value) {
wrapReflectEx(() -> putFloat.invoke(__getRuntimeInstance(), key, value));
}
public void putInt(String key, int value) {
wrapReflectEx(() -> putInt.invoke(__getRuntimeInstance(), key, value));
}
public void putIntArray(String key, int[] value) {
wrapReflectEx(() -> putIntArray.invoke(__getRuntimeInstance(), key, value));
}
public void putString(String key, String value) {
wrapReflectEx(() -> putString.invoke(__getRuntimeInstance(), key, value));
}
public void putUUID(String key, UUID value) {
wrapReflectEx(() -> putUUID.invoke(__getRuntimeInstance(), key, value));
}
public void putLong(String key, long value) {
wrapReflectEx(() -> putLong.invoke(__getRuntimeInstance(), key, value));
}
public void putLongArray(String key, long[] value) {
wrapReflectEx(() -> putLongArray.invoke(__getRuntimeInstance(), key, value));
}
public void putShort(String key, short value) {
wrapReflectEx(() -> putShort.invoke(__getRuntimeInstance(), key, value));
}
public void put(String key, Tag value) {
wrapReflectEx(() -> put.invoke(__getRuntimeInstance(), key, unwrap(value)));
}
public byte getTagType(String key) {
return (byte) wrapReflectEx(() -> getTagType.invoke(__getRuntimeInstance(), key));
}
public byte getByte(String key) {
return (byte) wrapReflectEx(() -> getByte.invoke(__getRuntimeInstance(), key));
}
public short getShort(String key) {
return (short) wrapReflectEx(() -> getShort.invoke(__getRuntimeInstance(), key));
}
public int getInt(String key) {
return (int) wrapReflectEx(() -> getInt.invoke(__getRuntimeInstance(), key));
}
public long getLong(String key) {
return (long) wrapReflectEx(() -> getLong.invoke(__getRuntimeInstance(), key));
}
public float getFloat(String key) {
return (float) wrapReflectEx(() -> getFloat.invoke(__getRuntimeInstance(), key));
}
public double getDouble(String key) {
return (double) wrapReflectEx(() -> getDouble.invoke(__getRuntimeInstance(), key));
}
public String getString(String key) {
return (String) wrapReflectEx(() -> getString.invoke(__getRuntimeInstance(), key));
}
public byte[] getByteArray(String key) {
return (byte[]) wrapReflectEx(() -> getByteArray.invoke(__getRuntimeInstance(), key));
}
public int[] getIntArray(String key) {
return (int[]) wrapReflectEx(() -> getIntArray.invoke(__getRuntimeInstance(), key));
}
public long[] getLongArray(String key) {
return (long[]) wrapReflectEx(() -> getLongArray.invoke(__getRuntimeInstance(), key));
}
public CompoundTag getCompound(String key) {
return wrap(wrapReflectEx(() -> getCompound.invoke(__getRuntimeInstance(), key)), CompoundTag.class);
}
public boolean getBoolean(String key) {
return (boolean) wrapReflectEx(() -> getBoolean.invoke(__getRuntimeInstance(), key));
}
public Tag get(String key) {
return wrap(wrapReflectEx(() -> get.invoke(__getRuntimeInstance(), key)), Tag.class);
}
@SuppressWarnings("unchecked")
public Set<String> getAllKeys() {
return (Set<String>) wrapReflectEx(() -> getAllKeys.invoke(__getRuntimeInstance()));
}
/**
* The values in the returned Map are not wrapped.
*/
@SuppressWarnings("unchecked")
public Map<String, ?> entries() {
// we cannot easily wrap every value of the map without being able to synch the returned map with the wrapped map
return (Map<String, ?>) wrapReflectEx(() -> entries.invoke(__getRuntimeInstance()));
}
public int size() {
return (int) wrapReflectEx(() -> size.invoke(__getRuntimeInstance()));
}
public boolean contains(String key) {
return (boolean) wrapReflectEx(() -> contains.invoke(__getRuntimeInstance(), key));
}
}

View File

@ -0,0 +1,30 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import java.io.File;
import fr.pandacube.lib.core.util.Reflect.ReflectMethod;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
public class NbtIo extends ReflectWrapper {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.NbtIo"));
private static final ReflectMethod<?> readCompressed = wrapEx(() -> MAPPING.mojMethod("readCompressed", File.class));
private static final ReflectMethod<?> writeCompressed = wrapEx(() -> MAPPING.mojMethod("writeCompressed", CompoundTag.MAPPING, File.class));
private NbtIo(Object obj) {
super(obj);
}
public static CompoundTag readCompressed(File f) {
return new CompoundTag(wrapEx(() -> readCompressed.invokeStatic(f)));
}
public static void writeCompressed(CompoundTag tag, File f) {
Object nmsTag = ReflectWrapper.unwrap(tag);
wrapEx(() -> writeCompressed.invokeStatic(nmsTag, f));
}
}

View File

@ -0,0 +1,17 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
public class StringTag extends ReflectWrapper implements Tag {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.StringTag"));
public StringTag(Object nms) {
super(nms);
}
}

View File

@ -0,0 +1,31 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
import fr.pandacube.lib.core.util.Reflect.ReflectMethod;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
import fr.pandacube.lib.paper.reflect.wrapper.ConcreteWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperI;
@ConcreteWrapper(Tag.__concrete.class)
public interface Tag extends ReflectWrapperI {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.Tag"));
public static final ReflectMethod<?> getAsString = wrapEx(() -> MAPPING.mojMethod("getAsString"));
public default String getAsString() {
return wrapReflectEx(() -> (String) getAsString.invoke(__getRuntimeInstance()));
}
public static class __concrete extends ReflectWrapper implements Tag {
private __concrete(Object obj) {
super(obj);
}
}
}

View File

@ -0,0 +1,26 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.network;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.netty.ByteBuf;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class FriendlyByteBuf extends ByteBuf {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.FriendlyByteBuf"));
private static final Reflect.ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(ByteBuf.REFLECT.get()));
private static final Reflect.ReflectMethod<?> writeUtf = wrapEx(() -> MAPPING.mojMethod("writeUtf", String.class));
public FriendlyByteBuf(ByteBuf parent) {
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(unwrap(parent))));
}
public FriendlyByteBuf writeUtf(String string) {
return wrap(wrapReflectEx(() -> writeUtf.invoke(__getRuntimeInstance(), string)), FriendlyByteBuf.class);
}
protected FriendlyByteBuf(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,20 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.chat;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ConcreteWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperI;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
@ConcreteWrapper(Component.__concrete.class)
public interface Component extends ReflectWrapperI {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.chat.Component"));
public class __concrete extends ReflectWrapper implements Component {
protected __concrete(Object obj) {
super(obj);
}
}
}

View File

@ -0,0 +1,26 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.FriendlyByteBuf;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.resources.ResourceLocation;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ClientboundCustomPayloadPacket extends ReflectWrapper implements Packet {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket"));
private static final Reflect.ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(ResourceLocation.MAPPING.runtimeClass(), FriendlyByteBuf.MAPPING.runtimeClass()));
private static final Reflect.ReflectField<?> FIELD_BRAND = wrapEx(() -> MAPPING.mojField("BRAND"));
public static final ResourceLocation BRAND = wrap(wrapReflectEx(FIELD_BRAND::getStaticValue), ResourceLocation.class);
protected ClientboundCustomPayloadPacket(Object obj) {
super(obj);
}
public ClientboundCustomPayloadPacket(ResourceLocation res, FriendlyByteBuf buff) {
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(unwrap(res), unwrap(buff))));
}
}

View File

@ -0,0 +1,35 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ClientboundGameEventPacket extends ReflectWrapper implements Packet {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.game.ClientboundGameEventPacket"));
private static final Reflect.ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(Type.MAPPING.runtimeClass(), float.class));
private static final Reflect.ReflectField<?> FIELD_RAIN_LEVEL_CHANGE = wrapEx(() -> MAPPING.mojField("RAIN_LEVEL_CHANGE"));
private static final Reflect.ReflectField<?> FIELD_THUNDER_LEVEL_CHANGE = wrapEx(() -> MAPPING.mojField("THUNDER_LEVEL_CHANGE"));
public static final Type RAIN_LEVEL_CHANGE = wrap(wrapReflectEx(FIELD_RAIN_LEVEL_CHANGE::getStaticValue), Type.class);
public static final Type THUNDER_LEVEL_CHANGE = wrap(wrapReflectEx(FIELD_THUNDER_LEVEL_CHANGE::getStaticValue), Type.class);
public ClientboundGameEventPacket(Type type, float value) {
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(unwrap(type), value)));
}
protected ClientboundGameEventPacket(Object obj) {
super(obj);
}
public static class Type extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.game.ClientboundGameEventPacket$Type"));
protected Type(Object obj) {
super(obj);
}
}
}

View File

@ -0,0 +1,19 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ConcreteWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperI;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
@ConcreteWrapper(Packet.__concrete.class)
public interface Packet extends ReflectWrapperI {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.network.protocol.Packet"));
public class __concrete extends ReflectWrapper implements Packet {
protected __concrete(Object obj) {
super(obj);
}
}
}

View File

@ -0,0 +1,15 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.resources;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public class ResourceLocation extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.resources.ResourceLocation"));
protected ResourceLocation(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,40 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ChunkStorage;
import fr.pandacube.lib.paper.reflect.wrapper.paper.QueuedChangesMapLong2Object;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongSet;
import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ChunkMap extends ChunkStorage {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.level.ChunkMap"));
private static final Reflect.ReflectField<?> FIELD_autoSaveQueue = wrapEx(() -> MAPPING.runtimeReflect().field("autoSaveQueue")); // spigot/paper field
public static final Reflect.ReflectField<?> FIELD_level = wrapEx(() -> MAPPING.mojField("level"));
public static final Reflect.ReflectField<?> FIELD_pendingUnloads = wrapEx(() -> MAPPING.mojField("pendingUnloads"));
public static final Reflect.ReflectField<?> FIELD_toDrop = wrapEx(() -> MAPPING.mojField("toDrop"));
public static final Reflect.ReflectField<?> FIELD_updatingChunks = wrapEx(() -> MAPPING.runtimeReflect().field("updatingChunks")); // spigot/paper field
/** This field in unmapped */
public final ObjectRBTreeSet<?> autoSaveQueue;
public final ServerLevel level;
/** This field in unmapped */
public final Long2ObjectLinkedOpenHashMap<?> pendingUnloads;
/** This field in unmapped */
public final LongSet toDrop;
public final QueuedChangesMapLong2Object updatingChunks;
protected ChunkMap(Object obj) {
super(obj);
autoSaveQueue = (ObjectRBTreeSet<?>) wrapReflectEx(() -> FIELD_autoSaveQueue.getValue(obj));
level = wrap(wrapReflectEx(() -> FIELD_level.getValue(obj)), ServerLevel.class);
pendingUnloads = (Long2ObjectLinkedOpenHashMap<?>) wrapReflectEx(() -> FIELD_pendingUnloads.getValue(obj));
toDrop = (LongSet) wrapReflectEx(() -> FIELD_toDrop.getValue(obj));
updatingChunks = wrap(wrapReflectEx(() -> FIELD_updatingChunks.getValue(obj)), QueuedChangesMapLong2Object.class);
}
}

View File

@ -0,0 +1,14 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public class DedicatedPlayerList extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.DedicatedPlayerList"));
protected DedicatedPlayerList(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,25 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class DedicatedServer extends MinecraftServer {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.DedicatedServer"));
private static final Reflect.ReflectMethod<?> getLevelIdName = wrapEx(() -> MAPPING.mojMethod("getLevelIdName"));
private static final Reflect.ReflectMethod<?> getProperties = wrapEx(() -> MAPPING.mojMethod("getProperties"));
public String getLevelIdName() {
return (String) wrapReflectEx(() -> getLevelIdName.invoke(__getRuntimeInstance()));
}
public DedicatedServerProperties getProperties() {
return wrap(wrapReflectEx(() -> getProperties.invoke(__getRuntimeInstance())), DedicatedServerProperties.class);
}
protected DedicatedServer(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,13 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public class DedicatedServerProperties extends Settings {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.DedicatedServerProperties"));
protected DedicatedServerProperties(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,22 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Commands;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class MinecraftServer extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.MinecraftServer"));
private static final Reflect.ReflectField<?> vanillaCommandDispatcher = wrapEx(() -> MAPPING.runtimeReflect().field("vanillaCommandDispatcher"));
public Commands vanillaCommandDispatcher() {
return wrap(wrapReflectEx(() -> vanillaCommandDispatcher.getValue(__getRuntimeInstance())), Commands.class);
}
protected MinecraftServer(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,21 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ServerChunkCache extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.level.ServerChunkCache"));
private static final Reflect.ReflectField<?> FIELD_chunkMap = wrapEx(() -> MAPPING.mojField("chunkMap"));
public final ChunkMap chunkMap;
protected ServerChunkCache(Object obj) {
super(obj);
chunkMap = wrap(wrapReflectEx(() -> FIELD_chunkMap.getValue(obj)));
}
}

View File

@ -0,0 +1,22 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.protocol.Packet;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ServerGamePacketListenerImpl extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.network.ServerGamePacketListenerImpl"));
public static final Reflect.ReflectMethod<?> send = wrapEx(() -> MAPPING.mojMethod("send", Packet.MAPPING));
public void send(Packet packet) {
wrapReflectEx(() -> send.invoke(__getRuntimeInstance(), unwrap(packet)));
}
protected ServerGamePacketListenerImpl(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,29 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.util.ProgressListener;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Level;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ServerLevel extends Level {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.level.ServerLevel"));
public static final Reflect.ReflectMethod<?> save = wrapEx(() -> MAPPING.mojMethod("save", ProgressListener.MAPPING, boolean.class, boolean.class));
public static final Reflect.ReflectMethod<?> getChunkSource = wrapEx(() -> MAPPING.mojMethod("getChunkSource"));
public ServerChunkCache getChunkSource() {
return wrap(wrapReflectEx(() -> getChunkSource.invoke(__getRuntimeInstance())), ServerChunkCache.class);
}
public void save(ProgressListener listener, boolean flush, boolean savingDisabled) {
wrapReflectEx(() -> save.invoke(__getRuntimeInstance(), unwrap(listener), flush, savingDisabled));
}
protected ServerLevel(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,37 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSource;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Entity;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ServerPlayer extends Entity { // in NMS, ServerPlayer is not a direct subclass of Entity
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.level.ServerPlayer"));
public static final Reflect.ReflectField<?> connection = wrapEx(() -> MAPPING.mojField("connection"));
public static final Reflect.ReflectMethod<?> hurt = wrapEx(() -> MAPPING.mojMethod("hurt", DamageSource.MAPPING, float.class));
public static final Reflect.ReflectMethod<?> isTextFilteringEnabled = wrapEx(() -> MAPPING.mojMethod("isTextFilteringEnabled"));
public static final Reflect.ReflectMethod<?> allowsListing = wrapEx(() -> MAPPING.mojMethod("allowsListing"));
public boolean hurt(DamageSource source, float amount) {
return (boolean) wrapReflectEx(() -> hurt.invoke(__getRuntimeInstance(), unwrap(source), amount));
}
public boolean isTextFilteringEnabled() {
return (boolean) wrapReflectEx(() -> isTextFilteringEnabled.invoke(__getRuntimeInstance()));
}
public boolean allowsListing() {
return (boolean) wrapReflectEx(() -> allowsListing.invoke(__getRuntimeInstance()));
}
public ServerGamePacketListenerImpl connection() {
return wrap(wrapReflectEx(() -> connection.getValue(__getRuntimeInstance())), ServerGamePacketListenerImpl.class);
}
protected ServerPlayer(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,23 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import java.util.Properties;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class Settings extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.Settings"));
public static final Reflect.ReflectField<?> properties = wrapEx(() -> MAPPING.mojField("properties"));
public Properties properties() {
return (Properties) wrapReflectEx(() -> properties.getValue(__getRuntimeInstance()));
}
protected Settings(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,20 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.util;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ConcreteWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapperI;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
@ConcreteWrapper(ProgressListener.__concrete.class)
public interface ProgressListener extends ReflectWrapperI {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.util.ProgressListener"));
public class __concrete extends ReflectWrapper implements ProgressListener {
protected __concrete(Object obj) {
super(obj);
}
}
}

View File

@ -0,0 +1,21 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class AABB extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.phys.AABB"));
private static final Reflect.ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(double.class, double.class, double.class, double.class, double.class, double.class));
public AABB(double x1, double y1, double z1, double x2, double y2, double z2) {
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(x1, y1, z1, x2, y2, z2)));
}
protected AABB(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,21 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ChunkPos extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.ChunkPos"));
public static final Reflect.ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(int.class, int.class));
public ChunkPos(int x, int z) {
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(x, z)));
}
protected ChunkPos(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,32 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class ChunkStorage extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.chunk.storage.ChunkStorage"));
private static final Reflect.ReflectMethod<?> read = wrapEx(() -> MAPPING.mojMethod("read", ChunkPos.MAPPING));
private static final Reflect.ReflectMethod<?> readSync = wrapEx(() -> MAPPING.runtimeReflect().method("readSync", ChunkPos.MAPPING.runtimeReflect().get())); // spigot/paper method
public CompoundTag readSync(ChunkPos pos) {
return wrap(wrapReflectEx(() -> readSync.invoke(__getRuntimeInstance(), unwrap(pos))), CompoundTag.class);
}
public CompletableFuture<Optional<CompoundTag>> read(ChunkPos pos) {
@SuppressWarnings("unchecked")
CompletableFuture<Optional<?>> nmsFuture = (CompletableFuture<Optional<?>>) wrapReflectEx(() -> readSync.invoke(__getRuntimeInstance(), unwrap(pos)));
return nmsFuture.thenApply(o -> o.map(c -> wrap(c, CompoundTag.class)));
}
protected ChunkStorage(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,19 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class DamageSource extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.damagesource.DamageSource"));
private static final Reflect.ReflectField<?> FIELD_OUT_OF_WORLD = wrapEx(() -> MAPPING.mojField("OUT_OF_WORLD"));
public static final DamageSource OUT_OF_WORLD = wrap(wrapReflectEx(FIELD_OUT_OF_WORLD::getStaticValue), DamageSource.class);
protected DamageSource(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,21 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class Entity extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.entity.Entity"));
public static final Reflect.ReflectMethod<?> getBukkitEntity = wrapEx(() -> MAPPING.runtimeReflect().method("getBukkitEntity")); // spigot field
public org.bukkit.entity.Entity getBukkitEntity() {
return (org.bukkit.entity.Entity) wrapReflectEx(() -> getBukkitEntity.invoke(__getRuntimeInstance()));
}
protected Entity(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,32 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.WorldConfiguration;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class Level extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.Level"));
public static final Reflect.ReflectMethod<?> getGameTime = wrapEx(() -> MAPPING.mojMethod("getGameTime"));
public static final Reflect.ReflectMethod<?> getFreeMapId = wrapEx(() -> MAPPING.mojMethod("getFreeMapId"));
public static final Reflect.ReflectMethod<?> paperConfig = wrapEx(() -> MAPPING.runtimeReflect().method("paperConfig")); // paper method
public long getGameTime() {
return (long) wrapReflectEx(() -> getGameTime.invoke(__getRuntimeInstance()));
}
public int getFreeMapId() {
return (int) wrapReflectEx(() -> getFreeMapId.invoke(__getRuntimeInstance()));
}
public WorldConfiguration paperConfig() {
return wrap(wrapReflectEx(() -> paperConfig.invoke(__getRuntimeInstance())), WorldConfiguration.class);
}
protected Level(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,33 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class MapItemSavedData extends SavedData {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.saveddata.maps.MapItemSavedData"));
public static final Reflect.ReflectField<?> colors = wrapEx(() -> MAPPING.mojField("colors"));
public static final Reflect.ReflectField<?> locked = wrapEx(() -> MAPPING.mojField("locked"));
protected MapItemSavedData(Object obj) {
super(obj);
}
public boolean locked() {
return (boolean) wrapReflectEx(() -> locked.getValue(__getRuntimeInstance()));
}
public void locked(boolean l) {
wrapReflectEx(() -> locked.setValue(__getRuntimeInstance(), l));
}
public byte[] colors() {
return (byte[]) wrapReflectEx(() -> colors.getValue(__getRuntimeInstance()));
}
public void colors(byte[] c) {
wrapReflectEx(() -> colors.setValue(__getRuntimeInstance(), c));
}
}

View File

@ -0,0 +1,21 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class SavedData extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.saveddata.SavedData"));
public static final Reflect.ReflectMethod<?> setDirty = wrapEx(() -> MAPPING.mojMethod("setDirty"));
protected SavedData(Object obj) {
super(obj);
}
public void setDirty(boolean dirty) {
wrapReflectEx(() -> setDirty.invoke(__getRuntimeInstance(), dirty));
}
}

View File

@ -0,0 +1,14 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public class Vec3 extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.phys.Vec3"));
protected Vec3(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,14 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public class VoxelShape extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.phys.shapes.VoxelShape"));
protected VoxelShape(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,26 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class BambooBlock extends ReflectWrapper {
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.block.BambooBlock"));
public static final Reflect.ReflectField<?> COLLISION_SHAPE = wrapEx(() -> MAPPING.mojField("COLLISION_SHAPE"));
public static VoxelShape COLLISION_SHAPE() {
return wrap(wrapReflectEx(COLLISION_SHAPE::getStaticValue), VoxelShape.class);
}
public static void COLLISION_SHAPE(VoxelShape shape) {
wrapReflectEx(() -> COLLISION_SHAPE.setStaticValue(unwrap(shape)));
}
protected BambooBlock(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,16 @@
package fr.pandacube.lib.paper.reflect.wrapper.netty;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
public abstract class ByteBuf extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.netty.buffer.ByteBuf"));
protected ByteBuf(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,23 @@
package fr.pandacube.lib.paper.reflect.wrapper.netty;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class Unpooled extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.netty.buffer.Unpooled"));
private static final Reflect.ReflectMethod<?> buffer = wrapEx(() -> REFLECT.method("buffer"));
public static ByteBuf buffer() {
return wrap(wrapReflectEx(() -> buffer.invokeStatic()), ByteBuf.class);
}
protected Unpooled(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,21 @@
package fr.pandacube.lib.paper.reflect.wrapper.paper;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.AABB;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class AABBVoxelShape extends VoxelShape {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.voxel.AABBVoxelShape"));
private static final Reflect.ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> REFLECT.constructor(AABB.MAPPING.runtimeClass()));
public AABBVoxelShape(AABB aabb) {
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(unwrap(aabb))));
}
protected AABBVoxelShape(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,24 @@
package fr.pandacube.lib.paper.reflect.wrapper.paper;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.chat.Component;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class PaperAdventure extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.adventure.PaperAdventure"));
private static final Reflect.ReflectMethod<?> asAdventure = wrapEx(() -> REFLECT.method("asAdventure", Component.MAPPING.runtimeClass()));
public static net.kyori.adventure.text.Component asAdventure(Component component) {
return (net.kyori.adventure.text.Component) wrapReflectEx(() -> asAdventure.invokeStatic(unwrap(component)));
}
protected PaperAdventure(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,22 @@
package fr.pandacube.lib.paper.reflect.wrapper.paper;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class QueuedChangesMapLong2Object extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("com.destroystokyo.paper.util.map.QueuedChangesMapLong2Object"));
public static final Reflect.ReflectMethod<?> getVisibleMap = wrapEx(() -> REFLECT.method("getVisibleMap"));
/** The entries in the returned value are not mapped */
public Long2ObjectLinkedOpenHashMap<?> getVisibleMap() {
return (Long2ObjectLinkedOpenHashMap<?>) wrapReflectEx(() -> getVisibleMap.invoke(__getRuntimeInstance()));
}
protected QueuedChangesMapLong2Object(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,20 @@
package fr.pandacube.lib.paper.reflect.wrapper.paper.configuration;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class FallbackValue_Int extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.configuration.type.fallback.FallbackValue$Int"));
public static final Reflect.ReflectMethod<?> value = wrapEx(() -> REFLECT.method("value"));
public int value() {
return (int) wrapReflectEx(() -> value.invoke(__getRuntimeInstance()));
}
protected FallbackValue_Int(Object obj) {
super(obj);
}
}

View File

@ -0,0 +1,33 @@
package fr.pandacube.lib.paper.reflect.wrapper.paper.configuration;
import fr.pandacube.lib.core.util.Reflect;
import fr.pandacube.lib.paper.reflect.wrapper.ReflectWrapper;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.core.util.ThrowableUtil.wrapReflectEx;
public class WorldConfiguration extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.configuration.WorldConfiguration"));
public static final Reflect.ReflectField<?> chunks = wrapEx(() -> REFLECT.field("chunks"));
public Chunks chunks() {
return wrap(wrapReflectEx(() -> chunks.getValue(__getRuntimeInstance())), Chunks.class);
}
protected WorldConfiguration(Object obj) {
super(obj);
}
public static class Chunks extends ReflectWrapper {
public static final Reflect.ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("io.papermc.paper.configuration.WorldConfiguration$Chunks"));
public static final Reflect.ReflectField<?> autoSavePeriod = wrapEx(() -> REFLECT.field("autoSaveInterval"));
public FallbackValue_Int autoSavePeriod() {
return wrap(wrapReflectEx(() -> autoSavePeriod.getValue(__getRuntimeInstance())), FallbackValue_Int.class);
}
protected Chunks(Object obj) {
super(obj);
}
}
}