-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
JAXPLE
wants to merge
4
commits into
Wurst-Imperium:master
Choose a base branch
from
JAXPLE:MassTap-Scheduler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tpa Flooding Button #1108
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,12 +56,16 @@ public final class MassTpaHack extends Hack | |
"Stop when accepted", "Whether to stop sending more teleportation" | ||
+ " 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() | ||
|
@@ -72,44 +76,46 @@ 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 | ||
command = commandSetting.getValue().substring(1); | ||
|
||
// collect player names | ||
String playerName = MC.getSession().getUsername(); | ||
for(PlayerListEntry info : MC.player.networkHandler.getPlayerList()) | ||
{ | ||
for (PlayerListEntry info : MC.player.networkHandler.getPlayerList()) { | ||
String name = info.getProfile().getName(); | ||
name = StringHelper.stripTextFormat(name); | ||
if(name.equalsIgnoreCase(playerName)) | ||
|
||
if (isActiveMassTpaFlooding.isChecked() && WURST.getFriends().contains(name)) | ||
continue; | ||
|
||
|
||
if (name.equalsIgnoreCase(playerName)) | ||
continue; | ||
|
||
players.add(name); | ||
} | ||
|
||
Collections.shuffle(players, random); | ||
|
||
EVENTS.add(ChatInputListener.class, this); | ||
EVENTS.add(UpdateListener.class, this); | ||
|
||
if(players.isEmpty()) | ||
{ | ||
|
||
if (players.isEmpty()) { | ||
ChatUtils.error("Couldn't find any players."); | ||
setEnabled(false); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDisable() | ||
{ | ||
|
@@ -125,17 +131,29 @@ public void onUpdate() | |
timer--; | ||
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 = "/tpa"; | ||
setEnabled(false); | ||
return; | ||
} | ||
|
||
MC.getNetworkHandler() | ||
.sendChatCommand(command + " " + players.get(index)); | ||
.sendChatCommand(command + " " + players.get(sendTpaCount)); | ||
|
||
index++; | ||
sendTpaCount++; | ||
Comment on lines
+158
to
+160
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
+ 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);
+ }
|
||
timer = delay.getValueI() - 1; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add safeguards to command toggling logic.
Several improvements needed for the command toggling implementation:
📝 Committable suggestion