Skip to content

Commit 2437cbb

Browse files
committed
Add data component support for 1.21.4
1 parent 420b785 commit 2437cbb

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/npc/CitizensRegistry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public CitizensRegistry() {
4141
this.getIdMethod = ReflectionUtil.getMethod(this.npcClass, "getId");
4242
this.getNPCMethod = ReflectionUtil.getMethodByParams(
4343
this.npcRegistry.getClass(),
44-
"getNPC", Entity.class
44+
new String[]{"getNPC"},
45+
Entity.class
4546
);
4647
}
4748

bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/registry/replacer/PlaceholderApiReplacerRegistry.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public String replace(PlayerWrapper<?> playerWrapper, String text) {
4444

4545
private Method getPlaceholdersMethod() {
4646
Class<?> clazz = ReflectionUtil.classForName("me.clip.placeholderapi.PlaceholderAPI");
47-
return ReflectionUtil.getMethodByParams(clazz, "setPlaceholders", OfflinePlayer.class, String.class);
47+
return ReflectionUtil.getMethodByParams(
48+
clazz,
49+
new String[]{"setPlaceholders"},
50+
OfflinePlayer.class,
51+
String.class
52+
);
4853
}
4954
}

bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/util/BukkitDataComponentUtil.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import java.lang.reflect.Field;
2424
import java.lang.reflect.InvocationTargetException;
2525
import java.lang.reflect.Method;
26-
import java.util.LinkedHashMap;
27-
import java.util.Locale;
28-
import java.util.Map;
29-
import java.util.Objects;
26+
import java.util.*;
3027

3128
public final class BukkitDataComponentUtil {
3229

@@ -72,6 +69,8 @@ public final class BukkitDataComponentUtil {
7269
.getClassIfExists("net.minecraft.network.chat.Component");
7370
private static final Class<?> TAG = ReflectionUtil
7471
.getClassIfExists("net.minecraft.nbt.Tag");
72+
private static final Class<?> REFERENCE = ReflectionUtil
73+
.getClassIfExists("net.minecraft.core.Holder$Reference");
7574

7675
private static final Field NBT_OPS_INSTANCE =
7776
ReflectionUtil.getDeclaredField(NBT_OPS, "INSTANCE");
@@ -89,7 +88,7 @@ public final class BukkitDataComponentUtil {
8988
private static final Method RESOURCE_LOCATION_READ = ReflectionUtil
9089
.getStaticMethod(RESOURCE_LOCATION, RESOURCE_LOCATION, STRING_READER);
9190
private static final Method MAPPED_REGISTRY_GET = ReflectionUtil
92-
.getMethodByParams(MAPPED_REGISTRY, "get", RESOURCE_LOCATION);
91+
.getMethodByParams(MAPPED_REGISTRY, new String[]{"getValue", "get"}, RESOURCE_LOCATION);
9392
private static final Method CODEC_OR_THROW = ReflectionUtil
9493
.getMethod(DATA_COMPONENT_TYPE, "codecOrThrow");
9594
private static final Method PARSE = ReflectionUtil
@@ -116,6 +115,8 @@ public final class BukkitDataComponentUtil {
116115
.getMethod(COMPONENT, 0, "getString");
117116
private static final Method TAG_PARSER_READ_VALUE = ReflectionUtil
118117
.getMethod(TAG_PARSER, "readValue");
118+
private static final Method HOLDER_VALUE = ReflectionUtil
119+
.getMethod(REFERENCE, "value");
119120

120121
private static final Constructor<?> STRING_READER_CON =
121122
ReflectionUtil.getConstructor(STRING_READER, String.class);

core/src/main/java/com/clubobsidian/dynamicgui/core/util/ReflectionUtil.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@ public static Method getMethod(@Nullable Class<?> cl, int paramCount, String...
100100
return null;
101101
}
102102

103-
public static Method getMethodByParams(Class<?> cl, String methodName, Class<?>... params) {
103+
public static Method getMethodByParams(Class<?> cl, String[] methodNames, Class<?>... params) {
104104
if (cl == null) {
105105
return null;
106106
}
107-
try {
108-
Method method = cl.getDeclaredMethod(methodName, params);
109-
method.setAccessible(true);
110-
return method;
111-
} catch (NoSuchMethodException | SecurityException e) {
112-
e.printStackTrace();
107+
for (String methodName : methodNames) {
108+
try {
109+
Method method = cl.getDeclaredMethod(methodName, params);
110+
method.setAccessible(true);
111+
return method;
112+
} catch (NoSuchMethodException | SecurityException e) {
113+
}
113114
}
114115
return null;
115116
}

0 commit comments

Comments
 (0)