Compare commits
No commits in common. "edd4e89a6eeaeb2a06c901c9f0e4a72ca33cd98c" and "3e0297c8afd77a461f12aed585d8c43a8852165e" have entirely different histories.
edd4e89a6e
...
3e0297c8af
@ -58,8 +58,6 @@ import java.util.Set;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class to hold a command to be integrated into a Paper server vanilla command dispatcher.
|
* Abstract class to hold a command to be integrated into a Paper server vanilla command dispatcher.
|
||||||
*/
|
*/
|
||||||
@ -69,7 +67,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
|||||||
private static final CommandDispatcher<BukkitBrigadierCommandSource> nmsDispatcher;
|
private static final CommandDispatcher<BukkitBrigadierCommandSource> nmsDispatcher;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
wrapEx(PandalibPaperReflect::init);
|
PandalibPaperReflect.init();
|
||||||
vanillaCommandDispatcher = ReflectWrapper.wrapTyped(Bukkit.getServer(), CraftServer.class)
|
vanillaCommandDispatcher = ReflectWrapper.wrapTyped(Bukkit.getServer(), CraftServer.class)
|
||||||
.getServer()
|
.getServer()
|
||||||
.vanillaCommandDispatcher();
|
.vanillaCommandDispatcher();
|
||||||
|
@ -14,6 +14,7 @@ import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCDataConverter;
|
|||||||
import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCDataType;
|
import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCDataType;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCTypeRegistry;
|
import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCTypeRegistry;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.DetectedVersion;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.DetectedVersion;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.GameVersion;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.SharedConstants;
|
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.WorldVersion;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.BlockPosArgument;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.BlockPosArgument;
|
||||||
@ -57,7 +58,6 @@ 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.ChunkStorage;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSource;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSource;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSources;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSources;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DataVersion;
|
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Entity;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Entity;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ItemStack;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ItemStack;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Level;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Level;
|
||||||
@ -74,7 +74,6 @@ 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.QueuedChangesMapLong2Object;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.FallbackValue_Int;
|
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.FallbackValue_Int;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.WorldConfiguration;
|
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.WorldConfiguration;
|
||||||
import fr.pandacube.lib.util.ThrowableAccumulator;
|
|
||||||
|
|
||||||
import static fr.pandacube.lib.reflect.wrapper.WrapperRegistry.initWrapper;
|
import static fr.pandacube.lib.reflect.wrapper.WrapperRegistry.initWrapper;
|
||||||
|
|
||||||
@ -87,9 +86,8 @@ public class PandalibPaperReflect {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the reflect tools in {@code pandalib-paper-reflect} module.
|
* Initializes the reflect tools in {@code pandalib-paper-reflect} module.
|
||||||
* @throws Exception if a problem occurs when initializing wrapper classes.
|
|
||||||
*/
|
*/
|
||||||
public static void init() throws Exception {
|
public static void init() {
|
||||||
NMSReflect.init();
|
NMSReflect.init();
|
||||||
synchronized (PandalibPaperReflect.class) {
|
synchronized (PandalibPaperReflect.class) {
|
||||||
if (isInit)
|
if (isInit)
|
||||||
@ -99,112 +97,105 @@ public class PandalibPaperReflect {
|
|||||||
initWrapperClasses();
|
initWrapperClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initWrapperClasses() throws Exception {
|
private static void initWrapperClasses() {
|
||||||
|
|
||||||
ThrowableAccumulator<Throwable> thAcc = new ThrowableAccumulator<>(Throwable.class);
|
|
||||||
|
|
||||||
// brigadier
|
// brigadier
|
||||||
thAcc.catchThrowable(() -> initWrapper(CommandNode.class, CommandNode.REFLECT.get()));
|
initWrapper(CommandNode.class, CommandNode.REFLECT.get());
|
||||||
|
|
||||||
// craftbukkit
|
// craftbukkit
|
||||||
thAcc.catchThrowable(() -> initWrapper(CraftItemStack.class, CraftItemStack.REFLECT.get()));
|
initWrapper(CraftItemStack.class, CraftItemStack.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(CraftMapView.class, CraftMapView.REFLECT.get()));
|
initWrapper(CraftMapView.class, CraftMapView.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get()));
|
initWrapper(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get()));
|
initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(CraftServer.class, CraftServer.REFLECT.get()));
|
initWrapper(CraftServer.class, CraftServer.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(CraftVector.class, CraftVector.REFLECT.get()));
|
initWrapper(CraftVector.class, CraftVector.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(CraftWorld.class, CraftWorld.REFLECT.get()));
|
initWrapper(CraftWorld.class, CraftWorld.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(RenderData.class, RenderData.REFLECT.get()));
|
initWrapper(RenderData.class, RenderData.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(VanillaCommandWrapper.class, VanillaCommandWrapper.REFLECT.get()));
|
initWrapper(VanillaCommandWrapper.class, VanillaCommandWrapper.REFLECT.get());
|
||||||
|
|
||||||
// dataconverter
|
// dataconverter
|
||||||
thAcc.catchThrowable(() -> initWrapper(MCDataConverter.class, MCDataConverter.REFLECT.get()));
|
initWrapper(MCDataConverter.class, MCDataConverter.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(MCDataType.class, MCDataType.REFLECT.get()));
|
initWrapper(MCDataType.class, MCDataType.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(MCTypeRegistry.class, MCTypeRegistry.REFLECT.get()));
|
initWrapper(MCTypeRegistry.class, MCTypeRegistry.REFLECT.get());
|
||||||
|
|
||||||
// minecraft.commands
|
// minecraft.commands
|
||||||
thAcc.catchThrowable(() -> initWrapper(BlockPosArgument.class, BlockPosArgument.MAPPING.runtimeClass()));
|
initWrapper(BlockPosArgument.class, BlockPosArgument.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Commands.class, Commands.MAPPING.runtimeClass()));
|
initWrapper(Commands.class, Commands.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(CommandSourceStack.class, CommandSourceStack.MAPPING.runtimeClass()));
|
initWrapper(CommandSourceStack.class, CommandSourceStack.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ComponentArgument.class, ComponentArgument.MAPPING.runtimeClass()));
|
initWrapper(ComponentArgument.class, ComponentArgument.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Coordinates.class, Coordinates.MAPPING.runtimeClass()));
|
initWrapper(Coordinates.class, Coordinates.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(EntityArgument.class, EntityArgument.MAPPING.runtimeClass()));
|
initWrapper(EntityArgument.class, EntityArgument.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(EntitySelector.class, EntitySelector.MAPPING.runtimeClass()));
|
initWrapper(EntitySelector.class, EntitySelector.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(GameProfileArgument.class, GameProfileArgument.MAPPING.runtimeClass()));
|
initWrapper(GameProfileArgument.class, GameProfileArgument.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ResourceLocationArgument.class, ResourceLocationArgument.MAPPING.runtimeClass()));
|
initWrapper(ResourceLocationArgument.class, ResourceLocationArgument.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Vec3Argument.class, Vec3Argument.MAPPING.runtimeClass()));
|
initWrapper(Vec3Argument.class, Vec3Argument.MAPPING.runtimeClass());
|
||||||
// minecraft.core
|
// minecraft.core
|
||||||
thAcc.catchThrowable(() -> initWrapper(BlockPos.class, BlockPos.MAPPING.runtimeClass()));
|
initWrapper(BlockPos.class, BlockPos.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Vec3i.class, Vec3i.MAPPING.runtimeClass()));
|
initWrapper(Vec3i.class, Vec3i.MAPPING.runtimeClass());
|
||||||
// minecraft.nbt
|
// minecraft.nbt
|
||||||
thAcc.catchThrowable(() -> initWrapper(CollectionTag.class, CollectionTag.MAPPING.runtimeClass()));
|
initWrapper(CollectionTag.class, CollectionTag.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(CompoundTag.class, CompoundTag.MAPPING.runtimeClass()));
|
initWrapper(CompoundTag.class, CompoundTag.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ListTag.class, ListTag.MAPPING.runtimeClass()));
|
initWrapper(ListTag.class, ListTag.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(NbtIo.class, NbtIo.MAPPING.runtimeClass()));
|
initWrapper(NbtIo.class, NbtIo.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(StringTag.class, StringTag.MAPPING.runtimeClass()));
|
initWrapper(StringTag.class, StringTag.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Tag.class, Tag.MAPPING.runtimeClass()));
|
initWrapper(Tag.class, Tag.MAPPING.runtimeClass());
|
||||||
// minecraft.network.chat
|
// minecraft.network.chat
|
||||||
thAcc.catchThrowable(() -> initWrapper(Component.class, Component.MAPPING.runtimeClass()));
|
initWrapper(Component.class, Component.MAPPING.runtimeClass());
|
||||||
// minecraft.network.protocol
|
// minecraft.network.protocol
|
||||||
thAcc.catchThrowable(() -> initWrapper(ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket.MAPPING.runtimeClass()));
|
initWrapper(ClientboundCustomPayloadPacket.class, ClientboundCustomPayloadPacket.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ClientboundGameEventPacket.class, ClientboundGameEventPacket.MAPPING.runtimeClass()));
|
initWrapper(ClientboundGameEventPacket.class, ClientboundGameEventPacket.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ClientboundGameEventPacket.Type.class, ClientboundGameEventPacket.Type.MAPPING.runtimeClass()));
|
initWrapper(ClientboundGameEventPacket.Type.class, ClientboundGameEventPacket.Type.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Packet.class, Packet.MAPPING.runtimeClass()));
|
initWrapper(Packet.class, Packet.MAPPING.runtimeClass());
|
||||||
// minecraft.network
|
// minecraft.network
|
||||||
thAcc.catchThrowable(() -> initWrapper(FriendlyByteBuf.class, FriendlyByteBuf.MAPPING.runtimeClass()));
|
initWrapper(FriendlyByteBuf.class, FriendlyByteBuf.MAPPING.runtimeClass());
|
||||||
// minecraft.resources
|
// minecraft.resources
|
||||||
thAcc.catchThrowable(() -> initWrapper(ResourceLocation.class, ResourceLocation.MAPPING.runtimeClass()));
|
initWrapper(ResourceLocation.class, ResourceLocation.MAPPING.runtimeClass());
|
||||||
// minecraft.server
|
// minecraft.server
|
||||||
thAcc.catchThrowable(() -> initWrapper(ChunkMap.class, ChunkMap.MAPPING.runtimeClass()));
|
initWrapper(ChunkMap.class, ChunkMap.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(DedicatedPlayerList.class, DedicatedPlayerList.MAPPING.runtimeClass()));
|
initWrapper(DedicatedPlayerList.class, DedicatedPlayerList.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(DedicatedServer.class, DedicatedServer.MAPPING.runtimeClass()));
|
initWrapper(DedicatedServer.class, DedicatedServer.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(DedicatedServerProperties.class, DedicatedServerProperties.MAPPING.runtimeClass()));
|
initWrapper(DedicatedServerProperties.class, DedicatedServerProperties.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(MinecraftServer.class, MinecraftServer.MAPPING.runtimeClass()));
|
initWrapper(MinecraftServer.class, MinecraftServer.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(PlayerList.class, PlayerList.MAPPING.runtimeClass()));
|
initWrapper(PlayerList.class, PlayerList.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ServerChunkCache.class, ServerChunkCache.MAPPING.runtimeClass()));
|
initWrapper(ServerChunkCache.class, ServerChunkCache.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ServerGamePacketListenerImpl.class, ServerGamePacketListenerImpl.MAPPING.runtimeClass()));
|
initWrapper(ServerGamePacketListenerImpl.class, ServerGamePacketListenerImpl.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ServerLevel.class, ServerLevel.MAPPING.runtimeClass()));
|
initWrapper(ServerLevel.class, ServerLevel.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ServerPlayer.class, ServerPlayer.MAPPING.runtimeClass()));
|
initWrapper(ServerPlayer.class, ServerPlayer.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Settings.class, Settings.MAPPING.runtimeClass()));
|
initWrapper(Settings.class, Settings.MAPPING.runtimeClass());
|
||||||
// minecraft.util
|
// minecraft.util
|
||||||
thAcc.catchThrowable(() -> initWrapper(ProgressListener.class, ProgressListener.MAPPING.runtimeClass()));
|
initWrapper(ProgressListener.class, ProgressListener.MAPPING.runtimeClass());
|
||||||
// minecraft.world.block
|
// minecraft.world.block
|
||||||
thAcc.catchThrowable(() -> initWrapper(BambooStalkBlock.class, BambooStalkBlock.MAPPING.runtimeClass()));
|
initWrapper(BambooStalkBlock.class, BambooStalkBlock.MAPPING.runtimeClass());
|
||||||
// minecraft.world
|
// minecraft.world
|
||||||
thAcc.catchThrowable(() -> initWrapper(AABB.class, AABB.MAPPING.runtimeClass()));
|
initWrapper(AABB.class, AABB.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ChunkPos.class, ChunkPos.MAPPING.runtimeClass()));
|
initWrapper(ChunkPos.class, ChunkPos.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ChunkStorage.class, ChunkStorage.MAPPING.runtimeClass()));
|
initWrapper(ChunkStorage.class, ChunkStorage.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(DamageSource.class, DamageSource.MAPPING.runtimeClass()));
|
initWrapper(DamageSource.class, DamageSource.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(DamageSources.class, DamageSources.MAPPING.runtimeClass()));
|
initWrapper(DamageSources.class, DamageSources.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(DataVersion.class, DataVersion.MAPPING.runtimeClass()));
|
initWrapper(Entity.class, Entity.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Entity.class, Entity.MAPPING.runtimeClass()));
|
initWrapper(ItemStack.class, ItemStack.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(ItemStack.class, ItemStack.MAPPING.runtimeClass()));
|
initWrapper(Level.class, Level.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Level.class, Level.MAPPING.runtimeClass()));
|
initWrapper(MapItemSavedData.class, MapItemSavedData.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(MapItemSavedData.class, MapItemSavedData.MAPPING.runtimeClass()));
|
initWrapper(PlayerDataStorage.class, PlayerDataStorage.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(PlayerDataStorage.class, PlayerDataStorage.MAPPING.runtimeClass()));
|
initWrapper(SavedData.class, SavedData.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(SavedData.class, SavedData.MAPPING.runtimeClass()));
|
initWrapper(Vec3.class, Vec3.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Vec3.class, Vec3.MAPPING.runtimeClass()));
|
initWrapper(VoxelShape.class, VoxelShape.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(VoxelShape.class, VoxelShape.MAPPING.runtimeClass()));
|
|
||||||
// minecraft
|
// minecraft
|
||||||
thAcc.catchThrowable(() -> initWrapper(DetectedVersion.class, DetectedVersion.MAPPING.runtimeClass()));
|
initWrapper(DetectedVersion.class, DetectedVersion.MAPPING.runtimeClass());
|
||||||
thAcc.catchThrowable(() -> initWrapper(SharedConstants.class, SharedConstants.MAPPING.runtimeClass()));
|
initWrapper(GameVersion.class, GameVersion.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(WorldVersion.class, WorldVersion.MAPPING.runtimeClass()));
|
initWrapper(SharedConstants.class, SharedConstants.MAPPING.runtimeClass());
|
||||||
|
initWrapper(WorldVersion.class, WorldVersion.MAPPING.runtimeClass());
|
||||||
|
|
||||||
// netty
|
// netty
|
||||||
thAcc.catchThrowable(() -> initWrapper(ByteBuf.class, ByteBuf.REFLECT.get()));
|
initWrapper(ByteBuf.class, ByteBuf.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(Unpooled.class, Unpooled.REFLECT.get()));
|
initWrapper(Unpooled.class, Unpooled.REFLECT.get());
|
||||||
|
|
||||||
// paper.configuration
|
// paper.configuration
|
||||||
thAcc.catchThrowable(() -> initWrapper(FallbackValue_Int.class, FallbackValue_Int.REFLECT.get()));
|
initWrapper(FallbackValue_Int.class, FallbackValue_Int.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(WorldConfiguration.class, WorldConfiguration.REFLECT.get()));
|
initWrapper(WorldConfiguration.class, WorldConfiguration.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(WorldConfiguration.Chunks.class, WorldConfiguration.Chunks.REFLECT.get()));
|
initWrapper(WorldConfiguration.Chunks.class, WorldConfiguration.Chunks.REFLECT.get());
|
||||||
// paper
|
// paper
|
||||||
thAcc.catchThrowable(() -> initWrapper(AABBVoxelShape.class, AABBVoxelShape.REFLECT.get()));
|
initWrapper(AABBVoxelShape.class, AABBVoxelShape.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(PaperAdventure.class, PaperAdventure.REFLECT.get()));
|
initWrapper(PaperAdventure.class, PaperAdventure.REFLECT.get());
|
||||||
thAcc.catchThrowable(() -> initWrapper(QueuedChangesMapLong2Object.class, QueuedChangesMapLong2Object.REFLECT.get()));
|
initWrapper(QueuedChangesMapLong2Object.class, QueuedChangesMapLong2Object.REFLECT.get());
|
||||||
|
|
||||||
|
|
||||||
thAcc.throwCatched();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.reflect.Reflect;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectClass;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ConcreteWrapper;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapperI;
|
||||||
|
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||||
|
|
||||||
|
@ConcreteWrapper(GameVersion.__concrete.class)
|
||||||
|
public interface GameVersion extends ReflectWrapperI {
|
||||||
|
ReflectClass<?> REFLECT = wrapEx(() -> Reflect.ofClass("com.mojang.bridge.game.GameVersion"));
|
||||||
|
ReflectMethod<?> getWorldVersion = wrapEx(() -> REFLECT.method("getWorldVersion"));
|
||||||
|
|
||||||
|
default int getWorldVersion() {
|
||||||
|
return (int) wrapReflectEx(() -> getWorldVersion.invoke(__getRuntimeInstance()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class __concrete extends ReflectWrapper implements GameVersion {
|
||||||
|
private __concrete(Object obj) {
|
||||||
|
super(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package fr.pandacube.lib.paper.reflect.wrapper.minecraft;
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft;
|
||||||
|
|
||||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
|
||||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
|
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||||
|
@ -2,24 +2,15 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft;
|
|||||||
|
|
||||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
|
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DataVersion;
|
|
||||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
|
||||||
import fr.pandacube.lib.reflect.wrapper.ConcreteWrapper;
|
import fr.pandacube.lib.reflect.wrapper.ConcreteWrapper;
|
||||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapperI;
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapperI;
|
||||||
|
|
||||||
import static fr.pandacube.lib.reflect.wrapper.ReflectWrapper.wrap;
|
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
|
||||||
|
|
||||||
@ConcreteWrapper(WorldVersion.__concrete.class)
|
@ConcreteWrapper(WorldVersion.__concrete.class)
|
||||||
public interface WorldVersion extends ReflectWrapperI {
|
public interface WorldVersion extends GameVersion {
|
||||||
ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.WorldVersion"));
|
ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.WorldVersion"));
|
||||||
ReflectMethod<?> getDataVersion = wrapEx(() -> MAPPING.mojMethod("getDataVersion"));
|
|
||||||
|
|
||||||
default DataVersion getDataVersion() {
|
|
||||||
return wrap(wrapReflectEx(() -> getDataVersion.invoke(__getRuntimeInstance())), DataVersion.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
|
|
||||||
|
|
||||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
|
||||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
|
||||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
|
||||||
|
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
|
||||||
|
|
||||||
public class DataVersion extends ReflectWrapper {
|
|
||||||
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.storage.DataVersion"));
|
|
||||||
private static final ReflectMethod<?> getVersion = wrapEx(() -> MAPPING.mojMethod("getVersion"));
|
|
||||||
private static final ReflectMethod<?> getSeries = wrapEx(() -> MAPPING.mojMethod("getSeries"));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int getVersion() {
|
|
||||||
return (int) wrapReflectEx(() -> getVersion.invoke(__getRuntimeInstance()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSeries() {
|
|
||||||
return (String) wrapReflectEx(() -> getSeries.invoke(__getRuntimeInstance()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected DataVersion(Object obj) {
|
|
||||||
super(obj);
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,9 +7,9 @@ import java.util.function.ToIntBiFunction;
|
|||||||
/**
|
/**
|
||||||
* Implementation of the <a href="https://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance algorithm</a>
|
* Implementation of the <a href="https://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance algorithm</a>
|
||||||
* that operate on characters. Its purpose is to compute a "distance" between two strings of characters, that represents
|
* that operate on characters. Its purpose is to compute a "distance" between two strings of characters, that represents
|
||||||
* how many edition operations must be performed on the first string ({@code initialString}) to optain the second
|
* how many edition operation it is needed to perform on the first string ({@code initialString}) to optain the second
|
||||||
* one ({@code finalString}).
|
* one ({@code finalString}).
|
||||||
* <p>
|
*
|
||||||
* All the parameters of the algorithm are configurable:
|
* All the parameters of the algorithm are configurable:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>The score of adding a character</li>
|
* <li>The score of adding a character</li>
|
||||||
@ -21,13 +21,15 @@ import java.util.function.ToIntBiFunction;
|
|||||||
* ToIntBiFunction)} (for a full control of the parameters) or {@link #LevenshteinDistance(String, String)} (to keep the
|
* ToIntBiFunction)} (for a full control of the parameters) or {@link #LevenshteinDistance(String, String)} (to keep the
|
||||||
* default parameters value); then to call the method {@link #getCurrentDistance()} to compute the Levenshtein distance
|
* default parameters value); then to call the method {@link #getCurrentDistance()} to compute the Levenshtein distance
|
||||||
* between the two strings.
|
* between the two strings.
|
||||||
* <p>
|
*
|
||||||
* A more advanced usage offer the possibility to progressively compute a distance from a predefined
|
* A more advanced usage offer the possibility to progressively compute a distance from a predefined
|
||||||
* {@code initialString} to a {@code finalString} that is feeded progressively using {@link #add(char)} or
|
* {@code initialString} to a {@code finalString} that is feeded progressively using {@link #add(char)} or
|
||||||
* {@link #add(String)}. This is useful if the {@code finalString} is an input that is currently being typed by the
|
* {@link #add(String)}. This is useful if the {@code finalString} is an input that is currently being typed by the
|
||||||
* user, so the application can progressively update a list of suggested words based on the distance.
|
* user, so the application can progressively update a list of suggested words based on the distance.
|
||||||
* For this usage, you can use those constructors to avoid initializing the {@code finalString}:
|
* For this usage, you can use those constructors to avoid initializing the {@code finalString}:
|
||||||
* {@link #LevenshteinDistance(String, int, int, ToIntBiFunction)} or {@link #LevenshteinDistance(String)}.
|
* {@link #LevenshteinDistance(String, int, int, ToIntBiFunction)} or {@link #LevenshteinDistance(String)}.
|
||||||
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class LevenshteinDistance {
|
public class LevenshteinDistance {
|
||||||
|
|
||||||
|
@ -1,104 +0,0 @@
|
|||||||
package fr.pandacube.lib.util;
|
|
||||||
|
|
||||||
import fr.pandacube.lib.util.ThrowableUtil.RunnableException;
|
|
||||||
import fr.pandacube.lib.util.ThrowableUtil.SupplierException;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class that delay and accumulate thown exceptions, that can be thrown later using {@link #throwCatched()}.
|
|
||||||
* @param <T> the type of {@link Throwable} to accumulate.
|
|
||||||
*/
|
|
||||||
public class ThrowableAccumulator<T extends Throwable> {
|
|
||||||
T base = null;
|
|
||||||
final Class<T> throwableType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link ThrowableAccumulator} with the specified throwable type.
|
|
||||||
* @param throwableType The type of the {@link Throwable} to accumulate.
|
|
||||||
*/
|
|
||||||
public ThrowableAccumulator(Class<T> throwableType) {
|
|
||||||
this.throwableType = throwableType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the provided {@link RunnableException}, catching an eventual exception to accumulate for later use.
|
|
||||||
* @param run the {@link RunnableException} to run.
|
|
||||||
* @throws Exception if an exception not handled by this accumulator is thrown.
|
|
||||||
*/
|
|
||||||
public void catchThrowable(RunnableException<Exception> run) throws Exception {
|
|
||||||
try {
|
|
||||||
run.run();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
accumulateThrowable(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the provided {@link SupplierException}, catching an eventual exception to accumulate for later use.
|
|
||||||
* @param supp the {@link SupplierException} to run.
|
|
||||||
* @param returnValueIfException The value to return if this accumulator catch an exception.
|
|
||||||
* @return The return value of the supplier, or {@code returnValueIfException} if this accumulator catch an exception.
|
|
||||||
* @throws Exception if an exception not handled by this accumulator is thrown.
|
|
||||||
* @param <R> the type of the return value of the supplier.
|
|
||||||
*/
|
|
||||||
public <R> R catchThrowable(SupplierException<R, Exception> supp, R returnValueIfException) throws Exception {
|
|
||||||
return catchThrowable(supp, (Supplier<R>) () -> returnValueIfException);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the provided {@link SupplierException}, catching an eventual exception to accumulate for later use.
|
|
||||||
* @param supp the {@link SupplierException} to run.
|
|
||||||
* @param returnValueIfException The value to return if this accumulator catch an exception.
|
|
||||||
* @return The return value of the supplier, or the return value of {@code returnValueIfException} if this
|
|
||||||
* accumulator catch an exception.
|
|
||||||
* @throws Exception if an exception not handled by this accumulator is thrown.
|
|
||||||
* @param <R> the type of the return value of both suppliers.
|
|
||||||
*/
|
|
||||||
public <R> R catchThrowable(SupplierException<R, Exception> supp, Supplier<R> returnValueIfException) throws Exception {
|
|
||||||
try {
|
|
||||||
return supp.get();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
accumulateThrowable(t);
|
|
||||||
}
|
|
||||||
return returnValueIfException.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void accumulateThrowable(Throwable t) throws Exception {
|
|
||||||
if (throwableType.isInstance(t)) {
|
|
||||||
synchronized (this) {
|
|
||||||
if (base == null)
|
|
||||||
base = throwableType.cast(t);
|
|
||||||
else {
|
|
||||||
base.addSuppressed(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throwEx(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Throws an exception if there is at least one catched by this accumulator.
|
|
||||||
* If multiple exception where catched, all the exception after the first one are added to the first one as
|
|
||||||
* suppressed exceptions.
|
|
||||||
* If no exception were catched, this method does nothing.
|
|
||||||
* @throws Exception the first accumulated throwable, the other ones being suppressed.
|
|
||||||
*/
|
|
||||||
public void throwCatched() throws Exception {
|
|
||||||
synchronized (this) {
|
|
||||||
if (base != null)
|
|
||||||
throwEx(base);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void throwEx(Throwable t) throws Exception {
|
|
||||||
if (t instanceof Error e)
|
|
||||||
throw e;
|
|
||||||
else if (t instanceof Exception e)
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user