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.
Planning class structure:
RandomTeleport— main plugin class, registers listeners/commandsConfigManager— wraps config.yml valuesTeleportManager— finds safe random location and executes teleportPlayerListener— handlesPlayerJoinEventandPlayerDeathEventRTPCommand—/rtpadmin/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 arrivalHomeChecker— detects Essentials or CMI via reflection and checks if the player has a home set; defaults tofalse(no home) if neither plugin is presentPlayerListener— RTP on first join; on death, marks the player for RTP on their next respawn (only if no home detected)RTPCommand—/rtpfor self,/rtp <player>for adminsRandomTeleport— main class wiring everything together
If the player has a bed placed and has a respawn point they have a home
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.
Can I have the /rtp command be on a customizable cooldown in the config file
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— addedrtp-cooldown: 300(seconds) and acooldownmessage with a%time%placeholderConfigManager— addedgetRtpCooldown()getterRTPCommand— added aMap<UUID, Long>to track last-use timestamps; on each/rtpself-use it checks elapsed time against the configured cooldown and blocks with the cooldown message if not enough time has passed. Admins withrandomteleport.cooldown.bypassskip the check entirely. TheformatTime()helper formats the remaining seconds asXh Xm Xs,Xm Xs, orXsdepending on length.
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
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 toTeleportManagerthat runs synchronously (needed sincePlayerRespawnEventmust set the location on the event object directly)In
PlayerListener.onRespawn, call this sync method and useevent.setRespawnLocation()so the player spawns at the random coords instantly — no delay, no spectate windowKeep
teleportRandom(async) for first-join and the/rtpcommandI’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— addedfindSafeLocationForRespawn(Player), a public synchronous wrapper aroundfindSafeLocation. It must be sync becausePlayerRespawnEventis a synchronous event and we need the result immediately to set it on the event object.PlayerListener.onRespawn— instead of scheduling a delayedplayer.teleport()(which left a window for the spectate button), it now callsfindSafeLocationForRespawnand passes the result toevent.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— addedgetConfigManager()getter soPlayerListenercan access messages without a separate constructor parameter.
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
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.bypasspermission check stays but OPs no longer get it implicitly (controlled purely byplugin.ymldefault: 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 callshasOpenSky()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.ymlgetsrtp-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 thewarmup-cancelledmessage. 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.bypassis now explicitly declared inplugin.ymlwithdefault: false, meaning OPs get no implicit bypass. Only players manually granted the permission via a permissions plugin will bypass the cooldown.
can we not spam the chat when the player is warming up, can we just send one message to the player about the warmup
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.
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 ?
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 ?
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.
I can't even enter spectate mode
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.");
}
}