trebris

make a plugin 26.3 java that adds the command tpa that allows you to ask someone to tpa to him/her add /tphere which works the same like the tpa command but you ask someone to teleport to you for example /tphere notch and he accepts by /tpaccept and he teleports to you add a command tpa autotp <name_of_the_person_you_want_auto_tp> for example if you do tpa autotp notch he will be able to teleport to me without me accepting the teleport request add /tpadeny that denys the teleport request. both the tpaaccept and tpadeny work with tpa here and tpa commands. make it visible on the chat that someone requested you a teleport request and make it able so if you click at the part when it says accept tpa then it automatically accepts without typing the command also add the tpa deny button.add an option to untpauto someone.add an anti logout when you get hit you get 20 seconds of anty logout and when you leave the server while you are in combat you get automatically killed. on the action bar above the hotbar make the cooldown visible like it counts down. make it to when you are in combat you cannot type any commands. make it when you die the cooldown resets. make it so when a player is in combat you cannot teleport to them by tpa or tpa autotp.add a tpacancel command that cancels pending request from you (for example if you tpa to a wrong person).make it so mobs and non player entities do not enable the anti logout cooldown. make it so when you have multiple teleport requests and you accept one the other one doesnt cancel

Kodari AI
KodariOct 7 at 4:07 pm 1
TeleportCombatSystem
A comprehensive Minecraft plugin adding teleport request commands (/tpa, /tphere, /tpaccept, /tpadeny, /tpacancel) with clickable chat messages for accept/deny actions. Includes auto-teleport functionality (/tpa autotp) with removal option, anti-combat-logout system triggering 20-second cooldown on player hits, visible action bar countdown, command blocking during combat, death cooldown reset, combat teleport prevention, and multi-request handling where accepting one doesn't cancel others. Mobs and non-player entities don't trigger combat mode.
  1. Create the Paper plugin and register /tpa, /tphere, accept/deny, cancel, and auto-TP commands.

  2. Add clickable request buttons while preserving unrelated pending requests.

  3. Add 20-second player-combat tagging, action-bar countdown, command blocking, and combat logout death.

Created the Paper plugin with /tpa, /tphere, clickable accept/deny buttons, /tpaccept, /tpadeny, /tpacancel, /tpa autotp, and /untpauto. Requests to different players are tracked independently, and accepting one leaves the others pending.

