forked from DFOnline/CodeClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
87 lines (80 loc) · 3.46 KB
/
Event.java
File metadata and controls
87 lines (80 loc) · 3.46 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
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
package dev.dfonline.codeclient;
import dev.dfonline.codeclient.command.CommandSender;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.location.*;
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.util.math.Vec3d;
import java.util.List;
/**
* Detects mode changes.
*/
public class Event {
private static Vec3d tp;
private static Sequence step = Sequence.WAIT_FOR_CLEAR;
private static boolean switchingMode = false;
public static <T extends PacketListener> void handlePacket(Packet<T> packet) {
if (packet instanceof ClearTitleS2CPacket clear) {
if (clear.shouldReset()) step = Sequence.WAIT_FOR_POS;
}
if (packet instanceof PlayerPositionLookS2CPacket pos) {
tp = new Vec3d(pos.change().position().x, pos.change().position().y, pos.change().position().z);
if (step == Sequence.WAIT_FOR_POS) step = Sequence.WAIT_FOR_MESSAGE;
}
if (packet instanceof OverlayMessageS2CPacket overlay) {
if (step == Sequence.WAIT_FOR_MESSAGE && overlay.text().getString().startsWith("DiamondFire - ")) {
updateLocation(new Spawn());
}
}
if (packet instanceof GameMessageS2CPacket message) {
if (step == Sequence.WAIT_FOR_MESSAGE) {
String content = message.content().getString();
if (content.equals("» You are now in dev mode.")) {
updateLocation(new Dev(tp.x, tp.z));
}
if (content.equals("» You are now in build mode.")) {
updateLocation(new Build(tp));
}
if (content.startsWith("» Joined game: ")) {
updateLocation(new Play());
}
}
}
if (packet instanceof GameJoinS2CPacket) {
updateLocation(new Spawn());
}
}
public static <T extends PacketListener> void onSendPacket(Packet<T> packet) {
if (packet instanceof CommandExecutionC2SPacket command) {
CommandSender.registerCommandSend();
if (List.of("play", "build", "code", "dev").contains(command.command().replaceFirst("mode ", ""))) {
switchingMode = true;
}
}
if (packet instanceof ChatMessageC2SPacket) {
CommandSender.registerCommandSend();
}
}
public static void updateLocation(Location location) {
CodeClient.lastLocation = CodeClient.location;
CodeClient.location = location;
if (switchingMode) {
switchingMode = false;
if (location instanceof Plot plot && CodeClient.lastLocation instanceof Plot last)
plot.copyValuesFrom(last);
CodeClient.LOGGER.info("Switched location: " + location.name());
} else CodeClient.LOGGER.info("Changed location: " + location.name());
step = Sequence.WAIT_FOR_CLEAR;
CodeClient.LOGGER.info("" + Config.getConfig().InvisibleBlocksInDev);
CodeClient.onModeChange(location);
if (Config.getConfig().InvisibleBlocksInDev) CodeClient.shouldReload = true;
}
private enum Sequence {
WAIT_FOR_CLEAR,
WAIT_FOR_POS,
WAIT_FOR_MESSAGE,
}
}