OldCombatMechanics

OldCombatMechanics

46.1k Downloads

ArmorEquipEvent exception

sgdc3 opened this issue ยท 7 comments

commented

Info

  • Server version: Paper 1.13.1
  • OldCombatMechanics version: Jenkins build 58
  • Server log file: https://hastebin.com/okeculuzaw.cs
  • OldCombatMechanics config file: default config

Problem Description

Exception on armor equip event: https://hastebin.com/okeculuzaw.cs

commented

@sgdc3 Those hastebin links don't seem to actually load anything?

commented

@gvlfm78 that's why i should stop using hastebin, anyway, the cause is that the comphenix Attribute class uses numeric ids for enchants and etc but they were removed in 1.13

commented

๐Ÿค” and what were they replaced with?

commented

Minecraft namespaced keys

commented

๐Ÿค” ๐Ÿค” ๐Ÿค” We'll need to see if there's a way to keep compatibility with both systems...

commented

Consider using a nbt library like https://github.com/tr7zw/Item-NBT-API

commented

It already uses a (minimal) NBT library. The change does not seem to stem from what you said though @sgdc3.

The reason seems to be that the NBT hierarchy changed from:

public class NBTTagCompound extends NBTBase

to

public class NBTTagCompound implements NBTBase

and the code currently does:

BASE_CLASS = COMPOUND_CLASS.getSuperclass();

which now yields Object -- which has no getTypeId method.

Do you want to fix that or should I prepare something @gvlfm78?

EDIT:
This should actually do as the fix, as we already have a mechanism to get NMS classes. At least until Mojang renames the class...

diff --git a/src/main/java/com/comphenix/example/NbtFactory.java b/src/main/java/com/comphenix/example/NbtFactory.java
index 193bdc8..ac5d9b7 100644
--- a/src/main/java/com/comphenix/example/NbtFactory.java
+++ b/src/main/java/com/comphenix/example/NbtFactory.java
@@ -6,6 +6,8 @@ import com.google.common.collect.HashBiMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.MapMaker;
 import com.google.common.primitives.Primitives;
+import gvlfm78.plugin.OldCombatMechanics.utilities.reflection.Reflector;
+import gvlfm78.plugin.OldCombatMechanics.utilities.reflection.type.ClassType;
 import org.bukkit.Bukkit;
 import org.bukkit.Material;
 import org.bukkit.inventory.ItemStack;
@@ -50,7 +52,7 @@ public class NbtFactory {
 
                 // Prepare NBT
                 COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
-                BASE_CLASS = COMPOUND_CLASS.getSuperclass();
+                BASE_CLASS = Reflector.getClass(ClassType.NMS, "NBTBase");
                 NBT_GET_TYPE = getMethod(0, Modifier.STATIC, BASE_CLASS, "getTypeId");
                 NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, BASE_CLASS, "createTag", byte.class);