diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/players/PaperOffPlayer.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/players/PaperOffPlayer.java index f71f558..7ce8ff6 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/players/PaperOffPlayer.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/players/PaperOffPlayer.java @@ -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()); } /** diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/PandalibPaperReflect.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/PandalibPaperReflect.java index 1b0725a..9d94c3f 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/PandalibPaperReflect.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/PandalibPaperReflect.java @@ -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())); diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/nbt/NbtAccounter.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/nbt/NbtAccounter.java new file mode 100644 index 0000000..b536567 --- /dev/null +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/nbt/NbtAccounter.java @@ -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); + } +} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/nbt/NbtIo.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/nbt/NbtIo.java index 82b7134..7e06ae9 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/nbt/NbtIo.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/reflect/wrapper/minecraft/nbt/NbtIo.java @@ -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)); } }