I have a problem with creating a economy system

Discussion in 'Spigot Help' started by yurinogueira, Mar 22, 2020.

  1. I am having a problem with the player removing money part. Instead of removing a specific amount, this remove all the money that the player has.

    Code (Java):
        @Override
        public EconomyResponse withdrawPlayer(String playerName, double amount) {
            MoneyAPI.removeMoney(UUIDFetcher.getUUID(playerName), amount);
            return new EconomyResponse(amount, MoneyAPI.getMoney(UUIDFetcher.getUUID(playerName)), EconomyResponse.ResponseType.SUCCESS, null);
        }

        @Override
        public EconomyResponse withdrawPlayer(OfflinePlayer player, double amount) {
            MoneyAPI.removeMoney(player.getUniqueId(), amount);
            return new EconomyResponse(amount, MoneyAPI.getMoney(player.getUniqueId()), EconomyResponse.ResponseType.SUCCESS, null);
        }

        @Override
        public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) {
            MoneyAPI.removeMoney(UUIDFetcher.getUUID(playerName), amount);
            return new EconomyResponse(amount, MoneyAPI.getMoney(UUIDFetcher.getUUID(playerName)), EconomyResponse.ResponseType.SUCCESS, null);
        }

        @Override
        public EconomyResponse withdrawPlayer(OfflinePlayer player, String worldName, double amount) {
            MoneyAPI.removeMoney(player.getUniqueId(), amount);
            return new EconomyResponse(amount, MoneyAPI.getMoney(player.getUniqueId()), EconomyResponse.ResponseType.SUCCESS, null);
        }

    Code (Java):
        public static double getMoney(UUID uuid) {
            if (Vars.money.containsKey(uuid.toString())) {
                return Vars.money.get(uuid.toString());
            }
            double i = 0;
            if (PlayerManager.PlayerExist(uuid)) {
                try {
                    final ResultSet rs = EterniaServer.sqlcon.Query("SELECT * FROM eternia WHERE UUID='" + uuid.toString() + "';");
                    if (rs.next()) {
                        rs.getDouble("BALANCE");
                    }
                    i = rs.getDouble("BALANCE");
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } else {
                PlayerManager.CreatePlayer(uuid);
                getMoney(uuid);
            }
            Vars.money.put(uuid.toString(), i);
            return i;
        }

        public static void setMoney(UUID uuid, double Money) {
            if (PlayerManager.PlayerExist(uuid)) {
                Vars.money.remove(uuid.toString());
                Vars.money.put(uuid.toString(), Money);
                EterniaServer.sqlcon.Update("UPDATE eternia SET BALANCE='" + Money + "' WHERE UUID='" + uuid.toString() + "';");
            } else {
                PlayerManager.CreatePlayer(uuid);
                setMoney(uuid, Money);
            }
        }

        public static void addMoney(UUID uuid, double money) {
            if (PlayerManager.PlayerExist(uuid)) {
                setMoney(uuid, getMoney(uuid) + money);
            } else {
                PlayerManager.CreatePlayer(uuid);
                addMoney(uuid, getMoney(uuid) + money);
            }
        }

        public static void removeMoney(UUID uuid, double money) {
            if (PlayerManager.PlayerExist(uuid)) {
                money = getMoney(uuid) - money;
                setMoney(uuid, money);
            } else {
                PlayerManager.CreatePlayer(uuid);
                money = getMoney(uuid) - money;
                removeMoney(uuid, money);
            }
        }
    Code (Java):
        public static final HashMap<String, Double> money = new HashMap<>();