diff --git a/src/main/java/com/gamingmesh/jobs/economy/LimitsData.java b/src/main/java/com/gamingmesh/jobs/economy/LimitsData.java index 073c028c..947f9d1e 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/LimitsData.java +++ b/src/main/java/com/gamingmesh/jobs/economy/LimitsData.java @@ -16,28 +16,22 @@ public class LimitsData { @Deprecated public LimitsData(CurrencyType type, long paymentsTime) { - this(type, paymentsTime, 0D); + init(type, paymentsTime, 0D); } @Deprecated public LimitsData(CurrencyType type, long paymentsTime, double payment) { - this.type = type; - this.paymentsTime = paymentsTime; - CurrencyLimit limit = Jobs.getGCManager().getLimit(type); - if (limit.getResetsAt() != null) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - resetsAt = limit.getResetsAt().toMili(); - } else - resetsAt = (limit.getTimeLimit() * 100L) + System.currentTimeMillis(); - this.amount = payment; + init(type, paymentsTime, payment); } public LimitsData(CurrencyType type, double payment) { - this.type = type; - this.paymentsTime = System.currentTimeMillis(); - CurrencyLimit limit = Jobs.getGCManager().getLimit(type); + init(type, System.currentTimeMillis(), payment); + } + private void init(CurrencyType type, long paymentsTime, double payment) { + this.type = type; + this.paymentsTime = paymentsTime; + CurrencyLimit limit = Jobs.getGCManager().getLimit(type); if (limit.getResetsAt() != null) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); @@ -79,8 +73,15 @@ public class LimitsData { return paymentsTime; } + private static long day = (1000L * 60L * 60L * 24L); + public void setPaymentsTime(long paymentsTime) { this.paymentsTime = paymentsTime; + // If first payment time is over 24 hours, reset the amount + if (this.paymentsTime + day < resetsAt) { + setAmount(0); + setReseted(true); + } } public long getResetsAt() { diff --git a/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java b/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java index 390dd924..57acd491 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java +++ b/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java @@ -76,12 +76,9 @@ public class PaymentData { public void addNewAmount(CurrencyType type, Double Payment, Long time) { -// payments.put(type, new LimitsData(type, time == null ? System.currentTimeMillis() : time, Payment)); - LimitsData data = new LimitsData(type, Payment); - if (time != null) - data.setPaymentsTime(time); + data.setPaymentsTime(time == null ? System.currentTimeMillis() : time); payments.put(type, data); }