-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathChatPacketImpl19ToFuture.java
More file actions
61 lines (49 loc) · 2.42 KB
/
ChatPacketImpl19ToFuture.java
File metadata and controls
61 lines (49 loc) · 2.42 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package me.rayzr522.jsonmessage.compat.impl;
import me.rayzr522.jsonmessage.ReflectionHelper;
import me.rayzr522.jsonmessage.compat.ChatPacketCompat;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.UUID;
public class ChatPacketImpl19ToFuture implements ChatPacketCompat {
private final Constructor<?> chatPacketContructor;
private static int enumChatMessageTypeMessage;
private static int enumChatMessageTypeActionbar;
public ChatPacketImpl19ToFuture() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> NMS_I_CHAT_BASE_COMPONENT = ReflectionHelper.getClass("net.minecraft.network.chat.IChatBaseComponent");
// Class<?> NMS_CHAT_MESSAGE_TYPE = ReflectionHelper.getClass("net.minecraft.network.chat.ChatMessageType");
// TODO: looks like it might need to use ClientboundPlayerChatPacket instead?
// here's the signature, unsure how to use it as of yet tho:
// public ClientboundPlayerChatPacket(PlayerChatMessage playerChatMessage, ChatMessageType.b boundNetwork) {
// this.a = playerChatMessage;
// this.b = boundNetwork;
// }
Class<?> NMS_PACKET_PLAY_OUT_CHAT = ReflectionHelper.getClass("net.minecraft.network.protocol.game.ClientboundSystemChatPacket");
chatPacketContructor = NMS_PACKET_PLAY_OUT_CHAT.getConstructor(
NMS_I_CHAT_BASE_COMPONENT,
int.class
);
// Method getChatMessageType = NMS_CHAT_MESSAGE_TYPE.getMethod("a", byte.class);
enumChatMessageTypeMessage = 0; // getChatMessageType.invoke(null, (byte) 1);
enumChatMessageTypeActionbar = 0; // getChatMessageType.invoke(null, (byte) 2);
}
private Object createPacket(Object chatComponent, int type) {
try {
return chatPacketContructor.newInstance(
chatComponent,
type
);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public Object createActionbarPacket(Object chatComponent) {
return createPacket(chatComponent, enumChatMessageTypeActionbar);
}
@Override
public Object createTextPacket(Object chatComponent) {
return createPacket(chatComponent, enumChatMessageTypeMessage);
}
}