-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathChatComponentImpl19ToFuture.java
More file actions
44 lines (37 loc) · 1.59 KB
/
ChatComponentImpl19ToFuture.java
File metadata and controls
44 lines (37 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package me.rayzr522.jsonmessage.compat.impl;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.rayzr522.jsonmessage.ReflectionHelper;
import me.rayzr522.jsonmessage.compat.ChatComponentCompat;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Type;
public class ChatComponentImpl19ToFuture implements ChatComponentCompat {
private final MethodHandle fromText;
private final MethodHandle fromJson;
public ChatComponentImpl19ToFuture() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException {
Class<?> IChatBaseComponent = ReflectionHelper.getClass("net.minecraft.network.chat.IChatBaseComponent$ChatSerializer");
Class<?> IChatBaseComponent_ChatSerializer = ReflectionHelper.getClass("net.minecraft.network.chat.IChatBaseComponent$ChatSerializer");
fromText = MethodHandles.lookup().unreflect(IChatBaseComponent.getMethod("b", String.class));
fromJson = MethodHandles.lookup().unreflect(IChatBaseComponent_ChatSerializer.getMethod("a", String.class));
}
@Override
public Object createComponent(String message) {
try {
return fromText.invoke(message);
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
@Override
public Object fromJson(JsonObject json) {
try {
return fromJson.invoke(json.toString());
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}