-
Notifications
You must be signed in to change notification settings - Fork 12
Using The API
Picono435 edited this page Apr 29, 2023
·
5 revisions
This page covers how you can use the PicoJobs API, for create addons and a lot more.
Remember that all the softwares connected to PicoJobs should have the license GPL-3.0, as said here.
The javadocs of the PicoJobs API can be found here
Here you can find some examples of the important things of the API.
// Getting the Jobs Manager.
JobsManager jobsManager = PicoJobsAPI.getJobsManager();
// Getting the Players Manager.
PlayersManager playersManager = PicoJobsAPI.getPlayersManager();
JobPlayer jp = playersManager.getJobPlayer(player);
JobPlayer jp = playersManager.getJobPlayer(player);
if(jp.hasJob()) {
// Player has job
} else {
// Player doesn't have a job
}
JobPlayer jp = playersManager.getJobPlayer(player);
Job job = jp.getJob();
if(job == null) {
// Player does not have a job ;(
return;
}
// Execute code with job
// Setting the variable of the job name
String jobname = "hunter";
// Getting the job by name
Job job = jobsManager.getJob(jobname);
# 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
}
A economy implementation is used to add a economy type, the plugin have these built-in economy types: VAULT, POINTS, TOKEN_MANAGER & EXP. For more information about what are these economy implementations check this.
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.gmail.picono435.picojobs.api.EconomyImplementation;
public class EconomyExample extends EconomyImplementation {
public EconomyExample() {
this.requiredPlugin = Bukkit.getPluginManager().getPlugin("PluginExample");
}
@Override
public String getName() {
return "ECONOMY_EXAMPLE";
}
@Override
public double getBalance(Player player) {
// Return the balance
return 0;
}
@Override
public void deposit(Player player, double amount) {
// Deposit the balance
}
@Override
public void withdraw(Player player, double amount) {
// Withdraw the balance
}
}
// 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
}
TO-DO
Thanks for using PicoJobs