Skip to content

Commit

Permalink
Merge #899 (MassTPA command setting) into v7.39
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Nov 13, 2023
2 parents 10172e4 + 94906d0 commit 456a5d2
Showing 1 changed file with 27 additions and 5 deletions.
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 @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.regex.Pattern;

import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.util.StringHelper;
Expand All @@ -19,34 +20,51 @@
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.DontSaveState;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.TextFieldSetting;
import net.wurstclient.util.ChatUtils;

@SearchTags({"mass tpa"})
@DontSaveState
public final class MassTpaHack extends Hack
implements UpdateListener, ChatInputListener
{
private static final Pattern ALLOWED_COMMANDS =
Pattern.compile("^/+[a-zA-Z0-9_\\-]+$");

private final TextFieldSetting commandSetting =
new TextFieldSetting("Command",
"The command to use for teleporting.\n"
+ "Examples: /tp, /tpa, /tpahere, /tpo",
"/tpa",
s -> s.length() < 64 && ALLOWED_COMMANDS.matcher(s).matches());

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

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

public MassTpaHack()
{
super("MassTPA");
setCategory(Category.CHAT);
addSetting(commandSetting);
}

@Override
public void onEnable()
{
// reset state
players.clear();
index = 0;
timer = -1;

players.clear();
String playerName = MC.getSession().getUsername();
// 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())
{
String name = info.getProfile().getName();
Expand Down Expand Up @@ -92,7 +110,9 @@ public void onUpdate()
return;
}

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

index++;
timer = 20;
}
Expand All @@ -107,14 +127,16 @@ public void onReceivedMessage(ChatInputEvent event)
if(message.contains("/help") || message.contains("permission"))
{
event.cancel();
ChatUtils.error("This server doesn't have TPA.");
ChatUtils.error("This server doesn't have a "
+ command.toUpperCase() + " command.");
setEnabled(false);

}else if(message.contains("accepted") && message.contains("request")
|| message.contains("akzeptiert") && message.contains("anfrage"))
{
event.cancel();
ChatUtils.message("Someone accepted your TPA request. Stopping.");
ChatUtils.message("Someone accepted your " + command.toUpperCase()
+ " request. Stopping.");
setEnabled(false);
}
}
Expand Down

0 comments on commit 456a5d2

Please sign in to comment.