Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //To load the account file
- public static void loadAccount(OfflinePlayer p) {
- file = new File("plugins/RP/accounts/" + p.getUniqueId() + ".yml");
- acc = new YamlConfiguration().loadConfiguration(file);
- }
- //Method for pay a Player money
- public static void payMoney(Player p, Player target, int money) {
- //Load Player account
- loadAccount(p);
- //If target is not there
- if(target == null) {
- p.sendMessage("§cDer Spieler ist nicht online");
- return;
- }
- //Load Target files
- File tfile = new File("plugins/RP/accounts/" + target.getUniqueId() + ".yml");
- YamlConfiguration tacc = new YamlConfiguration().loadConfiguration(tfile);
- //Break if target haven't a file
- if(!tfile.exists()) {
- p.sendMessage("§cDer Spieler besitzt kein Konto!");
- return;
- }
- //Get Balance from Players
- int pmoney = getBalance(p);
- int tmoney = getBalance(target);
- //Set Players money down
- acc.set("Account.balance", pmoney-money);
- //Set targets money up
- tacc.set("Account.balance", tmoney+money);
- //Save everything
- try {
- acc.save(file);
- tacc.save(tfile);
- p.sendMessage("§aTransaktion erfolgreich! §f(§c-" + money + "€-> §f" + target.getName() + ")");
- target.sendMessage("§aTransaktion erfolgreich! §f(" + p.getName() + " §a-" + money + "€-> §f" + target.getName() + ")");
- } catch (IOException e) {
- p.sendMessage("§4[Fehler] §cBei der Transaktion ist ein Fehler aufgetreten!");
- e.printStackTrace();
- }
- }
- //Method for get the Balance
- public static int getBalance(OfflinePlayer p) {
- loadAccount(p);
- int money = acc.getInt("Account.balance");
- return money;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement