PRB Vlog

Please create a rtp plugin for me that supports 26.3, and it should be optimized as much as possible, And the messages should be showed in the action bar and there should be a command to toggle messages and also add a countdown and a cooldown and give me the configuration option on the config file and I want all possible config options please, and please use symbols with text for the messages shown to users

Kodari AI
KodariNov 4 at 6:38 pm 2
RandomTeleportPro
RandomTeleportPro is a high-performance Minecraft plugin for version 26.3 that teleports players to random locations. It features a configurable countdown before teleportation, a cooldown between uses, and an action bar message system with toggleable notifications. The plugin includes extensive configuration options for message text with symbols, teleport ranges, world restrictions, and safety checks. Commands include /rtp to teleport and /rtp toggle to enable or disable action bar messages. Optimized for minimal server impact with asynchronous chunk loading and efficient random location generation.
  • Add asynchronous chunk loading with bounded safe-location searches.

  • Configure countdowns, cooldowns, movement cancellation, world settings, and action-bar messages.

  • Add /rtp toggle and /rtp reload, with message preferences saved across restarts.

Created the RTP plugin with asynchronous chunk searches, configurable countdowns and cooldowns, safe-location checks, and action-bar messages.

  • /rtp — teleport randomly

  • /rtp toggle — toggle RTP messages

  • /rtp reload — reload the configuration

Settings and messages are in config.yml. The plugin targets Paper-compatible servers; compatibility with 26.3 has not been verified.

PRB Vlog

Please add countdown message to the action bar and the cords should be send to chat

Kodari AI
KodariNov 4 at 6:45 pm 1
  • Keep the countdown in the action bar.

  • Send the successful teleport coordinates to chat, respecting the message toggle.

The countdown remains in the action bar. After a successful teleport, the coordinates are now sent to chat.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 371
src/main/java/com/kodari/rtp/RtpPlugin.java
package com.kodari.rtp;

import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public final class RtpPlugin extends JavaPlugin implements CommandExecutor, Listener {
    private final Map<UUID, Request> requests = new HashMap<>();
    private final Map<UUID, Long> cooldowns = new HashMap<>();
    private final Set<UUID> muted = new HashSet<>();
    private File preferencesFile;
    private YamlConfiguration preferences;

    private static final class Request {
        private final UUID playerId;
        private final World world;
        private final Location origin;
        private BukkitTask timer;
        private BukkitTask timeout;
        private int attempts;

        private Request(Player player) {
            playerId = player.getUniqueId();
            world = player.getWorld();
            origin = player.getLocation();
        }
    }

    @Override
    public void onEnable() {
        saveDefaultConfig();
        preferencesFile = new File(getDataFolder(), "preferences.yml");
        preferences = YamlConfiguration.loadConfiguration(preferencesFile);
        for (String id : preferences.getStringList("muted")) {
            try {
                muted.add(UUID.fromString(id));
            } catch (IllegalArgumentException ignored) {
                getLogger().warning("Ignoring invalid UUID in preferences.yml: " + id);
            }
        }
        getCommand("rtp").setExecutor(this);
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onDisable() {
        for (Request request : requests.values()) {
            stopTasks(request);
        }
        requests.clear();
        savePreferences();
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            if (!sender.hasPermission("kodarirtp.reload")) {
                send(sender, "no-permission", true);
            } else {
                reloadConfig();
                send(sender, "reloaded", true);
            }
            return true;
        }
        if (!(sender instanceof Player)) {
            send(sender, "player-only", true);
            return true;
        }
        Player player = (Player) sender;
        if (args.length == 1 && args[0].equalsIgnoreCase("toggle")) {
            if (!player.hasPermission("kodarirtp.toggle")) {
                send(player, "no-permission", true);
            } else {
                boolean enabled = muted.remove(player.getUniqueId());
                if (!enabled) muted.add(player.getUniqueId());
                savePreferences();
                send(player, enabled ? "toggled-on" : "toggled-off", true);
            }
            return true;
        }
        if (args.length != 0) {
            send(player, "usage", true);
            return true;
        }
        if (!player.hasPermission("kodarirtp.use")) {
            send(player, "no-permission", true);
            return true;
        }
        if (getConfig().getStringList("settings.disabled-worlds").stream().anyMatch(player.getWorld().getName()::equalsIgnoreCase)) {
            send(player, "disabled-world", false);
            return true;
        }
        UUID id = player.getUniqueId();
        if (requests.containsKey(id)) {
            send(player, "already-pending", false);
            return true;
        }
        long remaining = cooldowns.getOrDefault(id, 0L) - System.currentTimeMillis();
        if (remaining > 0 && !player.hasPermission("kodarirtp.bypass.cooldown")) {
            send(player, "cooldown", false, "{seconds}", Long.toString((remaining + 999) / 1000));
            return true;
        }
        Request request = new Request(player);
        requests.put(id, request);
        int countdown = player.hasPermission("kodarirtp.bypass.countdown") ? 0 : Math.max(0, getConfig().getInt("settings.countdown", 5));
        if (countdown == 0) {
            beginSearch(request);
        } else {
            final int[] seconds = {countdown};
            request.timer = Bukkit.getScheduler().runTaskTimer(this, () -> {
                if (seconds[0] <= 0) {
                    request.timer.cancel();
                    request.timer = null;
                    beginSearch(request);
                } else {
                    send(player, "countdown", false, "{seconds}", Integer.toString(seconds[0]--));
                }
            }, 0L, 20L);
        }
        return true;
    }

    private void beginSearch(Request request) {
        Player player = Bukkit.getPlayer(request.playerId);
        if (player == null || requests.get(request.playerId) != request) return;
        send(player, "searching", false);
        long timeout = Math.max(1, getConfig().getInt("settings.search-timeout", 30));
        request.timeout = Bukkit.getScheduler().runTaskLater(this, () -> finish(request, "failed"), timeout * 20L);
        search(request);
    }

    private void search(Request request) {
        if (requests.get(request.playerId) != request) return;
        if (++request.attempts > Math.max(1, getConfig().getInt("settings.max-attempts", 20))) {
            finish(request, "failed");
            return;
        }
        String prefix = "settings.worlds." + request.world.getName() + ".";
        int centerX = getConfig().getInt(prefix + "center-x", getConfig().getInt("settings.center-x", 0));
        int centerZ = getConfig().getInt(prefix + "center-z", getConfig().getInt("settings.center-z", 0));
        int max = Math.max(1, Math.min(29999984, getConfig().getInt(prefix + "max-radius", getConfig().getInt("settings.max-radius", 5000))));
        int min = Math.max(0, Math.min(max, getConfig().getInt(prefix + "min-radius", getConfig().getInt("settings.min-radius", 100))));
        ThreadLocalRandom random = ThreadLocalRandom.current();
        double radius = Math.sqrt(random.nextDouble() * ((double) max * max - (double) min * min) + (double) min * min);
        double angle = random.nextDouble() * Math.PI * 2;
        long rawX = (long) centerX + Math.round(radius * Math.cos(angle));
        long rawZ = (long) centerZ + Math.round(radius * Math.sin(angle));
        if (Math.abs(rawX) > 29999984 || Math.abs(rawZ) > 29999984) {
            Bukkit.getScheduler().runTask(this, () -> search(request));
            return;
        }
        int x = (int) rawX;
        int z = (int) rawZ;
        WorldBorder border = request.world.getWorldBorder();
        double half = border.getSize() / 2.0;
        Location center = border.getCenter();
        if (Math.abs(x + 0.5 - center.getX()) >= half - 1 || Math.abs(z + 0.5 - center.getZ()) >= half - 1) {
            Bukkit.getScheduler().runTask(this, () -> search(request));
            return;
        }
        request.world.getChunkAtAsync(x >> 4, z >> 4, getConfig().getBoolean("settings.generate-chunks", true)).whenComplete((chunk, error) -> {
            if (!isEnabled()) return;
            Bukkit.getScheduler().runTask(this, () -> {
                if (requests.get(request.playerId) != request) return;
                if (error != null || chunk == null) {
                    search(request);
                    return;
                }
                Location destination = findSafeLocation(request.world, x, z);
                Player player = Bukkit.getPlayer(request.playerId);
                if (destination == null) {
                    search(request);
                } else if (player == null) {
                    finish(request, null);