Skip to content
RonanCraft edited this page Mar 16, 2022 · 20 revisions

The BetterRTP API is a fairly powerful tool when it comes to changing and listening to RTP events.

Getting Started

Remember to add BetterRTP to your plugin.yml -> softdepend.
BetterRTP does not currently have an online maven repository, so this will need to be installed manually.

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

pom setup:

...
<dependencies>
  <dependency>
    <groupId>me.SuperRonanCraft</groupId>
    <artifactId>BetterRTP</artifactId>
    <version>3.2.3</version>
    <scope>provided</scope>
  </dependency>
<dependencies>
...

Events

Events are implemented right into the Bukkit API. Just use a Listener class and @EventHandler to listen to these events.

Event Description
RTP_CancelledEvent Called when an rtp is cancelled due to a player moving while under a delay
RTP_CommandEvent Called every time a player executes /rtp ...
RTP_CommandEvent_After Called after a successfully executed command
RTP_FindLocationEvent Called every time a new location find request is called
RTP_SettingUpEvent Called when an rtp is being setup to find a location
RTP_TeleportEvent Called right when a safe location is found and about to teleport a player
RTP_TeleportPostEvent Called after a random teleport
RTP_TeleportPreEvent Called before a random teleport

Commands

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!";
    }
}

Registering Commands

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.

Reload Listener

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();
    }
}

RTP a Player

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!

Clone this wiki locally