API Implementation

From Feudal Wiki
Revision as of 17:18, 22 June 2016 by Forseth11 (Talk | contribs)

Jump to: navigation, search

Feudal is not limited to just itself. Feudal can be used as an API when developing plugins for Spigot or Bukkit. This page will explain how to use Feudal's API and provide information on how to use parts of Feudal which are not explained here.

It is recommended that you add the following to your plugin yml when using Feudal as an API:

softdepend: [Feudal]

JavaDoc

Feudal has java documentation, but the definitions for returns and param are currently not explained. However, Feudal JavaDocs will still be very useful when using Feudal as an API.

Feudal JavaDoc


Accessing the Feudal Class

The Feudal class is the heart of the Feudal.

When accessing any parts of Feudal you should always make sure that Feudal is running. To do so use the following code:

private boolean isUsingFeudal(){
	return Bukkit.getPluginManager().getPlugin("Feudal") != null && Bukkit.getPluginManager().getPlugin("Feudal").isEnabled();
}

If that returns true, then you know Feudal is on the server and running. Now you can get the Feudal class with the following code:

Feudal feudal = Feudal.getPlugin();


Get a User

When getting a user we need to check that Feudal is running just like before. Then to get a user you can use the following code:

User user = Feudal.getUser(player.getUniqueId().toString());

This will return null if this player has no user data or if the user has never joined before or if they have joined, but have not created their character yet.


Get an Offline Player's UUID

If a player has joined the server in the past and they are offline, you may need to get their uuid. Instead of looking it up with the server or pinging a service for this information, you can use the following code to do this through Feudal.

Feudal.getPlayerData().getConfig().getString(username);


Get a Player's Kingdom

To get a player's kingdom you either need their UUID or their User. We will fist start with their UUID.

for(Kingdom kingdom : Feudal.getKingdoms()){
	if(kingdom.isMember(uuid)){
		//This player is in this kingdom
	}
}

This method is not suggested because data corrupt on either the Kingdom's end or User's end will result in problems. Getting a kingdom from a User will check both ends.

Kingdom king = null;
if(user != null && !user.getKingdomUUID().equals("")){
	king = Feudal.getKingdom(user.getKingdomUUID());
}

Note that a kingdom can be null.


Get a Kingdom From Location

Use the following code to get a kingdom from a location. This kingdom can be null since not all land is claimed.

Land land = new Land(player.getLocation());
Kingdom king = Feudal.getLandKingdom(land);


Language File

While using the Feudal API you might want to use some of the strings from the language file. To do so use the following code:

Feudal.getMessage("configField");

If the config field is missing this won't return null, but it will return "§4§lLANGUAGE INFORMATION MISSING", and an error will be sent to console. When the config field exists then the message will be returned, but & will be replaced with the color code and §§ will be replaced with &.


Is More Information Needed?

Does this page not cover enough information? If so, message "forseth11" on spigotmc.org.