Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.partygames.Enums.Stat;
- import me.wazup.partygames.PlayerData;
- import me.wazup.partygames.PartyGames;
- import me.wazup.partygames.PartyGamesAPI;
- public class Addon extends JavaPlugin {
- public void example(){
- //Get a player playerdata
- Player p = Bukkit.getPlayer("Wazup92");
- PlayerData data = PartyGamesAPI.getPlayerData(p);
- //Modifying some of their stats
- data.addCoins(p, 50);
- data.wins += 10;
- //To save the modifications when a player quits the server without playing a match, write the following
- data.saveStats = true;
- //Getting top players
- //First you have to load all players data, this should be Async
- try {
- HashMap<String, String> playersData = PartyGamesAPI.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 = PartyGamesAPI.getTopPlayers(playersData, Stat.COINS, 10);
- //Top now contains the top 10 players, ordered by their coins 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 = PartyGamesAPI.modifyOfflinePlayerStat("Wazup92", Stat.COINS, 50, true);
- } catch (SQLException e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement