API


Generated Documentation (v2.0.1): https://projects.samjakob.com/friend-referral/documentation/



Guides

These guides will teach you the basics of interacting with the FriendReferral API.

Table of Contents
  1. Hooking into FriendReferral
  2. Getting a player’s code

Hooking into FriendReferral

Note: For this tutorial, I will be demonstrating from IntelliJ IDEA (Community).

You will want to download the FriendReferral JAR to reference it from your IDE. You can get it from the SpigotMC resource page.

Once you’ve downloaded it, you need to add it to IntelliJ. (If you aren’t using IntelliJ or already know how to do this, you can skip this.) You need to open Project Structure to add the library. To do this, press Ctrl+Alt+Shift+S. The following window will open:

    1. Click ‘Modules’ in the sidebar
    2. Click the green ‘+’ icon on the right.
    3. Click ‘1 JARs or directories…’

In the dialog that opens, select the JAR on your drive and click ‘OK’. The JAR is now imported.

Next, you need to add FriendReferral as a dependency in your plugin.yml. To do this, simply add the following to your plugin.yml.

depend: [FriendReferral]

Finally you need to actually integrate with the plugin. This is very simple.

// This is the reference to the FriendReferral API.
private ReferralAPI referralAPI;

public void onEnable(){
	if(!getServer().getPluginManager().isPluginEnabled("FriendReferral")){
		// Disable plugin if FriendReferral is not installed.
		getLogger().severe("Unable to find FriendReferral dependency. Disabling plugin...");
		getServer().getPluginManager().disablePlugin(this);
	}
	
	// Set the reference.
	referralAPI = FriendReferral.getAPI();
}

Getting a player’s code

You can now use your ReferralAPI reference. In this example, the player is being given their code:

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
	// Usage: /refer-code
	if(cmd.getName().equalsIgnoreCase("refer-code")){
		// Make sure the sender isn't the console or a command block.
		if(sender instanceof Player){
			// Cast the sender to a player object
			Player player = (Player) sender;
			// Use the FriendReferral API to tell the player their FriendReferral code.
			sender.sendMessage("Your referral code is " + referralAPI.getCode(player));
		}else{
			sender.sendMessage("You must be a player!");
		}
	}
}

For a full list of methods and features, check the generated documentation (see the top of the page.)