API Implementation

From Feudal Wiki
Revision as of 01:42, 16 July 2017 by Forseth11 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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. This will make Feudal enable before your plugin:

softdepend: [Feudal]


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 Feudal

First make sure Feudal.jar is setup as a library for your project. It is done the same way you use Spigot.jar or Bukkit.jar as a library.

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 FeudalAPI class with the following code:

FeudalAPI feudal = Feudal.getAPI();

You should not have any Feudal code or imports included inside of any of your classes which have code doing other things (unless you require Feudal to always be on the server). You should have a class or a few classes dedicated to running any Feudal methods you need. This will allow a user to use your plugin with OR without Feudal. Just every time you make a call to that feudal handling class, make sure Feudal is enabled. You do not need to check if it is enabled every time, so you could use the code above to set a boolean in your main class and just check that variable.

To be sure you did it this right, temporarily remove Feudal.jar as a library and refresh your project. If there are any errors in classes which are essential to run your plugin, then you should move the code which has those errors into another class otherwise a person using your plugin will have to have Feudal installed.

Get a User

In this example `player` is a Bukkit Player.

User user = Feudal.getAPI().getUser(player.getUUID());


User user = Feudal.getAPI().getUser(player.getName());

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 a Player's Kingdom

You can get a player's kingdom from their Bukkit Player, their name, their UUID, or their Feudal User.

Getting their kingdom from their UUID:

Kingdom kingdom = Feudal.getAPI().getKingdom(player.getUniqueId())

Getting a kingdom from a Feudal User.

Kingdom kingdom = Feudal.getAPI().getKingdom(user)

Getting a kingdom from an OfflinePlayer (Can also use Bukkit Player).

Kingdom kingdom = Feudal.getAPI().getKingdom(offlinePlayer)

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.

Kingdom kingdom = Feudal.getAPI().getKingdom(location)

The `location` variable is a Bukkit Location.

Custom Feudal Command

Perhaps you need to add a sub command to Feudal. To learn how to do that, click here to read about Custom Feudal Commands.

Feudal Events

There are also some Feudal events which can be used just like all other Bukkit events, but they are triggered when a specific think in Feudal happens. Read about Feudal Events here.

Get a Challenge

If you need to get an active challenge/war, you can also use this API.

If you want to get all active challenges for a specific kingdom, use the following:

List<Challenge> challenges = Feudal.getAPI().getChallenges(kingdom);

If you want to get ALL active challenges, use the following:

List<Challenge> challenges = Feudal.getAPI().getChallenges();

If you want to get the challenge between two kingdoms, use the following:

Challenge challenge = Feudal.getAPI().getChallenge(attacker, defender);

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:


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.