API Documentation

*API/Documentation:*

READ THIS FIRST: Should I be on this page? If you are a server admin looking to install TravelPad, this has NO relevance for you. If you are a developer or a plugin creator who is looking to develop side-plugins that hook into TravelPad, or use/modify TravelPad's system in your plugin, then YES you should read this page.

JavaDocs:

To start accessing TravelPad in your plugin, first add the following to your plugin.yml: depend: [TravelPad]

If you are only using it in some circumstances (meaning your plugin will not break if TravelPad is not present) use: softdepend: [TravelPad]

Then, head to your onEnable() method, and gain access to the TravelPadManager like so:

TravelPadManager manager = manager = new TravelPadManager(this.getServer().getPluginManager().getPlugin("TravelPad"));

You can then use it's methods to control and interact with TravelPad.

Events: There are also 5 events that are available to listen for:

  • TravelPadCreateEvent - Called when a player creates a TravelPad
  • TravelPadDeleteEvent - Called when a player deletes his/her TravelPad, either by command or by breaking it.
  • TravelPadExpireEvent - Called when a TravelPad goes a minute without being named and expires
  • TravelPadNameEvent - Called when a player names his/her unnamed pad and it becomes useable
  • TravelPadTeleportEvent - Called when a player teleports from one pad to another.

Example:

Here is an example class that gets a list of created pads and sends them to a player when they type /tplist:

import java.util.List;
import net.h31ix.travelpad.api.Pad;
import net.h31ix.travelpad.api.TravelPadManager;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class TravelPadList extends JavaPlugin {
    TravelPadManager manager;
    
    public void onDisable() {
    }

    public void onEnable() {
        getCommand("tplist").setExecutor(this);
        manager = new TravelPadManager(getServer().getPluginManager().getPlugin("TravelPad"));
    }
    
    @Override
    public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
        if (cs instanceof Player)
        {
            Player player = (Player)cs;
            if (player.hasPermission("travelpad.list"))
            {
                List<Pad> pads = manager.getPads();
                player.sendMessage(ChatColor.GREEN+"-------------[TravelPad List]-------------");
                for (Pad pad : pads)
                {
                    player.sendMessage(ChatColor.GREEN+pad.getName()+" : "+pad.getOwner());
                }
            }
        }
        return true;
    }
}

Result: Result


Comments

Posts Quoted:
Reply
Clear All Quotes