Skip to content

Commit 8206006

Browse files
committed
Add version/branch mismatch alert
1 parent 7ce4430 commit 8206006

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

api/src/main/java/com/lunarclient/apollo/module/evnt/EVNTModule.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ public abstract class EVNTModule extends ApolloModule {
126126
.node("regen-exhaustion-heal-amount").type(TypeToken.get(Integer.class))
127127
.defaultValue(3).min(0).max(5).build();
128128

129+
public static final SimpleOption<Boolean> DISABLE_NOTIFY_MISMATCH = Option.<Boolean>builder()
130+
.comment("Set to 'true' to disable notifications for players using the wrong branch or version, otherwise 'false'.")
131+
.node("disable-notify-mismatch").type(TypeToken.get(Boolean.class))
132+
.defaultValue(false).build();
133+
134+
public static final SimpleOption<Boolean> DEBUG = Option.<Boolean>builder()
135+
.comment("Used for internal testing only.")
136+
.node("debug").type(TypeToken.get(Boolean.class))
137+
.defaultValue(false).build();
138+
129139
EVNTModule() {
130140
this.registerOptions(
131141
EVNTModule.DISABLE_ENDERPEARL_COOLDOWN,
@@ -143,7 +153,9 @@ public abstract class EVNTModule extends ApolloModule {
143153
EVNTModule.OVERRIDE_REGEN,
144154
EVNTModule.REGEN_INTERVAL,
145155
EVNTModule.REGEN_HEAL_AMOUNT,
146-
EVNTModule.REGEN_EXHAUSTION_HEAL_AMOUNT
156+
EVNTModule.REGEN_EXHAUSTION_HEAL_AMOUNT,
157+
EVNTModule.DISABLE_NOTIFY_MISMATCH,
158+
EVNTModule.DEBUG
147159
);
148160
}
149161

common/src/main/java/com/lunarclient/apollo/module/evnt/EVNTModuleImpl.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
*/
2424
package com.lunarclient.apollo.module.evnt;
2525

26+
import com.lunarclient.apollo.Apollo;
27+
import com.lunarclient.apollo.client.version.MinecraftVersion;
2628
import com.lunarclient.apollo.common.ApolloComponent;
2729
import com.lunarclient.apollo.event.ApolloReceivePacketEvent;
30+
import com.lunarclient.apollo.event.player.ApolloPlayerHandshakeEvent;
2831
import com.lunarclient.apollo.evnt.v1.CharacterAbilityMessage;
2932
import com.lunarclient.apollo.evnt.v1.CloseGuiMessage;
3033
import com.lunarclient.apollo.evnt.v1.EventGameOverviewMessage;
@@ -55,6 +58,9 @@
5558
import java.util.List;
5659
import java.util.UUID;
5760
import java.util.stream.Collectors;
61+
import net.kyori.adventure.text.Component;
62+
import net.kyori.adventure.text.format.NamedTextColor;
63+
import net.kyori.adventure.text.format.TextDecoration;
5864

5965
/**
6066
* Provides the EVNT module.
@@ -71,6 +77,7 @@ public final class EVNTModuleImpl extends EVNTModule {
7177
public EVNTModuleImpl() {
7278
super();
7379
this.handle(ApolloReceivePacketEvent.class, this::onCharacterSelection);
80+
this.handle(ApolloPlayerHandshakeEvent.class, this::onApolloPlayerHandshake);
7481
}
7582

7683

@@ -207,6 +214,10 @@ public void updateEventOverview(@NonNull Recipients recipients, @NonNull List<Ev
207214
}
208215

209216
private void onCharacterSelection(ApolloReceivePacketEvent event) {
217+
if (!this.getOptions().get(EVNTModule.DEBUG)) {
218+
return;
219+
}
220+
210221
event.unpack(OverrideCharacterMessage.class).ifPresent(packet -> {
211222
ApolloPlayer apolloPlayer = event.getPlayer();
212223

@@ -219,6 +230,36 @@ private void onCharacterSelection(ApolloReceivePacketEvent event) {
219230
});
220231
}
221232

233+
private void onApolloPlayerHandshake(ApolloPlayerHandshakeEvent event) {
234+
if (this.getOptions().get(EVNTModule.DISABLE_NOTIFY_MISMATCH)) {
235+
return;
236+
}
237+
238+
boolean isRunningCorrectVersion = event.getMinecraftVersion() == MinecraftVersion.V1_18_2;
239+
boolean isOnCorrectBranch = event.getLunarClientVersion().getGitBranch().contains("evnt");
240+
241+
if (isRunningCorrectVersion && isOnCorrectBranch) {
242+
return;
243+
}
244+
245+
String state = null;
246+
if (!isRunningCorrectVersion && !isOnCorrectBranch) {
247+
state = "branch and version!";
248+
} else if (!isRunningCorrectVersion) {
249+
state = "version!";
250+
} else {
251+
state = "branch!";
252+
}
253+
254+
Component message = Component.text(event.getPlayer().getName(), NamedTextColor.RED)
255+
.append(Component.text(" has connected without using the correct ", NamedTextColor.GRAY))
256+
.append(Component.text(state, NamedTextColor.RED, TextDecoration.BOLD));
257+
258+
Apollo.getPlayerManager().getPlayers().stream()
259+
.filter(player -> player.hasPermission("apollo.evnt.notify"))
260+
.forEach(player -> player.sendMessage(message));
261+
}
262+
222263
private com.lunarclient.apollo.evnt.v1.CharacterType toProtobuf(@NonNull CharacterType type) {
223264
return com.lunarclient.apollo.evnt.v1.CharacterType.forNumber(type.ordinal() + 1);
224265
}

0 commit comments

Comments
 (0)