carson

make me a minecraft java 26.3 plugin for paper where it has a /tpa command where you type /tpa {player} and the other player can type /tpaccept {player} also make it not teleport instantly when someone accepts make there be a timer above the players hotbar saying teleporting in 3 2 1 and also i want it to have a /tpauto where it auto accepts all teleports and if you type /tpauto it says above the players hotbar in green {you have tpauto on} and when the player dies it wont accept any teleports and tpauto turns off when you die

Kodari AI
KodariNov 9 at 10:37 pm 2
TeleportRequestSystem
A Minecraft Paper plugin providing a teleport request system. Players use /tpa {player} to send a teleport request, and the target accepts via /tpaccept {player}. Upon acceptance, a countdown timer displays above the hotbar showing "Teleporting in 3 2 1" before the teleport executes. Players can enable /tpauto to automatically accept all incoming requests, with a green hotbar message confirming activation. The auto-accept feature disables upon player death, and no teleports are accepted while dead. Includes request management, cooldowns, and configurable messages.

Created the Paper plugin with /tpa, /tpaccept, and /tpauto.

Teleports have a three-second action-bar countdown. Death disables auto-accept and cancels pending requests and countdowns.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 169
src/main/java/com/kodari/simpletpa/SimpleTPA.java
package com.kodari.simpletpa;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public final class SimpleTPA extends JavaPlugin implements Listener {
    private final Map<UUID, UUID> requests = new HashMap<>();
    private final Set<UUID> autoAccept = new HashSet<>();
    private final Map<UUID, Long> generations = new HashMap<>();

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("Only players can use this command.");
            return true;
        }

        if (command.getName().equalsIgnoreCase("tpauto")) {
            if (args.length != 0) return false;
            if (autoAccept.remove(player.getUniqueId())) {
                player.sendActionBar(Component.text("You have tpauto off", NamedTextColor.RED));
            } else if (!player.isDead()) {
                autoAccept.add(player.getUniqueId());
                player.sendActionBar(Component.text("You have tpauto on", NamedTextColor.GREEN));
            } else {
                player.sendMessage(Component.text("You cannot enable tpauto while dead.", NamedTextColor.RED));
            }
            return true;
        }

        if (args.length != 1) return false;
        Player other = Bukkit.getPlayerExact(args[0]);
        if (other == null || !other.isOnline()) {
            player.sendMessage(Component.text("That player is not online.", NamedTextColor.RED));
            return true;
        }
        if (player.equals(other)) {
            player.sendMessage(Component.text("You cannot teleport to yourself.", NamedTextColor.RED));
            return true;
        }
        if (player.isDead() || other.isDead()) {
            player.sendMessage(Component.text("Teleport requests cannot be used while either player is dead.", NamedTextColor.RED));
            return true;
        }

        if (command.getName().equalsIgnoreCase("tpa")) {
            requests.remove(player.getUniqueId());
            if (autoAccept.contains(other.getUniqueId())) {
                player.sendMessage(Component.text(other.getName() + " automatically accepted your teleport request.", NamedTextColor.GREEN));
                other.sendMessage(Component.text("Automatically accepted a teleport request from " + player.getName() + ".", NamedTextColor.GREEN));
                startTeleport(player, other);
            } else {
                requests.put(player.getUniqueId(), other.getUniqueId());
                player.sendMessage(Component.text("Teleport request sent to " + other.getName() + ".", NamedTextColor.GREEN));
                other.sendMessage(Component.text(player.getName() + " wants to teleport to you. Use /tpaccept " + player.getName() + " to accept.", NamedTextColor.YELLOW));
            }
            return true;
        }

        if (command.getName().equalsIgnoreCase("tpaccept")) {
            if (!player.getUniqueId().equals(requests.get(other.getUniqueId()))) {
                player.sendMessage(Component.text("That player has not sent you a teleport request.", NamedTextColor.RED));
                return true;
            }
            requests.remove(other.getUniqueId());
            player.sendMessage(Component.text("Accepted " + other.getName() + "'s teleport request.", NamedTextColor.GREEN));
            startTeleport(other, player);
            return true;
        }
        return false;
    }

    private void startTeleport(Player requester, Player destination) {
        UUID requesterId = requester.getUniqueId();
        UUID destinationId = destination.getUniqueId();
        long requesterGeneration = generations.merge(requesterId, 1L, Long::sum);
        long destinationGeneration = generations.getOrDefault(destinationId, 0L);
        new BukkitRunnable() {
            private int seconds = 3;

            @Override
            public void run() {
                if (!requester.isOnline() || !destination.isOnline() || requester.isDead() || destination.isDead()
                        || generations.getOrDefault(requesterId, 0L) != requesterGeneration
                        || generations.getOrDefault(destinationId, 0L) != destinationGeneration) {
                    cancel();
                    return;
                }
                if (seconds == 0) {
                    requester.teleport(destination.getLocation());
                    cancel();
                    return;
                }
                requester.sendActionBar(Component.text("Teleporting in " + seconds, NamedTextColor.YELLOW));
                seconds--;
            }
        }.runTaskTimer(this, 0L, 20L);
    }

    @EventHandler
    public void onDeath(PlayerDeathEvent event) {
        clearPlayer(event.getEntity().getUniqueId());
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent event) {
        clearPlayer(event.getPlayer().getUniqueId());
    }

    private void clearPlayer(UUID playerId) {
        autoAccept.remove(playerId);
        requests.remove(playerId);
        requests.values().removeIf(playerId::equals);
        generations.merge(playerId, 1L, Long::sum);
    }
}