Developers API Usage - TheGaming999/PrisonRanksX GitHub Wiki
Dependency name: PrisonRanksX
Add this to your plugin.yml, so PrisonRanksX starts before your plugin starts:
depend: [PrisonRanksX]
// or
softdepend: [PrisonRanksX]
To use PrisonRanksX API in your plugin, all you have to do is written on this code section:
public class Plugin extends JavaPlugin implements Listener {
// new field
PRXAPI api;
public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this);
// load the api
api = new PRXAPI();
// just write api. and you will see all of the available methods
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {
// usage example
Player p = e.getPlayer();
// get player rank name
p.sendMessage("Your rank is: " + api.getPlayerRank(p));
// change player rank
api.setPlayerRankPath(p, new RankPath("Z", "default"));
p.sendMessage("Your rank has been changed to Z!");
}
// you can access the player data asynchronously by using the uuid
@EventHandler
public void onLogin(AsyncPlayerPreLoginEvent e) {
String prestigeName = api.getPlayerPrestige(e.getUniqueId());
String playerName = e.getName();
if(prestigeName != null) {
Bukkit.broadcastMessage(playerName + " prestige is: " + prestigeName);
} else {
Bukkit.broadcastMessage(playerName + " doesn't have a prestige");
}
}
}
Events:
// Cancellable
@EventHandler
public void onRankUpdate(RankUpdateEvent e) {
RankUpdateCause ruc = e.getCause();
Player p = e.getPlayer();
p.sendMessage("Your rank changed because of " + ruc.toString());
// there is not e.getRank() however you can use the api
api.getPlayerRank(p); // rank before the update
api.getPlayerNextRank(p); // rank after the update
// or when using a runTaskLater
Bukkit.getScheduler().runTaskLater(this, () -> {
api.getPlayerRank(p); // rank after the update
}, 1);
}
// Cancellable
@EventHandler
public void onAutoRankup(AsyncAutoRankupEvent e) {}
// Cancellable using RankUpdateEvent RankUpdateCause.RANKUPMAX
@EventHandler
public void onRankupMax(AsyncRankupMaxEvent e) {}
// Cancellable
@EventHandler
public void onPrestige(PrestigeUpdateEvent e) {}
// Cancellable
@EventHandler
public void onRebirth(RebirthUpdateEvent e) {}
// Cancellable
@EventHandler
public void onAutoPrestige(AsyncAutoPrestigeEvent e) {}
// Cancellable
@EventHandler
public void onPrePrestigeMax(PrePrestigeMaxEvent e) {}
@EventHandler
public void onPrestigeMax(AsyncPrestigeMaxEvent e) {}
Other stuff:
PRXAPI api = new PRXAPI();
// to edit ranks/prestiges/rebirths in game
api.getPrisonRanksXManager();
// access prestige data
api.getPrestige(String prestigeName);
// how to use example:
// get the data handler
PrestigeDataHandler prestige = api.getPrestige("P1");
// change prestige cost
prestige.setCost(10.0);
// put it on the storage
api.getPrestigeStorage().put("P1", prestige);
// done
// not necessary but if you want to see it on prestiges.yml
// create an async task
Bukkit.getScheduler().runTaskAsynchronously(mainClass, () -> {
api.getPrestigeStorage().savePrestigesData();
// only if you are not using mysql.
api.getConfigManager().savePrestigesConfig();
});
// done