Skip to content

Commit

Permalink
Add version/branch mismatch alert
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNature committed Jan 16, 2025
1 parent 7ce4430 commit 8206006
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ public abstract class EVNTModule extends ApolloModule {
.node("regen-exhaustion-heal-amount").type(TypeToken.get(Integer.class))
.defaultValue(3).min(0).max(5).build();

public static final SimpleOption<Boolean> DISABLE_NOTIFY_MISMATCH = Option.<Boolean>builder()
.comment("Set to 'true' to disable notifications for players using the wrong branch or version, otherwise 'false'.")
.node("disable-notify-mismatch").type(TypeToken.get(Boolean.class))
.defaultValue(false).build();

public static final SimpleOption<Boolean> DEBUG = Option.<Boolean>builder()
.comment("Used for internal testing only.")
.node("debug").type(TypeToken.get(Boolean.class))
.defaultValue(false).build();

EVNTModule() {
this.registerOptions(
EVNTModule.DISABLE_ENDERPEARL_COOLDOWN,
Expand All @@ -143,7 +153,9 @@ public abstract class EVNTModule extends ApolloModule {
EVNTModule.OVERRIDE_REGEN,
EVNTModule.REGEN_INTERVAL,
EVNTModule.REGEN_HEAL_AMOUNT,
EVNTModule.REGEN_EXHAUSTION_HEAL_AMOUNT
EVNTModule.REGEN_EXHAUSTION_HEAL_AMOUNT,
EVNTModule.DISABLE_NOTIFY_MISMATCH,
EVNTModule.DEBUG
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
*/
package com.lunarclient.apollo.module.evnt;

import com.lunarclient.apollo.Apollo;
import com.lunarclient.apollo.client.version.MinecraftVersion;
import com.lunarclient.apollo.common.ApolloComponent;
import com.lunarclient.apollo.event.ApolloReceivePacketEvent;
import com.lunarclient.apollo.event.player.ApolloPlayerHandshakeEvent;
import com.lunarclient.apollo.evnt.v1.CharacterAbilityMessage;
import com.lunarclient.apollo.evnt.v1.CloseGuiMessage;
import com.lunarclient.apollo.evnt.v1.EventGameOverviewMessage;
Expand Down Expand Up @@ -55,6 +58,9 @@
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;

/**
* Provides the EVNT module.
Expand All @@ -71,6 +77,7 @@ public final class EVNTModuleImpl extends EVNTModule {
public EVNTModuleImpl() {
super();
this.handle(ApolloReceivePacketEvent.class, this::onCharacterSelection);
this.handle(ApolloPlayerHandshakeEvent.class, this::onApolloPlayerHandshake);
}


Expand Down Expand Up @@ -207,6 +214,10 @@ public void updateEventOverview(@NonNull Recipients recipients, @NonNull List<Ev
}

private void onCharacterSelection(ApolloReceivePacketEvent event) {
if (!this.getOptions().get(EVNTModule.DEBUG)) {
return;
}

event.unpack(OverrideCharacterMessage.class).ifPresent(packet -> {
ApolloPlayer apolloPlayer = event.getPlayer();

Expand All @@ -219,6 +230,36 @@ private void onCharacterSelection(ApolloReceivePacketEvent event) {
});
}

private void onApolloPlayerHandshake(ApolloPlayerHandshakeEvent event) {
if (this.getOptions().get(EVNTModule.DISABLE_NOTIFY_MISMATCH)) {
return;
}

boolean isRunningCorrectVersion = event.getMinecraftVersion() == MinecraftVersion.V1_18_2;
boolean isOnCorrectBranch = event.getLunarClientVersion().getGitBranch().contains("evnt");

if (isRunningCorrectVersion && isOnCorrectBranch) {
return;
}

String state = null;
if (!isRunningCorrectVersion && !isOnCorrectBranch) {
state = "branch and version!";
} else if (!isRunningCorrectVersion) {
state = "version!";
} else {
state = "branch!";
}

Component message = Component.text(event.getPlayer().getName(), NamedTextColor.RED)
.append(Component.text(" has connected without using the correct ", NamedTextColor.GRAY))
.append(Component.text(state, NamedTextColor.RED, TextDecoration.BOLD));

Apollo.getPlayerManager().getPlayers().stream()
.filter(player -> player.hasPermission("apollo.evnt.notify"))
.forEach(player -> player.sendMessage(message));
}

private com.lunarclient.apollo.evnt.v1.CharacterType toProtobuf(@NonNull CharacterType type) {
return com.lunarclient.apollo.evnt.v1.CharacterType.forNumber(type.ordinal() + 1);
}
Expand Down

0 comments on commit 8206006

Please sign in to comment.