Skip to content

Commit b280b32

Browse files
committed
Support bungeecord-chat 1.21
1 parent 322cfa1 commit b280b32

File tree

1 file changed

+14
-6
lines changed
  • bukkit/src/main/java/io/github/rothes/protocolstringreplacer/util

1 file changed

+14
-6
lines changed

bukkit/src/main/java/io/github/rothes/protocolstringreplacer/util/SpigotUtils.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import net.md_5.bungee.chat.TextComponentSerializer;
2424
import net.md_5.bungee.chat.TranslatableComponentSerializer;
2525

26+
import java.lang.reflect.Constructor;
2627
import java.lang.reflect.Field;
28+
import java.lang.reflect.InvocationTargetException;
2729

2830
public class SpigotUtils {
2931

@@ -42,12 +44,12 @@ public class SpigotUtils {
4244
GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping();
4345
try {
4446
gsonBuilder.registerTypeAdapter(BaseComponent.class, new ComponentSerializer())
45-
.registerTypeAdapter(TextComponent.class, new TextComponentSerializer())
46-
.registerTypeAdapter(TranslatableComponent.class, new TranslatableComponentSerializer())
47-
.registerTypeAdapter(KeybindComponent.class, new KeybindComponentSerializer())
48-
.registerTypeAdapter(ScoreComponent.class, new ScoreComponentSerializer())
49-
.registerTypeAdapter(SelectorComponent.class, new SelectorComponentSerializer())
50-
.registerTypeAdapter(Entity.class, new EntitySerializer())
47+
.registerTypeAdapter(TextComponent.class, newInstance(TextComponentSerializer.class))
48+
.registerTypeAdapter(TranslatableComponent.class, newInstance(TranslatableComponentSerializer.class))
49+
.registerTypeAdapter(KeybindComponent.class, newInstance(KeybindComponentSerializer.class))
50+
.registerTypeAdapter(ScoreComponent.class, newInstance(ScoreComponentSerializer.class))
51+
.registerTypeAdapter(SelectorComponent.class, newInstance(SelectorComponentSerializer.class))
52+
.registerTypeAdapter(Entity.class, newInstance(EntitySerializer.class))
5153
.registerTypeAdapter(Text.class, new TextSerializer())
5254
.registerTypeAdapter(Item.class, new ItemSerializer())
5355
.registerTypeAdapter(ItemTag.class, new ItemTag.Serializer());
@@ -102,4 +104,10 @@ public static boolean compareComponents(BaseComponent[] a, BaseComponent[] b) {
102104
return true;
103105
}
104106

107+
private static Object newInstance(Class<?> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
108+
Constructor<?> constructor = clazz.getDeclaredConstructor();
109+
constructor.setAccessible(true);
110+
return constructor.newInstance();
111+
}
112+
105113
}

0 commit comments

Comments
 (0)