Advertisement
Guest User

Untitled

a guest
Aug 25th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. //To load the account file
  2. public static void loadAccount(OfflinePlayer p) {
  3. file = new File("plugins/RP/accounts/" + p.getUniqueId() + ".yml");
  4. acc = new YamlConfiguration().loadConfiguration(file);
  5. }
  6.  
  7. //Method for pay a Player money
  8. public static void payMoney(Player p, Player target, int money) {
  9. //Load Player account
  10. loadAccount(p);
  11.  
  12. //If target is not there
  13. if(target == null) {
  14. p.sendMessage("§cDer Spieler ist nicht online");
  15. return;
  16. }
  17.  
  18. //Load Target files
  19. File tfile = new File("plugins/RP/accounts/" + target.getUniqueId() + ".yml");
  20. YamlConfiguration tacc = new YamlConfiguration().loadConfiguration(tfile);
  21.  
  22. //Break if target haven't a file
  23. if(!tfile.exists()) {
  24. p.sendMessage("§cDer Spieler besitzt kein Konto!");
  25. return;
  26. }
  27.  
  28. //Get Balance from Players
  29. int pmoney = getBalance(p);
  30. int tmoney = getBalance(target);
  31.  
  32. //Set Players money down
  33. acc.set("Account.balance", pmoney-money);
  34.  
  35. //Set targets money up
  36. tacc.set("Account.balance", tmoney+money);
  37.  
  38. //Save everything
  39. try {
  40. acc.save(file);
  41. tacc.save(tfile);
  42. p.sendMessage("§aTransaktion erfolgreich! §f(§c-" + money + "€-> §f" + target.getName() + ")");
  43. target.sendMessage("§aTransaktion erfolgreich! §f(" + p.getName() + " §a-" + money + "€-> §f" + target.getName() + ")");
  44. } catch (IOException e) {
  45. p.sendMessage("§4[Fehler] §cBei der Transaktion ist ein Fehler aufgetreten!");
  46. e.printStackTrace();
  47. }
  48. }
  49.  
  50.  
  51.  
  52. //Method for get the Balance
  53. public static int getBalance(OfflinePlayer p) {
  54. loadAccount(p);
  55.  
  56. int money = acc.getInt("Account.balance");
  57.  
  58. return money;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement