Skip to content

Commit 44df32e

Browse files
Improve static startup speed
1 parent 51c778b commit 44df32e

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/main/java/me/flame/menus/components/nbt/LegacyNbt.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
import java.lang.reflect.Method;
1212
import java.util.Objects;
1313

14+
// changed
15+
1416
/**
1517
* Class to set / get NBT tags from items.
16-
* I hate this class.
18+
* I hate this class. I hate it. I hate it.
1719
*/
1820
public final class LegacyNbt implements NbtWrapper {
19-
2021
public static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName();
2122
public static final String NMS_VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf(46) + 1);
22-
2323
private static Method getStringMethod;
2424
private static Method setStringMethod;
2525
private static Method setBooleanMethod;
@@ -29,23 +29,28 @@ public final class LegacyNbt implements NbtWrapper {
2929
private static Method removeTagMethod;
3030
private static Method asNMSCopyMethod;
3131
private static Method asBukkitCopyMethod;
32-
32+
3333
private static final Material AIR = Material.AIR;
3434

3535
private static Constructor<?> nbtCompoundConstructor;
3636

3737
static {
3838
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);
4954
} catch (NoSuchMethodException e) {
5055
e.printStackTrace();
5156
}

0 commit comments

Comments
 (0)