Fix 1.20.4 reflection wrappers

This commit is contained in:
Marc Baloup 2024-02-21 11:56:11 +01:00
parent 7d89f0c376
commit 649e1a56c8
4 changed files with 41 additions and 15 deletions

View File

@ -196,7 +196,7 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
File old = getPlayerDataFile(true);
old.delete();
Files.move(file.toPath(), old.toPath());
NbtIo.writeCompressed(data.data, file);
NbtIo.writeCompressed(data.data, file.toPath());
}
/**

View File

@ -31,6 +31,7 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.Vec3i;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CollectionTag;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.ListTag;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.NbtAccounter;
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;
@ -141,6 +142,7 @@ public class PandalibPaperReflect {
thAcc.catchThrowable(() -> initWrapper(CollectionTag.class, CollectionTag.MAPPING.runtimeClass()));
thAcc.catchThrowable(() -> initWrapper(CompoundTag.class, CompoundTag.MAPPING.runtimeClass()));
thAcc.catchThrowable(() -> initWrapper(ListTag.class, ListTag.MAPPING.runtimeClass()));
thAcc.catchThrowable(() -> initWrapper(NbtAccounter.class, NbtAccounter.MAPPING.runtimeClass()));
thAcc.catchThrowable(() -> initWrapper(NbtIo.class, NbtIo.MAPPING.runtimeClass()));
thAcc.catchThrowable(() -> initWrapper(StringTag.class, StringTag.MAPPING.runtimeClass()));
thAcc.catchThrowable(() -> initWrapper(Tag.class, Tag.MAPPING.runtimeClass()));

View File

@ -0,0 +1,25 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
import fr.pandacube.lib.reflect.ReflectMethod;
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
import java.io.File;
import java.nio.file.Path;
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
public class NbtAccounter extends ReflectWrapper {
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.NbtAccounter"));
private static final ReflectMethod<?> unlimitedHeap = wrapEx(() -> MAPPING.mojMethod("unlimitedHeap"));
private NbtAccounter(Object obj) {
super(obj);
}
public static NbtAccounter unlimitedHeap() {
return wrap(wrapEx(() -> unlimitedHeap.invokeStatic()), NbtAccounter.class);
}
}

View File

@ -1,18 +1,18 @@
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
import fr.pandacube.lib.reflect.ReflectMethod;
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
import java.nio.file.Path;
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
import java.io.File;
import fr.pandacube.lib.reflect.ReflectMethod;
import fr.pandacube.lib.paper.reflect.NMSReflect;
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
import fr.pandacube.lib.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 static final ReflectMethod<?> readCompressed = wrapEx(() -> MAPPING.mojMethod("readCompressed", Path.class, NbtAccounter.MAPPING));
private static final ReflectMethod<?> writeCompressed = wrapEx(() -> MAPPING.mojMethod("writeCompressed", CompoundTag.MAPPING, Path.class));
private NbtIo(Object obj) {
super(obj);
@ -20,12 +20,11 @@ public class NbtIo extends ReflectWrapper {
public static CompoundTag readCompressed(File f) {
return wrap(wrapEx(() -> readCompressed.invokeStatic(f)), CompoundTag.class);
public static CompoundTag readCompressed(Path p, NbtAccounter accounter) {
return wrap(wrapEx(() -> readCompressed.invokeStatic(p, unwrap(accounter))), CompoundTag.class);
}
public static void writeCompressed(CompoundTag tag, File f) {
Object nmsTag = ReflectWrapper.unwrap(tag);
wrapEx(() -> writeCompressed.invokeStatic(nmsTag, f));
public static void writeCompressed(CompoundTag tag, Path p) {
wrapEx(() -> writeCompressed.invokeStatic(unwrap(tag), p));
}
}