aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/events/SkyblockEvents.java
blob: 4df22fe3f812bf0c82239a69449a931f4331c2df (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package de.hysky.skyblocker.events;

import de.hysky.skyblocker.utils.Area;
import de.hysky.skyblocker.utils.Location;
import de.hysky.skyblocker.utils.purse.PurseChangeCause;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;

@Environment(EnvType.CLIENT)
public final class SkyblockEvents {
	public static final Event<SkyblockJoin> JOIN = EventFactory.createArrayBacked(SkyblockJoin.class, callbacks -> () -> {
		for (SkyblockEvents.SkyblockJoin callback : callbacks) {
			callback.onSkyblockJoin();
		}
	});

	public static final Event<SkyblockLeave> LEAVE = EventFactory.createArrayBacked(SkyblockLeave.class, callbacks -> () -> {
		for (SkyblockLeave callback : callbacks) {
			callback.onSkyblockLeave();
		}
	});

	public static final Event<SkyblockLocationChange> LOCATION_CHANGE = EventFactory.createArrayBacked(SkyblockLocationChange.class, callbacks -> location -> {
		for (SkyblockLocationChange callback : callbacks) {
			callback.onSkyblockLocationChange(location);
		}
	});

	public static final Event<SkyblockAreaChange> AREA_CHANGE = EventFactory.createArrayBacked(SkyblockAreaChange.class, callbacks -> area -> {
		for (SkyblockAreaChange callback : callbacks) {
			callback.onSkyblockAreaChange(area);
		}
	});

	/**
	 * Called when the player's Skyblock profile changes.
	 *
	 * @implNote This is called upon receiving the chat message for the profile change rather than the exact moment of profile change, so it may be delayed by a few seconds.
	 */
	public static final Event<ProfileChange> PROFILE_CHANGE = EventFactory.createArrayBacked(ProfileChange.class, callbacks -> (prev, profile) -> {
		for (ProfileChange callback : callbacks) {
			callback.onSkyblockProfileChange(prev, profile);
		}
	});

	/**
	 * <p>Called when the player's skyblock profile is first detected via chat messages.</p>
	 * <p>This is useful for initializing data on features that track data for separate profiles separately.</p>
	 *
	 * @implNote This is called upon receiving the chat message for the profile change rather than the exact moment of profile change, so it may be delayed by a few seconds.
	 */
	public static final Event<ProfileInit> PROFILE_INIT = EventFactory.createArrayBacked(ProfileInit.class, callbacks -> profile -> {
		for (ProfileInit callback : callbacks) {
			callback.onSkyblockProfileInit(profile);
		}
	});

	public static final Event<PurseChange> PURSE_CHANGE = EventFactory.createArrayBacked(PurseChange.class, callbacks -> (diff, cause) -> {
		for (PurseChange callback : callbacks) {
			callback.onPurseChange(diff, cause);
		}
	});

	@Environment(EnvType.CLIENT)
	@FunctionalInterface
	public interface SkyblockJoin {
		void onSkyblockJoin();
	}

	@Environment(EnvType.CLIENT)
	@FunctionalInterface
	public interface SkyblockLeave {
		void onSkyblockLeave();
	}

	@Environment(EnvType.CLIENT)
	@FunctionalInterface
	public interface SkyblockLocationChange {
		void onSkyblockLocationChange(Location location);
	}

	@Environment(EnvType.CLIENT)
	@FunctionalInterface
	public interface SkyblockAreaChange {
		void onSkyblockAreaChange(Area area);
	}

	@Environment(EnvType.CLIENT)
	@FunctionalInterface
	public interface ProfileChange {
		void onSkyblockProfileChange(String prevProfileId, String profileId);
	}

	@Environment(EnvType.CLIENT)
	@FunctionalInterface
	public interface ProfileInit {
		void onSkyblockProfileInit(String profileId);
	}

	@Environment(EnvType.CLIENT)
	@FunctionalInterface
	public interface PurseChange {
		void onPurseChange(double diff, PurseChangeCause cause);
	}
}