๐
1 file
13,504 chars
๐
pasted-code-1791018550788.txt
txt
961 lines
โถ
pasted-code-1791018550788.txt
txt
961 lines
Create a complete Minecraft Paper plugin from scratch.
# PROJECT INFORMATION
Plugin Name:
`RTP Plugin`
Project Folder:
`RTPPlugin`
Main Package:
`com.kodari.rtpplugin`
Main Class:
`RTPPlugin.java`
Minecraft:
`Paper 1.21.11`
Java:
`21`
Build Tool:
`Maven`
Final JAR:
`target/rtpplugin-1.0.0.jar`
Build the entire plugin from scratch.
Do not leave TODOs, placeholders, pseudocode, missing classes, or incomplete methods.
Do not use XSeries.
Use modern Paper/Bukkit APIs compatible with Paper 1.21.11.
---
# 1. COMMAND
The plugin must have only one main player command:
`/rtp`
Do NOT create:
* `/randomtp`
* `/wild`
* `/randomteleport`
* `/rtpworld`
Admin subcommands are allowed under `/rtp`:
`/rtp reload`
`/rtp unlock nether`
`/rtp unlock end`
`/rtp lock nether`
`/rtp lock end`
---
# 2. PERMISSIONS
Use:
`rtpplugin.use`
`rtpplugin.admin`
`rtpplugin.bypass.cooldown`
`rtpplugin.bypass.cost`
`rtpplugin.bypass.combat`
Defaults:
```text id="v4g0xw"
rtpplugin.use = true
rtpplugin.admin = op
rtpplugin.bypass.cooldown = op
rtpplugin.bypass.cost = op
rtpplugin.bypass.combat = op
```
---
# 3. PREMIUM RTP GUI
When a player uses:
`/rtp`
open a premium **45-slot chest GUI**.
The GUI must look clean, modern and professional.
---
# 4. EXACT GUI LAYOUT
The three dimension buttons MUST be arranged horizontally.
### LEFT
๐ฅ NETHER
### CENTER
๐ OVERWORLD
### RIGHT
๐ END
Use this layout:
```text id="9c9z8d"
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ ๐ฉ ๐ฉ ๐ฉ ๐ฉ โ
โ ๐ฉ ๐ฉ ๐ฅ ๐ฉ ๐ ๐ฉ ๐ ๐ฉ ๐ฉ โ
โ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ โ
โ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ โ
โ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
The exact positions should be balanced.
Do NOT put Nether directly against the left border.
Do NOT put End directly against the right border.
The three buttons must have equal visual spacing.
Overworld must be exactly in the center.
---
# 5. SERVER NAME BOX
At the TOP CENTER of the GUI create a premium decorative box.
Use:
`NETHER_STAR`
The name must come ONLY from `config.yml`.
Example:
```yaml id="v5d3u1"
gui:
server-name: "&b&lYOUR SERVER NAME"
```
If I change it to:
```yaml id="6f8m1e"
gui:
server-name: "&6&lMY SERVER"
```
the GUI must immediately use that name after `/rtp reload`.
There must be NO hard-coded server name such as:
`NYROX`
inside Java code.
The Server Name Box is decorative only.
Clicking it does nothing.
Players cannot take it.
---
# 6. SERVER NAME LORE
Also make the lore configurable:
```yaml id="t1v5e8"
gui:
server-name-lore:
- "&7Choose your destination"
- "&8โฆ Premium RTP"
```
---
# 7. GREEN GLASS BACKGROUND
Every unused GUI slot must contain:
`GREEN_STAINED_GLASS_PANE`
Display name:
`" "`
The entire GUI should have the green-glass background.
Only the Server Name Box and RTP buttons should be functional/display items.
Players must NOT be able to take any glass pane.
---
# 8. NETHER BUTTON
Position:
**LEFT**
Use:
`NETHERITE_SCRAP`
Display:
`&c&l๐ฅ NETHER`
Lore:
```text id="k5g9s1"
&7Teleport to a random location
&7inside the Nether.
&eClick to teleport
```
When locked:
```text id="k5g9s2"
&c&lLOCKED
&7Nether RTP is currently unavailable.
```
Clicking a locked Nether button must do nothing except optionally play a locked/error sound.
---
# 9. OVERWORLD BUTTON
Position:
**EXACT CENTER**
Use:
`GRASS_BLOCK`
Display:
`&a&l๐ OVERWORLD`
Lore:
```text id="8n6e0m"
&7Teleport to a random location
&7inside the Overworld.
&eClick to teleport
```
Overworld is unlocked by default.
---
# 10. END BUTTON
Position:
**RIGHT**
Use:
`ENDER_EYE`
Display:
`&5&l๐ END`
Lore:
```text id="3z4v8p"
&7Teleport to a random location
&7inside the End.
&eClick to teleport
```
When locked:
```text id="0q6m8j"
&c&lLOCKED
&7End RTP is currently unavailable.
```
---
# 11. GUI INVENTORY PROTECTION
The RTP GUI must be completely locked.
Players must NOT be able to:
* Take GUI items
* Move GUI items
* Shift-click
* Drag items
* Drop items
* Number-key swap
* Hotbar swap
* Offhand swap
* Double-click
* Put their own items into the GUI
* Move GUI items into their inventory
Handle all relevant inventory events.
The player's actual inventory must never be modified.
---
# 12. DEFAULT RTP WORLD STATUS
Default:
```text
Overworld = UNLOCKED
Nether = LOCKED
End = LOCKED
```
Admin commands:
`/rtp unlock nether`
`/rtp unlock end`
`/rtp lock nether`
`/rtp lock end`
Permission:
`rtpplugin.admin`
Save the unlock state so it survives server restarts.
---
# 13. COUNTDOWN
When a player selects an unlocked dimension:
1. Close GUI.
2. Save the player's original location.
3. Start a configurable countdown.
4. Show a large title/subtitle.
Default countdown:
`5 seconds`
Example:
```text
Title: &b&lRTP
Subtitle: &fTeleporting in &e5
```
Then:
`4`
`3`
`2`
`1`
Finally:
```text
Title: &a&lTELEPORTED!
Subtitle: &fWelcome!
```
Make title/subtitle configurable.
---
# 14. COUNTDOWN MOVEMENT CANCEL
If the player actually moves from their starting location during the countdown:
Cancel RTP.
Send:
`&c&lRTP CANCELLED`
`&7You moved during the countdown.`
Play a cancellation sound.
Small head rotation must NOT cancel RTP.
Only actual position movement should cancel it.
---
# 15. SAFE RANDOM LOCATION
Create a proper safe RTP location finder.
Never teleport into:
* Void
* Lava
* Water
* Fire
* Cactus
* Magma blocks
* Dangerous blocks
* Solid blocks that cause suffocation
Require:
* Solid ground
* Two blocks of headroom
* Safe feet position
* Safe body position
Avoid dangerous cliffs when reasonably possible.
Use configurable maximum attempts.
Default:
```yaml id="v9x2p1"
rtp:
min-distance: 500
max-distance: 5000
max-attempts: 30
```
Never create an infinite loop.
---
# 16. RTP DISTANCE
Generate a random location around the player's current location.
Minimum distance:
`500`
Maximum distance:
`5000`
Make these configurable.
For each dimension, use appropriate safe-location logic.
---
# 17. PERFORMANCE
The plugin must be optimized.
Do NOT perform massive world scans on the main thread.
Do NOT load thousands of chunks.
Use asynchronous processing where safe.
Perform final Bukkit/Paper world operations on the main thread when required.
Never create noticeable TPS problems.
Never use infinite loops.
---
# 18. COOLDOWN
Add configurable RTP cooldown.
Default:
`300 seconds`
After successful RTP, start cooldown.
Message:
`&cYou must wait &e%time% &cbefore using RTP again.`
Permission:
`rtpplugin.bypass.cooldown`
Players with this permission bypass cooldown.
---
# 19. ECONOMY
Add optional Vault economy support.
Config:
```yaml id="5m2d8a"
cost:
enabled: false
amount: 100
```
If enabled and player does not have enough money:
`&cYou need &e$%amount% &cto use RTP.`
Permission:
`rtpplugin.bypass.cost`
If economy is disabled, Vault should not be required.
---
# 20. COMBAT PROTECTION
Add configurable combat protection.
Config:
```yaml id="8p2s6h"
combat:
enabled: true
block-if-in-combat: true
```
If player is in combat:
`&cYou cannot use RTP while in combat.`
Permission:
`rtpplugin.bypass.combat`
Do not implement a fake combat system.
If another combat plugin is installed, make the combat integration configurable/extendable.
---
# 21. WORLD CONFIGURATION
Use environment detection:
* NORMAL
* NETHER
* THE_END
Also support explicit world names.
Config:
```yaml id="1j5v7r"
worlds:
overworld:
enabled: true
name: world
nether:
enabled: true
name: world_nether
end:
enabled: true
name: world_the_end
```
If a configured world does not exist, show a proper error.
Never crash the server.
---
# 22. PARTICLES
Use subtle premium effects.
During countdown:
* END_ROD
* PORTAL
* CLOUD
* ENCHANT
After teleport:
* PORTAL
* END_ROD
* CLOUD
Keep particle counts low and optimized.
---
# 23. SOUNDS
Use valid Paper 1.21.11 sounds.
Countdown:
`BLOCK_NOTE_BLOCK_PLING`
Teleport:
`ENTITY_ENDERMAN_TELEPORT`
Success:
`ENTITY_PLAYER_LEVELUP`
Cancel:
`BLOCK_NOTE_BLOCK_BASS`
Make sounds configurable.
---
# 24. CONFIG.YML
Create a complete configuration.
Example:
```yaml id="6y2c1p"
gui:
title: "&8โฆ &fRTP &8โฆ"
server-name: "&b&lYOUR SERVER NAME"
server-name-lore:
- "&7Choose your destination"
- "&8โฆ Premium RTP"
background:
material: GREEN_STAINED_GLASS_PANE
name: " "
nether:
name: "&c&l๐ฅ NETHER"
overworld:
name: "&a&l๐ OVERWORLD"
end:
name: "&5&l๐ END"
countdown:
seconds: 5
cancel-on-move: true
rtp:
min-distance: 500
max-distance: 5000
max-attempts: 30
cooldown:
enabled: true
seconds: 300
cost:
enabled: false
amount: 100
combat:
enabled: true
block-if-in-combat: true
worlds:
overworld:
enabled: true
name: world
nether:
enabled: true
name: world_nether
end:
enabled: true
name: world_the_end
effects:
particles: true
sounds: true
```
All important messages must also be configurable.
---
# 25. RELOAD
Support:
`/rtp reload`
Permission:
`rtpplugin.admin`
Reload:
* config
* GUI settings
* server name
* RTP settings
* messages
* cooldown settings
Do not require server restart.
---
# 26. DISCONNECT
If a player disconnects during countdown:
* Cancel their RTP
* Cancel their scheduled task
* Remove them from active RTP tracking
* Do not teleport them later
* Prevent memory leaks
---
# 27. DEATH
If player dies during countdown:
Cancel RTP.
Clean up their task.
---
# 28. WORLD CHANGE
If player changes world during countdown:
Cancel RTP.
Clean up their task.
---
# 29. ERROR HANDLING
Handle:
* Missing worlds
* Invalid config
* No safe location
* Player offline
* Player dead
* World unavailable
* Vault unavailable
* Teleport failure
Never crash the server.
If no safe location is found:
`&cCould not find a safe RTP location. Please try again.`
---
# 30. PROJECT STRUCTURE
Use this structure:
```text id="8j7m2k"
RTPPlugin/
โโโ pom.xml
โโโ src/
โโโ main/
โโโ java/
โ โโโ com/
โ โโโ kodari/
โ โโโ rtpplugin/
โ โโโ RTPPlugin.java
โ โ
โ โโโ command/
โ โ โโโ RTPCommand.java
โ โ
โ โโโ gui/
โ โ โโโ RTPMenu.java
โ โ โโโ RTPMenuListener.java
โ โ
โ โโโ rtp/
โ โ โโโ RTPManager.java
โ โ โโโ SafeLocationFinder.java
โ โ โโโ RTPCooldownManager.java
โ โ
โ โโโ listener/
โ โโโ RTPPlayerListener.java
โ
โโโ resources/
โโโ plugin.yml
โโโ config.yml
```
Additional classes may be added if needed.
---
# 31. MAVEN
Create a correct Maven `pom.xml`.
Use:
* Java 21
* Paper 1.21.11 API
* Vault API as optional/provided dependency
Do not use XSeries.
Use modern APIs.
---
# 32. PLUGIN.YML
The plugin.yml must use:
```yaml id="8y7r1m"
name: RTP Plugin
version: 1.0.0
main: com.kodari.rtpplugin.RTPPlugin
api-version: '1.21'
```
Register:
`/rtp`
Permissions:
```text id="2m6q9k"
rtpplugin.use
rtpplugin.admin
rtpplugin.bypass.cooldown
rtpplugin.bypass.cost
rtpplugin.bypass.combat
```
Vault should be a soft dependency only if necessary.
---
# 33. FINAL GUI RULES
These are NON-NEGOTIABLE:
### TOP CENTER
๐ Server Name Box
### LEFT
๐ฅ NETHER
### CENTER
๐ OVERWORLD
### RIGHT
๐ END
### BACKGROUND
Every unused slot:
`GREEN_STAINED_GLASS_PANE`
### SERVER NAME
Only from:
`config.yml`
### GUI PROTECTION
No item can be taken or moved.
### DEFAULT STATUS
Overworld unlocked.
Nether locked.
End locked.
---
# 34. FINAL BUILD
Before finishing:
1. Check every Java class.
2. Check every import.
3. Check Paper 1.21.11 compatibility.
4. Check Java 21.
5. Check Maven.
6. Check plugin.yml.
7. Check config.yml.
8. Check command registration.
9. Check GUI positions.
10. Check GUI item protection.
11. Check countdown.
12. Check movement cancellation.
13. Check safe-location system.
14. Check cooldown.
15. Check permissions.
16. Check unlock system.
17. Check reload.
18. Check error handling.
19. Build the project.
Final output MUST be:
`target/rtpplugin-1.0.0.jar`
Build the complete **RTP Plugin** from scratch now.
KodariOct 3 at 9:18 am 1
PremiumRTPPlugin
A premium Minecraft Paper plugin providing a GUI-based random teleportation system. Players use /rtp to open a 45-slot chest GUI with dimension selection buttons for Overworld, Nether, and End. Features configurable countdown with movement cancellation, safe location finder avoiding dangerous blocks, cooldown system, optional Vault economy cost, combat protection, world unlock/lock admin commands, and full config reload support. Includes complete GUI inventory protection, particle effects, sounds, and persistent world status storage.
Create the Maven/Paper 1.21.11 project metadata and plugin configuration.
Implement the RTP command, protected 45-slot GUI, persistent dimension locks, cooldown, and optional integrations.
Add cancellable countdowns and bounded asynchronous safe-location searches with the required cleanup handlers.
Created the Maven project and complete RTP plugin implementation, including the protected GUI, persistent dimension locks, countdown and cancellation handling, safe-location search, cooldown, optional Vault economy, and configurable messages and effects.
The Maven artifact is configured as target/rtpplugin-1.0.0.jar. I did not run a Maven build here, so that JAR has not been generated.
Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
12 1,005
src/main/java/com/kodari/rtpplugin/RTPPlugin.java
package com.kodari.rtpplugin;
import com.kodari.rtpplugin.command.RTPCommand;
import com.kodari.rtpplugin.gui.RTPMenu;
import com.kodari.rtpplugin.gui.RTPMenuListener;
import com.kodari.rtpplugin.listener.RTPPlayerListener;
import com.kodari.rtpplugin.rtp.RTPManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public final class RTPPlugin extends JavaPlugin {
private RTPManager rtpManager;
@Override
public void onEnable() {
saveDefaultConfig();
rtpManager = new RTPManager(this);
Bukkit.getPluginManager().registerEvents(new RTPMenuListener(this), this);
Bukkit.getPluginManager().registerEvents(new RTPPlayerListener(this), this);
RTPCommand command = new RTPCommand(this);
getCommand("rtp").setExecutor(command);
getCommand("rtp").setTabCompleter(command);
}
@Override
public void onDisable() {
if (rtpManager != null) {
rtpManager.shutdown();
}
}
public RTPManager getRtpManager() {
return rtpManager;
}
public void openMenu(Player player) {
player.openInventory(new RTPMenu(this).getInventory());
}
public void sendMessage(CommandSender sender, String key, String... replacements) {
String message = getConfig().getString("messages." + key, "");
String prefix = getConfig().getString("messages.prefix", "");
for (int i = 0; i + 1 < replacements.length; i += 2) {
message = message.replace("%" + replacements[i] + "%", replacements[i + 1]);
}
sender.sendMessage(color(prefix + message));
}
public static String color(String text) {
return ChatColor.translateAlternateColorCodes('&', text == null ? "" : text);
}
}