Code (Text):
public class Addon extends JavaPlugin {
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
if(!(sender instanceof Player)) return true;
if(commandLabel.equalsIgnoreCase("Addon")){
Player p = (Player) sender;
//Stats
PlayerData stats = OneInTheBattleAPI.getPlayerData(p);
//Give the player coins
stats.addCoins(p, 10);
//Get their stats, such as Kills
int kills = stats.getKills();
int zombieKills = stats.getZombieKills();
//Getting top players
try {
//First you have to load all players data, this should be Async
HashMap<String, String> playersData = OneInTheBattleAPI.getAllPlayersData();
//You can now get top players out of the playersData, ordered by a specfic stat
//If the third argument (int) is bigger than the amount of entries in the playersData hashmap, it will be filled with 'NO_PLAYER'
List<Entry<String, Integer>> top = OneInTheBattleAPI.getTopPlayers(StatType.KILLS, 10, playersData);
//Top now contains the top 10 players, ordered by their kills stat
//Entry key is the player name, and the entry value is their score
for(int i = 0; i < top.size(); i++){
Bukkit.broadcastMessage("# " + (i+1) + " is " + top.get(i).getKey() + " with a score of " + top.get(i).getValue());
}
} catch (SQLException e){
e.printStackTrace();
}
//You can also register your very own perks!
//This creates a new perk, the first String is the perk name, and the second on is the Description
//The material is the item that represents the perk, and the Rarity determines how likely it's for the players to get this perk in a case
//The PerkAction determines WHEN the perk will be executed, in this example, it will be when some one right clicks their axe
//You also could put a cooldown on the ability, in this example, there is a cooldown of 30 seconds on this ability
//The object list returns some information in SOME of the PerkActions for example PerkAction.BOW_HIT returns the player the bow hit as the first object in the list
Perk speed = new Perk("Speed", "Gives the user a speed boost!", Material.BUCKET, Rarity.COMMON, PerkAction.AXE_INTERACT){
@Override
public void execute(Player p, Object object...) {
if(OneInTheBattleAPI.getPlayerData(p).hasCooldown(p, "PERK_SPEED")) return;
OneInTheBattleAPI.getPlayerData(p).setCooldown("PERK_SPEED", 30);
p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 1));
}
};
//Dont forget to register the perk!
OneInTheBattleAPI.registerPerk(speed);
//Version 1.3
//You can now modify offline players stats!
//Arguments are PlayerName, The StatType, The Value, and the last boolean is very important
//If the 'increment' boolean was true, then coins will stack up, so if the user had 100 coins before, they will be 150 in this example
//If the 'increment' boolean was false, then coins will be SET to the that value!
//If you want to remove coins from the user, then the value would be in negative
//You should always run this asynchronously, and make sure that the player is not online!
try {
OneInTheBattleAPI.modifyOfflinePlayerStat("Wazup92", StatType.COINS, 50, true);
} catch (SQLException e) {
e.printStackTrace();
}
}
return true;
}
}