Advertisement
Guest User

Untitled

a guest
Aug 17th, 2023
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. package me.wazup.addon;
  2. import java.sql.SQLException;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map.Entry;
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9. import me.wazup.partygames.Enums.Stat;
  10. import me.wazup.partygames.PlayerData;
  11. import me.wazup.partygames.PartyGames;
  12. import me.wazup.partygames.PartyGamesAPI;
  13.  
  14. public class Addon extends JavaPlugin {
  15.  
  16. public void example(){
  17.  
  18. //Get a player playerdata
  19. Player p = Bukkit.getPlayer("Wazup92");
  20. PlayerData data = PartyGamesAPI.getPlayerData(p);
  21.  
  22. //Modifying some of their stats
  23. data.addCoins(p, 50);
  24. data.wins += 10;
  25.  
  26. //To save the modifications when a player quits the server without playing a match, write the following
  27. data.saveStats = true;
  28.  
  29. //Getting top players
  30. //First you have to load all players data, this should be Async
  31. try {
  32. HashMap<String, String> playersData = PartyGamesAPI.getAllPlayersData();
  33. //You can now get top players out of the playersData, ordered by a specfic stat
  34. //If the third argument (int) is bigger than the amount of entries in the playersData hashmap, it will be filled with 'NO_PLAYER'
  35. List<Entry<String, Integer>> top = PartyGamesAPI.getTopPlayers(playersData, Stat.COINS, 10);
  36. //Top now contains the top 10 players, ordered by their coins stat
  37. //Entry key is the player name, and the entry value is their score
  38. for(int i = 0; i < top.size(); i++){
  39. Bukkit.broadcastMessage("# " + (i+1) + " is " + top.get(i).getKey() + " with a score of " + top.get(i).getValue());
  40. }
  41. } catch (SQLException e){
  42. e.printStackTrace();
  43. }
  44.  
  45. //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
  46. //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
  47. //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
  48. try {
  49. boolean updated = PartyGamesAPI.modifyOfflinePlayerStat("Wazup92", Stat.COINS, 50, true);
  50. } catch (SQLException e){
  51. e.printStackTrace();
  52. }
  53.  
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement