blob: bfdbd5db6aa20af6b53cca006135368058c8fdc6 (
plain)
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
62
63
64
65
66
67
68
69
|
package kr.syeyoung.dungeonsguide.mod.chat;
import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
public class ChatTransmitter {
public static final String PREFIX = "§eDungeons Guide §7:: ";
public static String prefix = "§eDungeons Guide §7:: ";
public ChatTransmitter() {
MinecraftForge.EVENT_BUS.register(this);
}
static Queue<ChatComponentText> receiveQueue = new ConcurrentLinkedQueue<>();
public static void addToQueue(String chat, boolean noDupe) {
addToQueue(new ChatComponentText(chat), noDupe);
}
public static void addToQueue(ChatComponentText chat) {
addToQueue(chat, false);
}
public static void addToQueue(ChatComponentText chat, boolean noDupe) {
if(noDupe && receiveQueue.stream().anyMatch(a -> a.equals(chat))) return;
receiveQueue.add(chat);
}
public static void addToQueue(String s) {
addToQueue(s, false);
}
public static void sendDebugChat(IChatComponent iChatComponent) {
if(FeatureRegistry.DEBUG == null) return;
if (FeatureRegistry.DEBUG.isEnabled())
addToQueue((ChatComponentText) iChatComponent);
}
public static void sendDebugChat(String text) {
sendDebugChat(new ChatComponentText(text));
}
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent clientTickEvent) {
if(clientTickEvent.phase != TickEvent.Phase.START && Minecraft.getMinecraft().thePlayer == null) return;
if (!receiveQueue.isEmpty()) {
ClientChatReceivedEvent event = new ClientChatReceivedEvent((byte) 1, receiveQueue.poll());
MinecraftForge.EVENT_BUS.post(event);
if (!event.isCanceled()) {
Minecraft.getMinecraft().thePlayer.addChatMessage(event.message);
}
}
}
}
|