Skip to content

Commit

Permalink
spammer whilePlayerConnected setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Dec 8, 2024
1 parent bfb6b32 commit 4343456
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
12 changes: 11 additions & 1 deletion src/main/java/com/zenith/command/impl/SpammerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ public CommandUsage commandUsage() {
asList(
"on/off",
"whisper on/off",
"whilePlayerConnected on/off",
"delayTicks <int>",
"randomOrder on/off",
"appendRandom on/off",
"list",
"clear",
"add <message>",
"addAt <index> <message>",
"del <index>"),
"del <index>"
),
asList("spam")
);
}
Expand All @@ -62,6 +64,13 @@ public LiteralArgumentBuilder<CommandContext> register() {
.title("Whisper " + toggleStrCaps(CONFIG.client.extra.spammer.whisper));
return OK;
})))
.then(literal("whilePlayerConnected")
.then(argument("toggle", toggle()).executes(c -> {
CONFIG.client.extra.spammer.whilePlayerConnected = getToggle(c, "toggle");
c.getSource().getEmbed()
.title("While Player Connected " + toggleStrCaps(CONFIG.client.extra.spammer.whilePlayerConnected));
return OK;
})))
.then(literal("delayTicks")
.then(argument("delayTicks", integer(1, 10000)).executes(c -> {
CONFIG.client.extra.spammer.delayTicks = IntegerArgumentType.getInteger(c, "delayTicks");
Expand Down Expand Up @@ -140,6 +149,7 @@ public void postPopulate(final Embed builder) {
addListDescription(builder)
.addField("Spammer", toggleStr(CONFIG.client.extra.spammer.enabled), false)
.addField("Whisper", toggleStr(CONFIG.client.extra.spammer.whisper), false)
.addField("While Player Connected", toggleStr(CONFIG.client.extra.spammer.whilePlayerConnected), false)
.addField("Delay", CONFIG.client.extra.spammer.delayTicks, false)
.addField("Random Order", toggleStr(CONFIG.client.extra.spammer.randomOrder), false)
.addField("Append Random", toggleStr(CONFIG.client.extra.spammer.appendRandom), false)
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/com/zenith/module/impl/Spammer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.zenith.module.impl;

import com.zenith.event.module.ClientBotTick;
import com.zenith.Proxy;
import com.zenith.event.module.ClientTickEvent;
import com.zenith.module.Module;
import com.zenith.util.Timer;
import org.geysermc.mcprotocollib.protocol.data.game.PlayerListEntry;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatPacket;
import org.jetbrains.annotations.Nullable;

import java.time.Duration;
import java.util.HashSet;
import java.util.UUID;

Expand All @@ -22,8 +24,8 @@ public class Spammer extends Module {
public void subscribeEvents() {
EVENT_BUS.subscribe(
this,
of(ClientBotTick.class, this::handleClientTickEvent),
of(ClientBotTick.Starting.class, this::clientTickStarting)
of(ClientTickEvent.class, this::handleClientTickEvent),
of(ClientTickEvent.Starting.class, this::clientTickStarting)
);
}

Expand All @@ -42,12 +44,20 @@ public void onDisable() {
whisperedPlayers.clear();
}

public void handleClientTickEvent(final ClientBotTick event) {
public void handleClientTickEvent(final ClientTickEvent event) {
if (Proxy.getInstance().isInQueue()) return;
if (!Proxy.getInstance().isOnlineForAtLeastDuration(Duration.ofSeconds(5))) return;
if (!CONFIG.client.extra.spammer.whilePlayerConnected && Proxy.getInstance().hasActivePlayer()) return;
if (tickTimer.tick(CONFIG.client.extra.spammer.delayTicks)) {
sendSpam();
}
}

public void clientTickStarting(final ClientTickEvent.Starting event) {
tickTimer.reset();
spamIndex = 0;
}

private void sendSpam() {
if (CONFIG.client.extra.spammer.messages.isEmpty()) return;
if (CONFIG.client.extra.spammer.randomOrder) {
Expand All @@ -58,9 +68,11 @@ private void sendSpam() {
if (CONFIG.client.extra.spammer.whisper) {
String player = getNextPlayer();
if (player != null) {
debug("> /w {} {}", player, CONFIG.client.extra.spammer.messages.get(spamIndex));
sendClientPacketAsync(new ServerboundChatPacket("/w " + player + " " + CONFIG.client.extra.spammer.messages.get(spamIndex) + (CONFIG.client.extra.spammer.appendRandom ? " " + UUID.randomUUID().toString().substring(0, 6) : "")));
}
} else {
debug("> {}", CONFIG.client.extra.spammer.messages.get(spamIndex));
sendClientPacketAsync(new ServerboundChatPacket(CONFIG.client.extra.spammer.messages.get(spamIndex) + (CONFIG.client.extra.spammer.appendRandom ? " " + UUID.randomUUID().toString().substring(0, 6) : "")));
}
}
Expand All @@ -80,9 +92,4 @@ private void sendSpam() {
return getNextPlayer();
}
}

public void clientTickStarting(final ClientBotTick.Starting event) {
tickTimer.reset();
spamIndex = 0;
}
}
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 @@ -334,6 +334,7 @@ public static final class AutoRespawn {

public static final class Spammer {
public boolean enabled = false;
public boolean whilePlayerConnected = false;
public boolean whisper = false;
public long delayTicks = 200;
public boolean randomOrder = false;
Expand Down

0 comments on commit 4343456

Please sign in to comment.