Advertisement
SamWilko

Untitled

Jun 19th, 2022
926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package me.wilko.economy;
  2.  
  3. import me.wilko.settings.Settings;
  4. import org.bukkit.entity.Player;
  5. import org.mineacademy.fo.settings.YamlConfig;
  6.  
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. import java.util.UUID;
  10.  
  11. public class PlayerAccount extends YamlConfig {
  12.  
  13.     private final UUID uuid;
  14.     private double balance = 0;
  15.     private static final Map<UUID, PlayerAccount> accounts = new HashMap<>();
  16.  
  17.     public PlayerAccount(String name) {
  18.         this(name, null);
  19.     }
  20.  
  21.     public PlayerAccount(String name, java.util.UUID uuid) {
  22.         this.uuid = uuid;
  23.  
  24.         this.loadConfiguration("accounts/" + uuid.toString() + ".yml");
  25.  
  26.         accounts.put(uuid, this);
  27.     }
  28.  
  29.     public UUID getUUID() {
  30.         return uuid;
  31.     }
  32.  
  33.     public double getBalance() {
  34.         return balance;
  35.     }
  36.  
  37.     public void setBalance(double balance) {
  38.         this.balance = balance;
  39.  
  40.         this.save();
  41.     }
  42.  
  43.     @Override
  44.     protected void onLoad() {
  45.         this.balance = this.getInteger("bal", Settings.START_BAL);
  46.     }
  47.  
  48.     @Override
  49.     protected void onSave() {
  50.         this.set("bal", this.balance);
  51.     }
  52.  
  53.     public static PlayerAccount findAccount(Player player) {
  54.         return PlayerAccount.findAccount(player.getName(), player.getUniqueId());
  55.     }
  56.  
  57.     public static PlayerAccount findAccount(String name, UUID uuid) {
  58.  
  59.         PlayerAccount account = accounts.get(uuid);
  60.  
  61.         if (account == null)
  62.             account = new PlayerAccount(name, uuid);
  63.  
  64.  
  65.         return account;
  66.     }
  67.  
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement