Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.insideintel.arena.API;
- import org.bukkit.configuration.InvalidConfigurationException;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import java.io.File;
- import java.io.IOException;
- public class Economy {
- public static FileConfiguration GetEconomy(Player p) {
- File user = GetUserData.GetPlayerFolder(p);
- FileConfiguration config = new YamlConfiguration();
- try {
- config.load(user);
- String money = config.getString("Money");
- if (money == null) {
- config.set("Money", 0.0);
- config.save(user);
- }
- } catch (IOException | InvalidConfigurationException ex) {
- System.out.println(ex);
- }
- return config;
- }
- public static void SaveMoney(Player p) {
- }
- public static void Add(Player p, double amount) {
- File user = GetUserData.GetPlayerFolder(p);
- FileConfiguration a = GetEconomy(p);
- try {
- a.load(user);
- a.set("Money", a.getDouble("Money") + amount);
- a.save(user);
- } catch (IOException | InvalidConfigurationException ex) {
- }
- }
- public static void Remove(Player p, double amount) {
- File user = GetUserData.GetPlayerFolder(p);
- FileConfiguration a = GetEconomy(p);
- try {
- a.load(user);
- if (Has(p, 0)) {
- if (Get(p) >= amount) {
- a.set("Money", a.getDouble("Money") - amount);
- a.save(user);
- }
- }
- } catch (IOException | InvalidConfigurationException ex) {
- }
- }
- public static void Set(Player p, double amount) {
- File user = GetUserData.GetPlayerFolder(p);
- FileConfiguration a = GetEconomy(p);
- try {
- a.load(user);
- a.set("Money", amount);
- a.save(user);
- } catch (IOException | InvalidConfigurationException ex) {
- }
- }
- public static boolean Has(Player p, double amount) {
- File user = GetUserData.GetPlayerFolder(p);
- FileConfiguration a = GetEconomy(p);
- double money = a.getDouble("Money");
- return money >= amount;
- }
- public static double Get(Player p) {
- File user = GetUserData.GetPlayerFolder(p);
- FileConfiguration a = GetEconomy(p);
- double money = a.getDouble("Money");
- return money;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement