toddpocalypse

Develop a plugin that teleports players to random coordinates within customizable bounds upon their first join and when they die, provided they do not have a home set. Implement checks to ensure teleportation occurs only within the world border, with an Enderman teleport sound effect upon each teleport. Include a configurable safe distance check to ensure no other players are nearby and verify that the teleport location is safe for spawning, preventing immediate danger upon arrival.

Kodari AI
KodariMay 10 at 7:47 pm 6,270 (v2)
RandomTeleport
Teleports players to random coordinates within configurable bounds on first join and on death (if no home is set). Ensures teleport locations are within the world border, safe for spawning, and no other players are within a configurable radius. Plays an Enderman teleport sound on each teleport. Fully configurable bounds, safe-distance radius, max attempts, and messages via config.yml.

Planning class structure:

  • RandomTeleport — main plugin class, registers listeners/commands

  • ConfigManager — wraps config.yml values

  • TeleportManager — finds safe random location and executes teleport

  • PlayerListener — handles PlayerJoinEvent and PlayerDeathEvent

  • RTPCommand — /rtp admin/debug command

All files are created:

  • ConfigManager — reads all config values (bounds, max attempts, safe distance, messages)

  • TeleportManager — async location search respecting world border, player proximity, and spawn safety; plays Enderman teleport sound on arrival

  • HomeChecker — detects Essentials or CMI via reflection and checks if the player has a home set; defaults to false (no home) if neither plugin is present

  • PlayerListener — RTP on first join; on death, marks the player for RTP on their next respawn (only if no home detected)

  • RTPCommand — /rtp for self, /rtp <player> for admins

  • RandomTeleport — main class wiring everything together

toddpocalypse

If the player has a bed placed and has a respawn point they have a home

Kodari AI
KodariMay 10 at 7:53 pm 1,604 (v2)

The fix is straightforward: add a bed/respawn-point check directly in HomeChecker.hasHome() using player.getBedSpawnLocation(), which returns non-null when the player has a valid set respawn point (bed or respawn anchor). This check runs first, before any plugin lookups.

hasHome() now checks player.getBedSpawnLocation() first — if the player has a valid bed or respawn anchor set, it returns true immediately and skips the Essentials/CMI lookups entirely. The unused Plugin import is also cleaned up automatically since it was never referenced.

toddpocalypse

Can I have the /rtp command be on a customizable cooldown in the config file

Kodari AI
KodariMay 10 at 7:55 pm 4,337 (v2)

Now add the getter to ConfigManager and the cooldown logic to RTPCommand:

Now add the formatTime helper at the bottom of RTPCommand:

Here’s what changed:

  • config.yml — added rtp-cooldown: 300 (seconds) and a cooldown message with a %time% placeholder

  • ConfigManager — added getRtpCooldown() getter

  • RTPCommand — added a Map<UUID, Long> to track last-use timestamps; on each /rtp self-use it checks elapsed time against the configured cooldown and blocks with the cooldown message if not enough time has passed. Admins with randomteleport.cooldown.bypass skip the check entirely. The formatTime() helper formats the remaining seconds as Xh Xm Xs, Xm Xs, or Xs depending on length.

toddpocalypse

if the player clicks spectate world before they are banned in my Hardcore smp they avoid the teleport completely, can we have the teleport happen as soon as the player spawns so they don't even see it happen

Kodari AI
KodariMay 10 at 8:01 pm 12,653 (v2)

The issue is that the teleport is triggered on PlayerRespawnEvent with a 1-tick delay — enough time for the player to click “Spectate World” and avoid it. The fix is to move the teleport directly into PlayerRespawnEvent by setting the respawn location on the event itself, so the player spawns at the random location with no gap.

The plan:

  • Add a findSafeLocationSync(World, Player) method to TeleportManager that runs synchronously (needed since PlayerRespawnEvent must set the location on the event object directly)

  • In PlayerListener.onRespawn, call this sync method and use event.setRespawnLocation() so the player spawns at the random coords instantly — no delay, no spectate window

  • Keep teleportRandom (async) for first-join and the /rtp commandI’ll use the update tag to rewrite both files cleanly:

Now expose getConfigManager() on the main class so PlayerListener can reach it:

Good — RandomTeleport doesn’t need changes since PlayerListener already receives teleportManager directly. Now let me write the two updated files:

Now expose getConfigManager() on the main class:

Now write the actual updated files:

Here’s what changed:

  • TeleportManager — added findSafeLocationForRespawn(Player), a public synchronous wrapper around findSafeLocation. It must be sync because PlayerRespawnEvent is a synchronous event and we need the result immediately to set it on the event object.

  • PlayerListener.onRespawn — instead of scheduling a delayed player.teleport() (which left a window for the spectate button), it now calls findSafeLocationForRespawn and passes the result to event.setRespawnLocation(). The player spawns directly at the random coords — there is no moment where they exist at the death location and could click Spectate. The sound plays 1 tick later once they’re fully loaded in.

  • RandomTeleport — added getConfigManager() getter so PlayerListener can access messages without a separate constructor parameter.

toddpocalypse

can we add a check to make sure we are not spawned in a cave and can we add a teleport commencing cooldown which is customizable for /rtp in which the player has to stand still or it cancels the rtp and can OP's not be defaulted to bypass the rtp cooldown

Kodari AI
KodariMay 10 at 8:03 pm 13,494 (v2)

Three things to implement:

  • Cave check — after finding a safe Y, walk upward and confirm there is a clear sky column (no solid blocks above up to world max height)

  • Warmup countdown — configurable seconds in config; a repeating task tracks the player’s position each second, cancels if they move, fires the teleport when it reaches zero; a per-second message shows the countdown

  • Remove OP bypass — the randomteleport.cooldown.bypass permission check stays but OPs no longer get it implicitly (controlled purely by plugin.yml default: false)

Now I have everything I need. Patching all four files in parallel:

Now rewrite TeleportManager to add the cave check, and rewrite RTPCommand to add the warmup logic:

Now rewrite RTPCommand with the warmup logic:

Now update RandomTeleport to pass plugin into RTPCommand:

Now write the actual RTPCommand with warmup:

Here’s a summary of every change:

  • Cave check — TeleportManager.getSafeY() now calls hasOpenSky() which walks every block from the candidate Y up to world max height; if any solid block is found above, the location is rejected and the search continues. Players will always land in the open air.

  • Warmup countdown — config.yml gets rtp-warmup: 5 (seconds). When a player runs /rtp, a repeating 1-second task starts. Each tick it checks if the player has moved more than 0.1 blocks — if so, it cancels and sends the warmup-cancelled message. If they stand still for the full duration, the teleport fires and the cooldown is stamped. A new countdown message is sent each second showing the remaining time.

  • OP bypass removed — randomteleport.cooldown.bypass is now explicitly declared in plugin.yml with default: false, meaning OPs get no implicit bypass. Only players manually granted the permission via a permissions plugin will bypass the cooldown.

toddpocalypse

can we not spam the chat when the player is warming up, can we just send one message to the player about the warmup

Kodari AI
KodariMay 10 at 8:10 pm 3,149 (v2)

Let me read the current RTPCommand to see the warmup messaging.

The fix is simple — remove the per-second player.sendMessage(...) inside the repeating task. The initial message before the task starts is enough.

The per-second repeated warmup message is removed. Now the player only sees one message when the warmup begins (e.g. “Teleporting in 5 seconds, don’t move!”), and then either the cancelled or teleported message at the end — no spam.

toddpocalypse

When I try to enter spectate mode now it no longer works at all. can I enter this mode while alive as a staff member ?

toddpocalypse

When I try to enter spectate mode now it no longer works at all. can I enter this mode while alive as a staff member ?

Kodari AI
KodariMay 11 at 12:43 am 9,989 (v2)

Let me read the relevant files to understand what’s happening.

The issue is in onDeath — it uses EventPriority.MONITOR with ignoreCancelled = true, but more importantly it fires for any player death, including staff in spectator mode. However the real problem is that onRespawn intercepts the respawn event for anyone in pendingRespawnRTP, which is fine — but the onDeath listener adds all players who die without a home, including staff.

The fix: check if the player has the bypass/staff permission on death, and if so, skip adding them to pendingRespawnRTP.

Players with randomteleport.admin are now skipped on death — they won’t be queued for RTP on respawn and can freely use spectator mode. Regular players without that permission are unaffected.

toddpocalypse

I can't even enter spectate mode

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
9 599
src/main/java/com/example/randomteleport/RandomTeleport.java
package com.example.randomteleport;

import org.bukkit.plugin.java.JavaPlugin;

public class RandomTeleport extends JavaPlugin {

    private ConfigManager configManager;
    private TeleportManager teleportManager;

    public ConfigManager getConfigManager() {
        return configManager;
    }

    @Override
    public void onEnable() {
        configManager = new ConfigManager(this);
        teleportManager = new TeleportManager(this, configManager);
        HomeChecker homeChecker = new HomeChecker();

        getServer().getPluginManager().registerEvents(
                new PlayerListener(this, teleportManager, homeChecker), this);

        getCommand("rtp").setExecutor(new RTPCommand(this, teleportManager, configManager));

        getLogger().info("RandomTeleport enabled.");
    }

    @Override
    public void onDisable() {
        getLogger().info("RandomTeleport disabled.");
    }
}