11
11
import java .lang .reflect .Method ;
12
12
import java .util .Objects ;
13
13
14
+ // changed
15
+
14
16
/**
15
17
* Class to set / get NBT tags from items.
16
- * I hate this class.
18
+ * I hate this class. I hate it. I hate it.
17
19
*/
18
20
public final class LegacyNbt implements NbtWrapper {
19
-
20
21
public static final String PACKAGE_NAME = Bukkit .getServer ().getClass ().getPackage ().getName ();
21
22
public static final String NMS_VERSION = PACKAGE_NAME .substring (PACKAGE_NAME .lastIndexOf (46 ) + 1 );
22
-
23
23
private static Method getStringMethod ;
24
24
private static Method setStringMethod ;
25
25
private static Method setBooleanMethod ;
@@ -29,23 +29,28 @@ public final class LegacyNbt implements NbtWrapper {
29
29
private static Method removeTagMethod ;
30
30
private static Method asNMSCopyMethod ;
31
31
private static Method asBukkitCopyMethod ;
32
-
32
+
33
33
private static final Material AIR = Material .AIR ;
34
34
35
35
private static Constructor <?> nbtCompoundConstructor ;
36
36
37
37
static {
38
38
try {
39
- getStringMethod = Objects .requireNonNull (getNMSClass ("NBTTagCompound" )).getMethod ("getString" , String .class );
40
- removeTagMethod = Objects .requireNonNull (getNMSClass ("NBTTagCompound" )).getMethod ("remove" , String .class );
41
- setStringMethod = Objects .requireNonNull (getNMSClass ("NBTTagCompound" )).getMethod ("setString" , String .class , String .class );
42
- setBooleanMethod = Objects .requireNonNull (getNMSClass ("NBTTagCompound" )).getMethod ("setBoolean" , String .class , boolean .class );
43
- hasTagMethod = Objects .requireNonNull (getNMSClass ("ItemStack" )).getMethod ("hasTag" );
44
- getTagMethod = Objects .requireNonNull (getNMSClass ("ItemStack" )).getMethod ("getTag" );
45
- setTagMethod = Objects .requireNonNull (getNMSClass ("ItemStack" )).getMethod ("setTag" , getNMSClass ("NBTTagCompound" ));
46
- nbtCompoundConstructor = Objects .requireNonNull (getNMSClass ("NBTTagCompound" )).getDeclaredConstructor ();
47
- asNMSCopyMethod = Objects .requireNonNull (getCraftItemStackClass ()).getMethod ("asNMSCopy" , ItemStack .class );
48
- asBukkitCopyMethod = Objects .requireNonNull (getCraftItemStackClass ()).getMethod ("asBukkitCopy" , getNMSClass ("ItemStack" ));
39
+ Class <?> nbtTag = Objects .requireNonNull (getNMSClass ("NBTTagCompound" ));
40
+ getStringMethod = nbtTag .getMethod ("getString" , String .class );
41
+ removeTagMethod = nbtTag .getMethod ("remove" , String .class );
42
+ setStringMethod = nbtTag .getMethod ("setString" , String .class , String .class );
43
+ setBooleanMethod = nbtTag .getMethod ("setBoolean" , String .class , boolean .class );
44
+
45
+ Class <?> craftItemStack = Objects .requireNonNull (getNMSClass ("ItemStack" ));
46
+ hasTagMethod = craftItemStack .getMethod ("hasTag" );
47
+ getTagMethod = craftItemStack .getMethod ("getTag" );
48
+ setTagMethod = craftItemStack .getMethod ("setTag" , nbtTag );
49
+ nbtCompoundConstructor = nbtTag .getDeclaredConstructor ();
50
+
51
+ Class <?> craftItemStackClass = Objects .requireNonNull (getCraftItemStackClass ());
52
+ asNMSCopyMethod = craftItemStackClass .getMethod ("asNMSCopy" , ItemStack .class );
53
+ asBukkitCopyMethod = craftItemStackClass .getMethod ("asBukkitCopy" , craftItemStack );
49
54
} catch (NoSuchMethodException e ) {
50
55
e .printStackTrace ();
51
56
}
0 commit comments