-
Notifications
You must be signed in to change notification settings - Fork 89
API
The BetterRTP API is a fairly powerful tool when it comes to changing and listening to RTP events.
⚠️ Remember to addBetterRTP
to yourplugin.yml
-> softdepend.
BetterRTP can be installed using the online repository. logs.ronanplugins.com Use the drop down boxes below for the configuration you need.
Maven Setup
...
<repositories>
<repository>
<id>ronanplugins-releases</id>
<name>Ronan Plugins</name>
<url>https://repo.ronanplugins.com/releases</url>
</repository>
<repositories>
...
<dependencies>
<dependency>
<groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId>
<version>(current version)</version>
<scope>provided</scope>
</dependency>
<dependencies>
...
Gradle
...
repositories {
maven {url "https://repo.ronanplugins.com/releases"}
}
...
dependencies {
implementation "com.ronanplugins:BetterRTP:3.6.2"
}
...
Manual Setup
Installing via Maven using Maven Helper in IntelliJ using a New Goal:
install:install-file -Dfile=<path-to-BetterRTP-jar> -DgroupId=me.SuperRonanCraft -DartifactId=BetterRTP -Dversion=3.2.3 -Dpackaging=jar
Events are implemented right into the Bukkit API. Just use a Listener class and @EventHandler
to listen to these events.
Event | Cancellable | Description |
---|---|---|
RTP_CancelledEvent | No(lol) | Called when an rtp is cancelled due to a player moving while under a delay |
RTP_CommandEvent | Yes | Called every time a player executes /rtp ...
|
RTP_CommandEvent_After | No | Called after a successfully executed command |
RTP_FindLocationEvent | Yes | Called every time a new location find request is called |
RTP_SettingUpEvent | Yes | Called when an rtp is being setup to find a location |
RTP_TeleportEvent | No | Called right when a safe location is found and about to teleport a player |
RTP_TeleportPostEvent | No | Called after a random teleport |
RTP_TeleportPreEvent | Yes | Called before a random teleport |
RTP_FailedEvent | No | Called when max teleport attempts reached |
With BetterRTP, you are able to extend the command library by registering your own sub command.
Lets for example try to add link
into the list of commands, creating /rtp link
.
This can be used by implementing RTPCommand
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
public class LinkCommand implements RTPCommand {
public String getName() {
return "link";
}
@Override
public void execute(CommandSender sendi, String label, String[] args) {
sendi.sendMessage("Link Command!");
}
}
If you would like add a help message when someone executes /rtp help
, have the class also implement RTPCommandHelpable
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
public class LinkCommand implements RTPCommand, RTPCommandHelpable {
public String getName() {
return "link";
}
@Override
public String getHelp() {
return " - &6/%command% link &8| &7Help with linking!";
}
}
Now that we know how to create a command, we need to load the command into BetterRTP.
We can achieve this by running the method load()
in the following.
import me.SuperRonanCraft.BetterRTP.BetterRTP;
public class AddonCommands {
private final LinkCommand cmd = new LinkCommand();
public load() {
HelperRTP_Command.registerCommand(cmd, false);
}
}
Tip: The register method's boolean is to force the plugin to load the command if the command is only enabled when debug mode is enabled.
Adding commands are nice, but one pet peeve is that the command gets unloaded everytime someone executes /rtp reload
.
So we will need a reload listener and register our commands every time this happens. Which can be detected using the RTP_CommandEvent
event.
Example:
import me.SuperRonanCraft.BetterRTP.player.commands.types.CmdReload;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_CommandEvent;
public class ReloadListener implements Listener {
public ReloadListener(Plugin pl) {
Bukkit.getPluginManager().registerEvents(this, pl);
}
@EventHandler
void reload(RTP_CommandEvent e) {
if (e.getCmd() instanceof CmdReload)
AddonCommands.load();
}
}
Want to just RTP a player on your own means? Maybe you want to have you own alias command plugin, or have custom events to rtp a player.
Just call the following method:
Simple Teleport
HelperRTP.tp(player, sendi, world, biomes, RTP_TYPE.ADDON);
Customized Teleport
RTPSetupInformation setup_info = new RTPSetupInformation(player.getWorld().getName(), command_sender, player, personalized, null, true, RTP_TYPE.ADDON, null);
BetterRTP.getInstance().getRTP().start(setup_info);
Tip#1: Player and Command_Sender can be the same, these are just used to send messages, just like what /rtp player <player>
does.
Tip#2: You can provide a String list of biomes to this method, as well as to ignore delays for the player so they cannot perform /rtp
right after.
This method does not check permissions, so make your own permission checks before hand.
Tip#3: RTP Setup Information is a class now needed for API version 3.0.6+, this class holds data for rtp'ing, you can use this class as well to change data before calling the start method!
Chat with us on Discord
Have a Suggestion? Make an issue!
Thank you for viewing the Wiki for BetterRTP!
Did this wiki help you out? Please give it a Star so I know it's getting use!
Check out my other plugins!