diff --git a/src/main/java/net/wurstclient/hacks/MassTpaHack.java b/src/main/java/net/wurstclient/hacks/MassTpaHack.java index 94fc2b87aa..acfe45b530 100644 --- a/src/main/java/net/wurstclient/hacks/MassTpaHack.java +++ b/src/main/java/net/wurstclient/hacks/MassTpaHack.java @@ -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; @@ -19,6 +20,7 @@ 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"}) @@ -26,9 +28,20 @@ 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 players = new ArrayList<>(); + private String command; private int index; private int timer; @@ -36,17 +49,22 @@ 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(); @@ -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; } @@ -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); } }