API

Developer API

First, let me say that the PlayerCommands API is working from version 1.4 and forward. Older versions won't work with the API. Anyway, here's how to use the PlayerCommands API. First of all, you might want to add PlayerCommands as a dependency in your IDE, and in your plugin.yml. It should look like this:

#Test plugin name
name: TestPlugin
#Path to main class
main: me.myName.test.Test
#Plugin description
description: "A plugin that uses the PlayerCommands API."
#Depend on PlayerCommands. anyOtherPluginYouWant is optional, and means what it says (It can depend another plugin).
#You can also softdepend PlayerCommands
depend: [PlayerCommands, anyOtherPluginYouWant]
#Optional dependencies.
softdepend: [Vault]

How to use the API

We have provided a class with static methods as an API. We also have a javadoc here. The PlayerCommandsAPI is still in development, but is really easy to use and flexible. You can do many things with it, for example: Set homes for players or offline players, teleport to an offline player, listen to events (i.e. God mode event), set a player vanished, etc. Some example usages are below:

public class Demo {

    /**
     * Gets a home from a player.
     * 
     * @param uuid The UUID of the player.
     * @param homeName The home name.
     * @return The location of the desired home.
     */
    public static Location getHome(UUID uuid, String homeName){
        //Example usage with a PCommandsPlayer.
        PCommandsPlayer player = PCommandsAPI.getPCommandsPlayer(uuid);
        if(player != null) return player.getHome(homeName);
        //Example usage with an IOfflinePCommandsPlayer.
        IOfflinePCommandsPlayer offlinePCommandsPlayer = PCommandsAPI.getOfflinePCommandsPlayer(uuid);
        return offlinePCommandsPlayer.getHome(homeName);
    }

    /**
     * Sets a player in god mode.
     * 
     * @param uuid The player's UUID.
     * @param enabled Whether god mode should be on or off.
     */
    public static void setGodMode(UUID uuid, boolean enabled){
        //Get the player.
        PCommandsPlayer player = PCommandsAPI.getPCommandsPlayer(uuid);
        //Avoid an NPE.
        if(player != null)player.setGodMode(enabled);
    }

    /**
     * Sets the server spawn.
     * @param location The new spawn location.
     */
    public static void setSpawn(Location location){
        PCommandsAPI.setSpawn(location);
    }

    /**
     * Returns a warps location.
     * 
     * @param name Name of the warp.
     * @return The warps location.
     */
    public static Location getWarp(String name){
        return PCommandsAPI.getWarp(name);
    }
    
}

Comments

Posts Quoted:
Reply
Clear All Quotes