package com.example.addon.modules; import com.example.addon.QuinnAddon; import meteordevelopment.meteorclient.events.game.ReceiveMessageEvent; import meteordevelopment.meteorclient.settings.EnumSetting; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.settings.StringListSetting; import meteordevelopment.meteorclient.settings.StringSetting; import meteordevelopment.meteorclient.systems.friends.Friend; import meteordevelopment.meteorclient.systems.friends.Friends; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.utils.player.ChatUtils; import meteordevelopment.orbit.EventHandler; import net.minecraft.text.Text; import java.util.List; /** * Accepts teleport requests. Supplied by Rei; changed only where the original could not build here: * it referenced an {@code Addon} class and a {@code utils.Utils} helper that this addon does not * have, so the category comes from {@link QuinnAddon} and the toggle messages are left to Meteor, * which already prints them. The accept command is a setting because it is server-specific — * {@code /tpy} is not universal. */ public class AutoAccept extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); public enum Mode { Friends, Whitelist, Blacklist, All } private final Setting mode = sgGeneral.add(new EnumSetting.Builder() .name("mode") .description("Which players to accept requests from.") .defaultValue(Mode.Friends) .build()); private final Setting> whitelist = sgGeneral.add(new StringListSetting.Builder() .name("whitelist") .description("List of players to accept.") .visible(() -> mode.get() == Mode.Whitelist) .build()); private final Setting> blacklist = sgGeneral.add(new StringListSetting.Builder() .name("blacklist") .description("List of players to ignore.") .visible(() -> mode.get() == Mode.Blacklist) .build()); private final Setting acceptCommand = sgGeneral.add(new StringSetting.Builder() .name("accept-command") .description("Command sent to accept, with the player name appended. Servers differ: /tpy, /tpaccept, /tpayes.") .defaultValue("/tpy") .build()); public AutoAccept() { super(QuinnAddon.CATEGORY, "auto-accept", "Automatically accepts teleport requests."); } @EventHandler private void onMessageReceive(ReceiveMessageEvent event) { Text message = event.getMessage(); String text = message.getString(); if (text.contains("has requested to teleport") || text.contains("to teleport to you") || text.contains("has invited you to join them")) { String playerName = extractPlayerName(text); if (playerName != null && shouldAccept(playerName)) { info("Accepting teleport request from " + playerName); ChatUtils.sendPlayerMsg(acceptCommand.get() + " " + playerName); } } } private boolean shouldAccept(String playerName) { switch (mode.get()) { case Friends: for (Friend friend : Friends.get()) { if (friend.name.equalsIgnoreCase(playerName)) return true; } return false; case Whitelist: for (String name : whitelist.get()) { if (name.equalsIgnoreCase(playerName)) return true; } return false; case Blacklist: for (String name : blacklist.get()) { if (name.equalsIgnoreCase(playerName)) return false; } return true; case All: return true; default: return false; } } /** * Takes the first word of the message as the requester's name. That holds when the server puts * the name first, and breaks when it prefixes a rank or a tag — worth checking against the * server this is used on. */ private String extractPlayerName(String text) { String[] parts = text.split(" "); if (parts.length > 0) { return parts[0]; } return null; } }