Skip to content

Using The API

Picono435 edited this page Jun 29, 2023 · 5 revisions

Overview

This page covers how you can use the PicoJobs API, for create addons and a lot more.

JavaDocs

The javadocs of the PicoJobs API can be found here

Examples

Here you can find some examples of the important things of the API.

ATTENTION: As of v1.0-pre any reference to bukkit class Player has been moved to UUID to better improve multiplatform support.

Getting the managers

// Getting the Jobs Manager.
JobsManager jobsManager = PicoJobsAPI.getJobsManager();
// Getting the Players Manager.
PlayersManager playersManager = PicoJobsAPI.getPlayersManager();

Getting a job player

JobPlayer jp = playersManager.getJobPlayer(uuid);

Check if a player has a job

JobPlayer jp = playersManager.getJobPlayer(uuid);
if(jp.hasJob()) {
    // Player has job
} else {
    // Player doesn't have a job
}

Get player job

JobPlayer jp = playersManager.getJobPlayer(uuid);
Job job = jp.getJob();
if(job == null) {
    // Player does not have a job ;(
    return;
}
// Execute code with job

Get job by name

// Setting the variable of the job name
String jobname = "hunter";
// Getting the job by name
Job job = jobsManager.getJob(jobname);

Get & Compare the job type

# Getting the job type
job.getType();

# Comparing the job type
if(job.getType() == Type.BREAK) {
    // This is a job of the type break
} else {
    // This is not a job of the type break
}

Adding your own Economy Implementation

An economy implementation is used to add a economy type, the plugin has some built-in economy types which can be found here.

Creating the economy implementation class

import com.gmail.picono435.picojobs.api.EconomyImplementation;

public class EconomyExample extends EconomyImplementation {
	
	public EconomyExample() {
		this.requiredPlugin = "PluginExample";
	}
	
	@Override
	public String getName() {
		return "ECONOMY_EXAMPLE";
	}

	@Override
	public double getBalance(UUID player) {
		// Return the balance
		return 0;
	}

	@Override
	public void deposit(UUID player, double amount) {
		// Deposit the balance
	}

	@Override
	public void withdraw(UUID player, double amount) {
		// Withdraw the balance
	}
}

Registering the economy implementation

// Registering normally
PicoJobsAPI.registerEconomy(new EconomyExample());

// Registering &  detecting if it was successfully registered or not
if(PicoJobsAPI.registerEconomy(new EconomyExample())) {
    // The required plugin was found and the economy implementation was successfully registered
} else {
    // The required plugin was not found so the economy implementation was not registered
}

Adding your own Work Zone Implementation

TO-DO