aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/events/ChatEvents.java
blob: 2c50aeb056413d9a31419ae2cb1bee31d5b22bdd (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
package de.hysky.skyblocker.events;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Environment(EnvType.CLIENT)
public class ChatEvents {
	/**
	 * This will be called when a game message is received, cancelled or not.
	 *
	 * @implNote Not fired when {@code overlay} is {@code true}. See {@link de.hysky.skyblocker.mixins.MessageHandlerMixin#skyblocker$monitorGameMessage(Text, boolean, CallbackInfo) the mixin} for more information.
	 */
	@SuppressWarnings("JavadocReference")
	public static final Event<ChatTextEvent> RECEIVE_TEXT = EventFactory.createArrayBacked(ChatTextEvent.class, listeners -> message -> {
		for (ChatTextEvent listener : listeners) {
			listener.onMessage(message);
		}
	});

	/**
	 * This will be called when a game message is received, cancelled or not.
	 * This method is called with the result of {@link Text#getString()} to avoid each listener having to call it.
	 *
	 * @implNote Not fired when {@code overlay} is {@code true}. See {@link de.hysky.skyblocker.mixins.MessageHandlerMixin#skyblocker$monitorGameMessage(Text, boolean, CallbackInfo) the mixin} for more information.
	 */
	@SuppressWarnings("JavadocReference")
	public static final Event<ChatStringEvent> RECEIVE_STRING = EventFactory.createArrayBacked(ChatStringEvent.class, listeners -> message -> {
		for (ChatStringEvent listener : listeners) {
			listener.onMessage(message);
		}
	});

	@FunctionalInterface
	public interface ChatTextEvent {
		void onMessage(Text message);
	}

	@FunctionalInterface
	public interface ChatStringEvent {
		void onMessage(String message);
	}
}