Skip to content

Commit

Permalink
autodisconnect totem pop setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Nov 13, 2024
1 parent b86972a commit 41c14f6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/zenith/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import static com.zenith.Shared.*;
import static com.zenith.util.Config.Authentication.AccountType.MSA;
import static com.zenith.util.Config.Authentication.AccountType.OFFLINE;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;


Expand Down Expand Up @@ -717,6 +716,7 @@ public void handleConnectEvent(ConnectEvent event) {
public void handleStartQueueEvent(StartQueueEvent event) {
this.inQueue = true;
this.queuePosition = 0;
if (event.wasOnline()) this.connectTime = Instant.now();
}

public void handleQueuePositionUpdateEvent(QueuePositionUpdateEvent event) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/zenith/command/impl/AutoDisconnectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public CommandUsage commandUsage() {
* Health: Disconnects when health is below a set threshold level
* Thunder: Disconnects during thunderstorms (i.e. avoid lightning burning down bases)
* Unknown Player: Disconnects when a player not on the friends list, whitelist, or spectator whitelist is in visual range
* TotemPop: Disconnects when your totem is popped
Multiple modes can be enabled, they are non-exclusive
Settings non-exclusive to modes:
Expand All @@ -44,6 +45,7 @@ public CommandUsage commandUsage() {
"health <integer>",
"thunder on/off",
"unknownPlayer on/off",
"totemPop on/off",
"whilePlayerConnected on/off",
"autoClientDisconnect on/off",
"cancelAutoReconnect on/off"
Expand Down Expand Up @@ -109,6 +111,13 @@ public LiteralArgumentBuilder<CommandContext> register() {
c.getSource().getEmbed()
.title("AutoDisconnect WhilePlayerConnected " + toggleStrCaps(CONFIG.client.extra.utility.actions.autoDisconnect.whilePlayerConnected));
return 1;
})))
.then(literal("totemPop")
.then(argument("toggle", toggle()).executes(c -> {
CONFIG.client.extra.utility.actions.autoDisconnect.onTotemPop = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("AutoDisconnect TotemPop " + toggleStrCaps(CONFIG.client.extra.utility.actions.autoDisconnect.onTotemPop));
return 1;
})));
}

Expand All @@ -120,6 +129,7 @@ public void postPopulate(final Embed builder) {
.addField("Health Level", CONFIG.client.extra.utility.actions.autoDisconnect.health, false)
.addField("Thunder", toggleStr(CONFIG.client.extra.utility.actions.autoDisconnect.thunder), false)
.addField("UnknownPlayer", toggleStr(CONFIG.client.extra.utility.actions.autoDisconnect.onUnknownPlayerInVisualRange), false)
.addField("Totem Pop", toggleStr(CONFIG.client.extra.utility.actions.autoDisconnect.onTotemPop), false)
.addField("WhilePlayerConnected", toggleStr(CONFIG.client.extra.utility.actions.autoDisconnect.whilePlayerConnected), false)
.addField("AutoClientDisconnect", toggleStr(CONFIG.client.extra.utility.actions.autoDisconnect.autoClientDisconnect), false)
.addField("CancelAutoReconnect", toggleStr(CONFIG.client.extra.utility.actions.autoDisconnect.cancelAutoReconnect), false)
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/zenith/module/impl/AutoDisconnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.zenith.event.proxy.HealthAutoDisconnectEvent;
import com.zenith.event.proxy.NewPlayerInVisualRangeEvent;
import com.zenith.event.proxy.ProxyClientDisconnectedEvent;
import com.zenith.event.proxy.TotemPopEvent;
import com.zenith.module.Module;

import static com.github.rfresh2.EventConsumer.of;
Expand All @@ -25,7 +26,8 @@ public void subscribeEvents() {
of(PlayerHealthChangedEvent.class, this::handleLowPlayerHealthEvent),
of(WeatherChangeEvent.class, this::handleWeatherChangeEvent),
of(ProxyClientDisconnectedEvent.class, this::handleProxyClientDisconnectedEvent),
of(NewPlayerInVisualRangeEvent.class, this::handleNewPlayerInVisualRangeEvent)
of(NewPlayerInVisualRangeEvent.class, this::handleNewPlayerInVisualRangeEvent),
of(TotemPopEvent.class, this::handleTotemPopEvent)
);
}

Expand Down Expand Up @@ -76,6 +78,14 @@ public void handleNewPlayerInVisualRangeEvent(NewPlayerInVisualRangeEvent event)
Proxy.getInstance().disconnect(AUTO_DISCONNECT);
}

private void handleTotemPopEvent(TotemPopEvent event) {
if (!CONFIG.client.extra.utility.actions.autoDisconnect.onTotemPop) return;
if (playerConnectedCheck()) {
info("Totem popped");
Proxy.getInstance().disconnect(AUTO_DISCONNECT);
}
}

private boolean playerConnectedCheck() {
if (Proxy.getInstance().hasActivePlayer()) {
var whilePlayerConnected = CONFIG.client.extra.utility.actions.autoDisconnect.whilePlayerConnected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTabListPacket;

import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -63,7 +62,6 @@ private synchronized void parse2bQueueState(ClientboundTabListPacket packet, Cli
wasOnline = true;
wasOnlineDuration = Duration.ofSeconds(Proxy.getInstance().getOnlineTimeSeconds());
CLIENT_LOG.info("Detected that the client was kicked to queue. Was online for {}", formatDuration(wasOnlineDuration));
Proxy.getInstance().setConnectTime(Instant.now());
}
EVENT_BUS.postAsync(new StartQueueEvent(wasOnline, wasOnlineDuration));
queueDuration = Optional.empty();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/zenith/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public static final class AutoDisconnect {
// checks friends list, whitelist, and spectator whitelist
public boolean onUnknownPlayerInVisualRange = false;
public boolean mentionOnDisconnect = false;
public boolean onTotemPop = false;
}

public static final class ActiveHours {
Expand Down

0 comments on commit 41c14f6

Please sign in to comment.