βοΈAPI
package me.wazup.addon;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import me.wazup.towerdefense.Enums.Stat;
import me.wazup.towerdefense.PlayerData;
import me.wazup.towerdefense.TowerDefense;
import me.wazup.towerdefense.TowerDefenseAPI;
public class Addon extends JavaPlugin {
public void example(){
TowerDefenseAPI api = TowerDefense.api;
//Get a player playerdata
Player p = Bukkit.getPlayer("Wazup92");
PlayerData data = api.getPlayerData(p);
//Modifying some of their stats
data.addCoins(p, 50);
data.kills += 10;
//Some booleans
api.isInArena(p);
api.isSpectating(p);
api.isPlaying(p);
//Getting top players
//First you have to load all players data, this should be Async
try {
HashMap<String, String> playersData = api.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 = api.getTopPlayers(playersData, Stat.KILLS, 10);
//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();
}
//If you want to modify offline players stats, then you have to use a different method, because you can't use the PlayerData class on offline players
//The following method returns true if the stat was updated, and it returns false if the player name wasn't found or the stat wasn't updated for some reason
//The boolean at the end 'increment' is whether you want to SET their stat to the give value, or you want to add it up
try {
boolean updated = api.modifyOfflinePlayerStat("Wazup92", Stat.COINS, 50, true);
} catch (SQLException e){
e.printStackTrace();
}
}
}PlayerData
Last updated