Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tpa Flooding Button #1108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/main/java/net/wurstclient/hacks/MassTpaHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ public final class MassTpaHack extends Hack
+ " requests when someone accepts one of them.",
true);

private final CheckboxSetting isActiveMassTpaFlooding = new CheckboxSetting(
"TPA Flood", "Re-request TPA from all players except my friend", false);

private final Random random = new Random();
private final ArrayList<String> players = new ArrayList<>();

private String command;
private int index;
private int sendTpaCount;
private int timer;

public MassTpaHack()
Expand All @@ -72,14 +75,15 @@ public MassTpaHack()
addSetting(delay);
addSetting(ignoreErrors);
addSetting(stopWhenAccepted);
addSetting(isActiveMassTpaFlooding);
}

@Override
protected void onEnable()
{
// reset state
players.clear();
index = 0;
sendTpaCount = 0;
timer = 0;

// cache command in case the setting is changed mid-run
Expand All @@ -92,6 +96,10 @@ protected void onEnable()
String name = info.getProfile().getName();
name = StringHelper.stripTextFormat(name);

if(isActiveMassTpaFlooding.isChecked()
&& WURST.getFriends().contains(name))
continue;

if(name.equalsIgnoreCase(playerName))
continue;

Expand Down Expand Up @@ -126,16 +134,30 @@ public void onUpdate()
return;
}

if(index >= players.size())
if(isActiveMassTpaFlooding.isChecked()
&& sendTpaCount >= players.size())
{
sendTpaCount = 0;

if(command.equals("tpa"))
command = "tpacancel";

else if(command.equals("tpacancel"))
command = "tpa";
}

if(!isActiveMassTpaFlooding.isChecked()
&& sendTpaCount >= players.size())
{
command = commandSetting.getValue().substring(1);
setEnabled(false);
return;
}

MC.getNetworkHandler()
.sendChatCommand(command + " " + players.get(index));
.sendChatCommand(command + " " + players.get(sendTpaCount));

index++;
sendTpaCount++;
Comment on lines +158 to +160
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add rate limiting and error handling for network calls.

The command execution should include:

  1. Rate limiting to prevent server timeouts
  2. Error handling for network failures
  3. Logging for debugging purposes
+		try {
+			if (System.currentTimeMillis() - lastCommandTime < MIN_COMMAND_INTERVAL) {
+				return;
+			}
 			MC.getNetworkHandler()
 				.sendChatCommand(command + " " + players.get(sendTpaCount));
+			lastCommandTime = System.currentTimeMillis();
 			sendTpaCount++;
+		} catch (Exception e) {
+			ChatUtils.error("Failed to send command: " + e.getMessage());
+			setEnabled(false);
+		}

Committable suggestion skipped: line range outside the PR's diff.

timer = delay.getValueI() - 1;
}

Expand Down
Loading