mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-04 06:28:51 +00:00
v2.7.8 Add 1.21.6 support
This commit is contained in:
1 parent
1321573296
commit
9257973247
8 files changed
+85
-36
No files matched your search
+2
-2
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>nightcore</artifactId>
|
<artifactId>nightcore</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>bridge</artifactId>
|
<artifactId>bridge</artifactId>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>utils</artifactId>
|
<artifactId>utils</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,11 @@ public class Reflex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object getFieldValue(@NotNull Object source, @NotNull String realName, @NotNull String obfName) {
|
||||||
|
Object byName = getFieldValue(source, realName);
|
||||||
|
return byName == null ? getFieldValue(source, obfName) : byName;
|
||||||
|
}
|
||||||
|
|
||||||
public static Object getFieldValue(@NotNull Object source, @NotNull String name) {
|
public static Object getFieldValue(@NotNull Object source, @NotNull String name) {
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = source instanceof Class<?> ? (Class<?>) source : source.getClass();
|
Class<?> clazz = source instanceof Class<?> ? (Class<?>) source : source.getClass();
|
||||||
@@ -160,6 +165,11 @@ public class Reflex {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Method getMethod(@NotNull Class<?> source, @NotNull String realName, @NotNull String obfName, @NotNull Class<?>... params) {
|
||||||
|
Method byName = getMethod(source, realName, params);
|
||||||
|
return byName == null ? getMethod(source, obfName, params) : byName;
|
||||||
|
}
|
||||||
|
|
||||||
public static Method getMethod(@NotNull Class<?> source, @NotNull String name, @NotNull Class<?>... params) {
|
public static Method getMethod(@NotNull Class<?> source, @NotNull String name, @NotNull Class<?>... params) {
|
||||||
try {
|
try {
|
||||||
return source.getDeclaredMethod(name, params);
|
return source.getDeclaredMethod(name, params);
|
||||||
|
|||||||
+5
-5
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>nightcore</artifactId>
|
<artifactId>nightcore</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>main</artifactId>
|
<artifactId>main</artifactId>
|
||||||
@@ -53,25 +53,25 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>bridge</artifactId>
|
<artifactId>bridge</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>utils</artifactId>
|
<artifactId>utils</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>paper</artifactId>
|
<artifactId>paper</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ package su.nightexpress.nightcore.util;
|
|||||||
|
|
||||||
import com.mojang.datafixers.DSL;
|
import com.mojang.datafixers.DSL;
|
||||||
import com.mojang.datafixers.DataFixer;
|
import com.mojang.datafixers.DataFixer;
|
||||||
import com.mojang.serialization.Dynamic;
|
import com.mojang.serialization.*;
|
||||||
import com.mojang.serialization.DynamicOps;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import su.nightexpress.nightcore.Engine;
|
||||||
import su.nightexpress.nightcore.NightCore;
|
import su.nightexpress.nightcore.NightCore;
|
||||||
import su.nightexpress.nightcore.core.CoreConfig;
|
import su.nightexpress.nightcore.core.CoreConfig;
|
||||||
|
|
||||||
@@ -36,6 +36,8 @@ public class ItemNbt {
|
|||||||
private static final Class<?> CLS_DATA_FIXERS = Reflex.getNMSClass("net.minecraft.util.datafix", "DataFixers", "DataConverterRegistry");
|
private static final Class<?> CLS_DATA_FIXERS = Reflex.getNMSClass("net.minecraft.util.datafix", "DataFixers", "DataConverterRegistry");
|
||||||
private static final Class<?> CLS_REFERENCES = Reflex.getNMSClass("net.minecraft.util.datafix.fixes", "References", "DataConverterTypes");
|
private static final Class<?> CLS_REFERENCES = Reflex.getNMSClass("net.minecraft.util.datafix.fixes", "References", "DataConverterTypes");
|
||||||
|
|
||||||
|
private static final Class<?> CLS_HOLDER_LOOKUP_PROVIDER = Reflex.getNMSClass("net.minecraft.core", "HolderLookup$Provider", "HolderLookup$a");
|
||||||
|
|
||||||
private static Method mCraftItemStackAsNmsCopy;
|
private static Method mCraftItemStackAsNmsCopy;
|
||||||
private static Method mCraftItemStackAsBukkitCopy;
|
private static Method mCraftItemStackAsBukkitCopy;
|
||||||
|
|
||||||
@@ -56,9 +58,15 @@ public class ItemNbt {
|
|||||||
private static Method mMinecraftItemStackOf;
|
private static Method mMinecraftItemStackOf;
|
||||||
private static Method mMinecraftItemStackSave;
|
private static Method mMinecraftItemStackSave;
|
||||||
|
|
||||||
// Base
|
// For 1.21.6+
|
||||||
|
private static Codec<?> itemStackCodec;
|
||||||
|
private static Method mCreateSerializationContext;
|
||||||
|
private static Method mEncodeStart;
|
||||||
|
private static Method mParse;
|
||||||
|
|
||||||
|
// Base
|
||||||
private static boolean useRegistry;
|
private static boolean useRegistry;
|
||||||
|
private static boolean useCodec;
|
||||||
private static Object registryAccess;
|
private static Object registryAccess;
|
||||||
private static boolean loaded;
|
private static boolean loaded;
|
||||||
|
|
||||||
@@ -82,9 +90,9 @@ public class ItemNbt {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mNbtIoWrite = Reflex.getMethod(CLS_NBT_IO, "a", CLS_COMPOUND_TAG, DataOutput.class);
|
mNbtIoWrite = Reflex.getMethod(CLS_NBT_IO, "write", "a", CLS_COMPOUND_TAG, DataOutput.class);
|
||||||
mNbtIoRead = Reflex.getMethod(CLS_NBT_IO, "a", DataInput.class);
|
mNbtIoRead = Reflex.getMethod(CLS_NBT_IO, "read", "a", DataInput.class);
|
||||||
mTagParserParseTag = Reflex.getMethod(CLS_TAG_PARSER, "a", String.class);
|
mTagParserParseTag = Reflex.getMethod(CLS_TAG_PARSER, "parseCompoundFully", "a", String.class);
|
||||||
|
|
||||||
if (mNbtIoWrite == null || mNbtIoRead == null || mTagParserParseTag == null) {
|
if (mNbtIoWrite == null || mNbtIoRead == null || mTagParserParseTag == null) {
|
||||||
core.error("[Item NBT] Could not find NbtIo or TagParser methods.");
|
core.error("[Item NBT] Could not find NbtIo or TagParser methods.");
|
||||||
@@ -92,15 +100,15 @@ public class ItemNbt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load DataFixer components.
|
// Load DataFixer components.
|
||||||
Method mGetDataFixer = Reflex.getMethod(CLS_DATA_FIXERS, "a");
|
Method mGetDataFixer = Reflex.getMethod(CLS_DATA_FIXERS, "getDataFixer", "a");
|
||||||
if (mGetDataFixer == null) {
|
if (mGetDataFixer == null) {
|
||||||
core.error("[Item NBT] Could not load DataFixer components.");
|
core.error("[Item NBT] Could not load DataFixer components.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dataFixer = (DataFixer) Reflex.invokeMethod(mGetDataFixer, CLS_DATA_FIXERS);
|
dataFixer = (DataFixer) Reflex.invokeMethod(mGetDataFixer, CLS_DATA_FIXERS);
|
||||||
nbtOps = Reflex.getFieldValue(CLS_NBT_OPS, "a");
|
nbtOps = Reflex.getFieldValue(CLS_NBT_OPS, "INSTANCE", "a");
|
||||||
itemStackReference = Reflex.getFieldValue(CLS_REFERENCES, "t");
|
itemStackReference = Reflex.getFieldValue(CLS_REFERENCES, "ITEM_STACK", Version.isAtLeast(Version.MC_1_21_6) ? "u" : "t");
|
||||||
|
|
||||||
// Load version specific item parsers.
|
// Load version specific item parsers.
|
||||||
if (Version.isAtLeast(Version.MC_1_20_6)) {
|
if (Version.isAtLeast(Version.MC_1_20_6)) {
|
||||||
@@ -124,18 +132,34 @@ public class ItemNbt {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?> clsHolderLookupProvider = Reflex.getNMSClass("net.minecraft.core", "HolderLookup$a"); // HolderLookup.Provider
|
Class<?> clsHolderLookupProvider = Reflex.getNMSClass("net.minecraft.core", "HolderLookup$Provider", "HolderLookup$a");
|
||||||
if (clsHolderLookupProvider == null) {
|
if (clsHolderLookupProvider == null) {
|
||||||
core.error("[Item NBT] Could not find MinecraftServer or HolderLookup#Provider.");
|
core.error("[Item NBT] Could not find MinecraftServer or HolderLookup#Provider.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mItemStackParse = Reflex.getMethod(CLS_MINECRAFT_ITEM_STACK, "a", clsHolderLookupProvider, CLS_TAG);
|
if (Version.isAtLeast(Version.MC_1_21_6)) {
|
||||||
mItemStackSave = Reflex.getMethod(CLS_MINECRAFT_ITEM_STACK, "a", clsHolderLookupProvider);
|
useCodec = true;
|
||||||
|
|
||||||
if (mItemStackParse == null || mItemStackSave == null) {
|
if (CLS_HOLDER_LOOKUP_PROVIDER == null) {
|
||||||
core.error("[Item NBT] Could not find ItemStack#parse or ItemStack#save methods.");
|
core.error("Class not found: HoolderLookup.Provider");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemStackCodec = (Codec<?>) Reflex.getFieldValue(CLS_MINECRAFT_ITEM_STACK, "CODEC", "b");
|
||||||
|
mCreateSerializationContext = Reflex.getMethod(CLS_HOLDER_LOOKUP_PROVIDER, "createSerializationContext", "a", DynamicOps.class);
|
||||||
|
|
||||||
|
mEncodeStart = Reflex.getMethod(Encoder.class, "encodeStart", DynamicOps.class, Object.class);
|
||||||
|
mParse = Reflex.getMethod(Decoder.class, "parse", DynamicOps.class, Object.class);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mItemStackParse = Reflex.getMethod(CLS_MINECRAFT_ITEM_STACK, "parse", "a", clsHolderLookupProvider, CLS_TAG);
|
||||||
|
mItemStackSave = Reflex.getMethod(CLS_MINECRAFT_ITEM_STACK, "save", "a", clsHolderLookupProvider);
|
||||||
|
|
||||||
|
if (mItemStackParse == null || mItemStackSave == null) {
|
||||||
|
core.error("[Item NBT] Could not find ItemStack#parse or ItemStack#save methods.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -152,9 +176,10 @@ public class ItemNbt {
|
|||||||
loaded = true;
|
loaded = true;
|
||||||
|
|
||||||
if (!test()) {
|
if (!test()) {
|
||||||
core.error("[Item NBT] Compression test failed.");
|
core.error("[Item NBT] Test failed.");
|
||||||
loaded = false;
|
loaded = false;
|
||||||
}
|
}
|
||||||
|
else core.info("[Item NBT] Test successful.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean test() {
|
public static boolean test() {
|
||||||
@@ -227,12 +252,6 @@ public class ItemNbt {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static ItemStack fromTagString(@NotNull String tagString) {
|
public static ItemStack fromTagString(@NotNull String tagString) {
|
||||||
// if (tagString.isBlank() || tagString.equalsIgnoreCase("{}")) return null;
|
|
||||||
//
|
|
||||||
// Object compoundTag = Reflex.invokeMethod(mTagParserParseTag, null, tagString);
|
|
||||||
// if (compoundTag != null) System.out.println("fromCompoundTag(compoundTag) = " + fromCompoundTag(compoundTag));
|
|
||||||
// return compoundTag == null ? null : fromCompoundTag(compoundTag);
|
|
||||||
|
|
||||||
return fromTag(new ItemTag(tagString, CoreConfig.DATA_FIXER_MISSING_VERSION.get()));
|
return fromTag(new ItemTag(tagString, CoreConfig.DATA_FIXER_MISSING_VERSION.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,6 +303,15 @@ public class ItemNbt {
|
|||||||
if (bukkitStack.getType().isAir() || bukkitStack.getAmount() <= 0) return null;
|
if (bukkitStack.getType().isAir() || bukkitStack.getAmount() <= 0) return null;
|
||||||
|
|
||||||
Object nmsStack = Reflex.invokeMethod(mCraftItemStackAsNmsCopy, null, bukkitStack);
|
Object nmsStack = Reflex.invokeMethod(mCraftItemStackAsNmsCopy, null, bukkitStack);
|
||||||
|
|
||||||
|
if (useCodec) {
|
||||||
|
Object context = createSerializationContext();
|
||||||
|
DataResult.Success<?> result = (DataResult.Success<?>) Reflex.invokeMethod(mEncodeStart, itemStackCodec, context, nmsStack);
|
||||||
|
if (result == null) return null;
|
||||||
|
|
||||||
|
return result.getOrThrow();
|
||||||
|
}
|
||||||
|
|
||||||
if (useRegistry) {
|
if (useRegistry) {
|
||||||
return Reflex.invokeMethod(mItemStackSave, nmsStack, registryAccess);
|
return Reflex.invokeMethod(mItemStackSave, nmsStack, registryAccess);
|
||||||
}
|
}
|
||||||
@@ -300,7 +328,14 @@ public class ItemNbt {
|
|||||||
Object itemStack;
|
Object itemStack;
|
||||||
Object compoundTag = ItemNbt.applyDataFixer(tag, sourceVersion);
|
Object compoundTag = ItemNbt.applyDataFixer(tag, sourceVersion);
|
||||||
|
|
||||||
if (useRegistry) {
|
if (useCodec) {
|
||||||
|
Object context = createSerializationContext();
|
||||||
|
DataResult<?> decoded = (DataResult<?>) Reflex.invokeMethod(mParse, itemStackCodec, context, tag);
|
||||||
|
if (decoded == null) return null;
|
||||||
|
|
||||||
|
itemStack = decoded.resultOrPartial(itemId -> Engine.core().error("Could not decode ItemStack from tag: " + itemId)).orElse(null);
|
||||||
|
}
|
||||||
|
else if (useRegistry) {
|
||||||
Optional<?> optional = (Optional<?>) Reflex.invokeMethod(mItemStackParse, null, registryAccess, compoundTag);
|
Optional<?> optional = (Optional<?>) Reflex.invokeMethod(mItemStackParse, null, registryAccess, compoundTag);
|
||||||
itemStack = Objects.requireNonNull(optional).orElse(null);
|
itemStack = Objects.requireNonNull(optional).orElse(null);
|
||||||
}
|
}
|
||||||
@@ -320,4 +355,8 @@ public class ItemNbt {
|
|||||||
Dynamic<?> dynamic = new Dynamic<>((DynamicOps) nbtOps, compoundTag);
|
Dynamic<?> dynamic = new Dynamic<>((DynamicOps) nbtOps, compoundTag);
|
||||||
return dataFixer.update((DSL.TypeReference) itemStackReference, dynamic, sourceVersion, targetVersion).getValue();
|
return dataFixer.update((DSL.TypeReference) itemStackReference, dynamic, sourceVersion, targetVersion).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Object createSerializationContext() {
|
||||||
|
return Reflex.invokeMethod(mCreateSerializationContext, registryAccess, nbtOps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>nightcore</artifactId>
|
<artifactId>nightcore</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>paper</artifactId>
|
<artifactId>paper</artifactId>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>bridge</artifactId>
|
<artifactId>bridge</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>nightcore</artifactId>
|
<artifactId>nightcore</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>main</module>
|
<module>main</module>
|
||||||
|
|||||||
+2
-2
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>nightcore</artifactId>
|
<artifactId>nightcore</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>bridge</artifactId>
|
<artifactId>bridge</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>nightcore</artifactId>
|
<artifactId>nightcore</artifactId>
|
||||||
<version>2.7.7</version>
|
<version>2.7.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>utils</artifactId>
|
<artifactId>utils</artifactId>
|
||||||
|
|||||||
Reference in new issue
Block a user