From 23a5a6810fbb6611a4c49b7b9dc9bcf3b3bd2909 Mon Sep 17 00:00:00 2001 From: JwonLEE <114869036+JAXPLE@users.noreply.github.com> Date: Mon, 27 Jan 2025 18:45:01 +0900 Subject: [PATCH 1/4] Re-request TPA from all players except my friend. --- .../net/wurstclient/hacks/MassTpaHack.java | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/wurstclient/hacks/MassTpaHack.java b/src/main/java/net/wurstclient/hacks/MassTpaHack.java index a5897baca0..d8a7e03ecb 100644 --- a/src/main/java/net/wurstclient/hacks/MassTpaHack.java +++ b/src/main/java/net/wurstclient/hacks/MassTpaHack.java @@ -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 players = new ArrayList<>(); private String command; - private int index; + private int sendTpaCount; private int timer; public MassTpaHack() @@ -72,6 +76,7 @@ public MassTpaHack() addSetting(delay); addSetting(ignoreErrors); addSetting(stopWhenAccepted); + addSetting(isActiveMassTpaFlooding); } @Override @@ -79,37 +84,38 @@ 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++; timer = delay.getValueI() - 1; } From b88600b153b40c4c4490878a1715cb61c1075b27 Mon Sep 17 00:00:00 2001 From: JwonLEE <114869036+JAXPLE@users.noreply.github.com> Date: Mon, 27 Jan 2025 18:48:52 +0900 Subject: [PATCH 2/4] Re Formatting code --- .../net/wurstclient/hacks/MassTpaHack.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/wurstclient/hacks/MassTpaHack.java b/src/main/java/net/wurstclient/hacks/MassTpaHack.java index d8a7e03ecb..b70837ac7d 100644 --- a/src/main/java/net/wurstclient/hacks/MassTpaHack.java +++ b/src/main/java/net/wurstclient/hacks/MassTpaHack.java @@ -58,9 +58,8 @@ public final class MassTpaHack extends Hack true); private final CheckboxSetting isActiveMassTpaFlooding = new CheckboxSetting( - "TPA Flood", "Re-request TPA from all players except my friend", - false); - + "TPA Flood", "Re-request TPA from all players except my friend", false); + private final Random random = new Random(); private final ArrayList players = new ArrayList<>(); @@ -86,36 +85,39 @@ protected void onEnable() players.clear(); 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 (isActiveMassTpaFlooding.isChecked() && WURST.getFriends().contains(name)) + + if(isActiveMassTpaFlooding.isChecked() + && WURST.getFriends().contains(name)) continue; - - if (name.equalsIgnoreCase(playerName)) + + 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() { @@ -131,19 +133,21 @@ public void onUpdate() timer--; return; } - - if (isActiveMassTpaFlooding.isChecked() && sendTpaCount >= players.size()) + + if(isActiveMassTpaFlooding.isChecked() + && sendTpaCount >= players.size()) { sendTpaCount = 0; - - if (command.equals("tpa")) + + if(command.equals("tpa")) command = "tpacancel"; - - else if (command.equals("tpacancel")) + + else if(command.equals("tpacancel")) command = "tpa"; } - - if(!isActiveMassTpaFlooding.isChecked() && sendTpaCount >= players.size()) + + if(!isActiveMassTpaFlooding.isChecked() + && sendTpaCount >= players.size()) { command = "/tpa"; setEnabled(false); From 54b814e9fafd84f6b3af85f73286b2800529adaf Mon Sep 17 00:00:00 2001 From: JwonLEE <114869036+JAXPLE@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:04:52 +0900 Subject: [PATCH 3/4] Change Format --- src/main/java/net/wurstclient/hacks/MassTpaHack.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/wurstclient/hacks/MassTpaHack.java b/src/main/java/net/wurstclient/hacks/MassTpaHack.java index b70837ac7d..1a3a0433a6 100644 --- a/src/main/java/net/wurstclient/hacks/MassTpaHack.java +++ b/src/main/java/net/wurstclient/hacks/MassTpaHack.java @@ -56,7 +56,7 @@ 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); From 441c3e5b245590773176f489ccd05f77bdbe52df Mon Sep 17 00:00:00 2001 From: JwonLEE <114869036+JAXPLE@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:07:22 +0900 Subject: [PATCH 4/4] Refactor ref codeRabbit --- src/main/java/net/wurstclient/hacks/MassTpaHack.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/wurstclient/hacks/MassTpaHack.java b/src/main/java/net/wurstclient/hacks/MassTpaHack.java index 1a3a0433a6..c44de26bf3 100644 --- a/src/main/java/net/wurstclient/hacks/MassTpaHack.java +++ b/src/main/java/net/wurstclient/hacks/MassTpaHack.java @@ -149,7 +149,7 @@ else if(command.equals("tpacancel")) if(!isActiveMassTpaFlooding.isChecked() && sendTpaCount >= players.size()) { - command = "/tpa"; + command = commandSetting.getValue().substring(1); setEnabled(false); return; }