Added 20-second combat tagging for player-vs-player damage, an action-bar countdown, command blocking during combat, cooldown reset on death, and death on combat logout. Auto-TP grants and pending requests are currently kept in memory and reset when the plugin restarts.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 478
src/main/java/com/kodari/tpa/TpaPlugin.java
package com.kodari.tpa;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public final class TpaPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private static final long COMBAT_DURATION_MILLIS = 20_000L;

    private final Map<UUID, LinkedHashMap<UUID, TeleportRequest>> requestsByRecipient = new HashMap<>();
    private final Map<UUID, Set<UUID>> autoTeleportPlayers = new HashMap<>();
    private final Map<UUID, Long> combatUntil = new HashMap<>();
    private BukkitTask actionBarTask;

    @Override
    public void onEnable() {
        for (String command : new String[]{"tpa", "tphere", "tpaccept", "tpadeny", "tpacancel", "untpauto"}) {
            getCommand(command).setExecutor(this);
        }
        getServer().getPluginManager().registerEvents(this, this);
        actionBarTask = Bukkit.getScheduler().runTaskTimer(this, this::updateCombatActionBars, 0L, 20L);
    }

    @Override
    public void onDisable() {
        if (actionBarTask != null) {
            actionBarTask.cancel();
        }
    }

    @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;
        }

        switch (command.getName().toLowerCase(Locale.ROOT)) {
            case "tpa" -> handleTpa(player, args);
            case "tphere" -> handleTpHere(player, args);
            case "tpaccept" -> handleAccept(player, args);
            case "tpadeny" -> handleDeny(player, args);
            case "tpacancel" -> handleCancel(player, args);
            case "untpauto" -> handleUntpAuto(player, args);
            default -> { }
        }
        return true;
    }

    private void handleTpa(Player requester, String[] args) {
        if (args.length == 2 && args[0].equalsIgnoreCase("autotp")) {
            grantAutoTeleport(requester, args[1]);
            return;
        }
        if (args.length == 2 && args[0].equalsIgnoreCase("untpauto")) {
            revokeAutoTeleport(requester, args[1]);
            return;
        }
        if (args.length != 1) {
            requester.sendMessage(Component.text("Usage: /tpa <player> or /tpa autotp <player>", NamedTextColor.RED));
            return;
        }

        Player target = findOnlinePlayer(args[0]);
        if (target == null) {
            requester.sendMessage(Component.text("That player is not online.", NamedTextColor.RED));
            return;
        }
        if (target.equals(requester)) {
            requester.sendMessage(Component.text("You cannot teleport to yourself.", NamedTextColor.RED));
            return;
        }
        if (isInCombat(target)) {
            requester.sendMessage(Component.text("You cannot teleport to a player who is in combat.", NamedTextColor.RED));
            return;
        }

        if (autoTeleportPlayers.getOrDefault(target.getUniqueId(), Set.of()).contains(requester.getUniqueId())) {
            requester.teleport(target.getLocation());
            requester.sendMessage(Component.text("Teleported to " + target.getName() + ".", NamedTextColor.GREEN));
            target.sendMessage(Component.text(requester.getName() + " teleported to you using auto-TP.", NamedTextColor.YELLOW));
            return;
        }

        createRequest(requester, target, RequestType.TPA);
    }

    private void handleTpHere(Player requester, String[] args) {
        if (args.length != 1) {
            requester.sendMessage(Component.text("Usage: /tphere <player>", NamedTextColor.RED));
            return;
        }
        Player target = findOnlinePlayer(args[0]);
        if (target == null) {
            requester.sendMessage(Component.text("That player is not online.", NamedTextColor.RED));
            return;
        }
        if (target.equals(requester)) {
            requester.sendMessage(Component.text("You cannot request yourself.", NamedTextColor.RED));
            return;
        }
        if (isInCombat(requester)) {
            requester.sendMessage(Component.text("You cannot be teleported to while you are in combat.", NamedTextColor.RED));
            return;
        }
        createRequest(requester, target, RequestType.HERE);
    }

    private void createRequest(Player requester, Player recipient, RequestType type) {
        LinkedHashMap<UUID, TeleportRequest> incoming = requestsByRecipient.computeIfAbsent(
                recipient.getUniqueId(), ignored -> new LinkedHashMap<>());
        incoming.remove(requester.getUniqueId());
        TeleportRequest request = new TeleportRequest(requester.getUniqueId(), requester.getName(),
                recipient.getUniqueId(), type);
        incoming.put(requester.getUniqueId(), request);

        String description = type == RequestType.TPA
                ? requester.getName() + " wants to teleport to you. "
                : requester.getName() + " wants you to teleport to them. ";
        Component message = Component.text(description, NamedTextColor.YELLOW)
                .append(Component.text("[Accept]", NamedTextColor.GREEN)
                        .clickEvent(ClickEvent.runCommand("/tpaccept " + requester.getName())))
                .append(Component.text(" "))
                .append(Component.text("[Deny]", NamedTextColor.RED)
                        .clickEvent(ClickEvent.runCommand("/tpadeny " + requester.getName())));
        recipient.sendMessage(message);
        requester.sendMessage(Component.text("Teleport request sent to " + recipient.getName() + ".", NamedTextColor.GREEN));
    }

    private void handleAccept(Player recipient, String[] args) {
        if (args.length > 1) {
            recipient.sendMessage(Component.text("Usage: /tpaccept [player]", NamedTextColor.RED));
            return;
        }
        TeleportRequest request = findIncomingRequest(recipient, args.length == 1 ? args[0] : null);
        if (request == null) {
            recipient.sendMessage(Component.text("You have no matching teleport request.", NamedTextColor.RED));
            return;
        }

        Player requester = Bukkit.getPlayer(request.requesterId);
        if (requester == null) {
            removeRequest(request);
            recipient.sendMessage(Component.text("That requester is no longer online.", NamedTextColor.RED));
            return;
        }
        Player destination = request.type == RequestType.TPA ? recipient : requester;
        Player traveler = request.type == RequestType.TPA ? requester : recipient;
        if (isInCombat(destination)) {
            recipient.sendMessage(Component.text("You cannot teleport to a player who is in combat.", NamedTextColor.RED));
            return;
        }

        if (!traveler.teleport(destination.getLocation())) {
            recipient.sendMessage(Component.text("Teleportation failed; the request is still pending.", NamedTextColor.RED));
            return;
        }
        removeRequest(request);
        recipient.sendMessage(Component.text("Teleport request accepted.", NamedTextColor.GREEN));
        requester.sendMessage(Component.text("Your teleport request was accepted.", NamedTextColor.GREEN));
    }

    private void handleDeny(Player recipient, String[] args) {
        if (args.length > 1) {
            recipient.sendMessage(Component.text("Usage: /tpadeny [player]", NamedTextColor.RED));
            return;
        }
        TeleportRequest request = findIncomingRequest(recipient, args.length == 1 ? args[0] : null);
        if (request == null) {
            recipient.sendMessage(Component.text("You have no matching teleport request.", NamedTextColor.RED));
            return;
        }
        removeRequest(request);
        recipient.sendMessage(Component.text("Teleport request denied.", NamedTextColor.YELLOW));
        Player requester = Bukkit.getPlayer(request.requesterId);