mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
Updating payment limit handling
This commit is contained in:
parent
07e97f50ae
commit
3d48656311
@ -1276,11 +1276,17 @@ public class Jobs extends JavaPlugin {
|
||||
if (jobsExpGainEvent.isCancelled())
|
||||
return;
|
||||
|
||||
boolean limited = true;
|
||||
for (CurrencyType one : CurrencyType.values()) {
|
||||
if (!jPlayer.isUnderLimit(one, payment.get(one)))
|
||||
return;
|
||||
if (jPlayer.isUnderLimit(one, payment.get(one))) {
|
||||
limited = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (limited)
|
||||
return;
|
||||
|
||||
economy.pay(jPlayer, payment.getPayment());
|
||||
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
|
@ -52,14 +52,10 @@ public class limit implements Cmd {
|
||||
if (!Jobs.getGCManager().getLimit(type).isEnabled())
|
||||
continue;
|
||||
PaymentData limit = JPlayer.getPaymentLimit();
|
||||
if (limit == null) {
|
||||
int lefttime1 = Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000;
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort((long) lefttime1)));
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "Limit",
|
||||
"%current%", "0.0",
|
||||
"%total%", JPlayer.getLimit(type)));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (limit.getLeftTime(type) <= 0)
|
||||
limit.resetLimits(type);
|
||||
|
||||
if (limit.getLeftTime(type) > 0) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort(limit.getLeftTime(type))));
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "Limit",
|
||||
|
@ -166,7 +166,7 @@ public class JobsPlayer {
|
||||
if (data.isReachedLimit(type, value == null ? 0 : value)) {
|
||||
String name = type.getName().toLowerCase();
|
||||
|
||||
if (player.isOnline() && !data.isInformed() && !data.isReseted()) {
|
||||
if (player.isOnline() && !data.isInformed() && !data.isReseted(type)) {
|
||||
if (Jobs.getGCManager().useMaxPaymentCurve) {
|
||||
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + name + "limit"));
|
||||
player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + name + "limit2"));
|
||||
@ -179,8 +179,8 @@ public class JobsPlayer {
|
||||
}
|
||||
if (data.isAnnounceTime(limit.getAnnouncementDelay()) && player.isOnline())
|
||||
ActionBarManager.send(player, Jobs.getLanguage().getMessage("command.limit.output." + name + "time", "%time%", TimeManage.to24hourShort(data.getLeftTime(type))));
|
||||
if (data.isReseted())
|
||||
data.setReseted(false);
|
||||
if (data.isReseted(type))
|
||||
data.setReseted(type, false);
|
||||
return false;
|
||||
}
|
||||
data.addAmount(type, amount);
|
||||
|
57
src/main/java/com/gamingmesh/jobs/economy/LimitsData.java
Normal file
57
src/main/java/com/gamingmesh/jobs/economy/LimitsData.java
Normal file
@ -0,0 +1,57 @@
|
||||
package com.gamingmesh.jobs.economy;
|
||||
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
|
||||
public class LimitsData {
|
||||
private CurrencyType type = null;
|
||||
private double amount = 0D;
|
||||
private long paymentsTime = 0L;
|
||||
private boolean reseted = false;
|
||||
|
||||
public LimitsData(CurrencyType type, long paymentsTime) {
|
||||
this(type, paymentsTime, 0D);
|
||||
}
|
||||
|
||||
public LimitsData(CurrencyType type, long paymentsTime, double payment) {
|
||||
this.type = type;
|
||||
this.paymentsTime = paymentsTime;
|
||||
this.amount = payment;
|
||||
}
|
||||
|
||||
public boolean isReseted() {
|
||||
return reseted;
|
||||
}
|
||||
|
||||
public void setReseted(boolean reseted) {
|
||||
this.reseted = reseted;
|
||||
}
|
||||
|
||||
public CurrencyType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(CurrencyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public double addAmount(double amount) {
|
||||
return this.amount += amount;
|
||||
}
|
||||
|
||||
public void setAmount(double payment) {
|
||||
this.amount = payment;
|
||||
}
|
||||
|
||||
public long getPaymentsTime() {
|
||||
return paymentsTime;
|
||||
}
|
||||
|
||||
public void setPaymentsTime(long paymentsTime) {
|
||||
this.paymentsTime = paymentsTime;
|
||||
}
|
||||
|
||||
}
|
@ -9,30 +9,24 @@ public class PaymentData {
|
||||
|
||||
private Long lastAnnouced = 0L;
|
||||
|
||||
private final HashMap<CurrencyType, Double> payments = new HashMap<>();
|
||||
private final HashMap<CurrencyType, Long> paymentsTimes = new HashMap<>();
|
||||
private final HashMap<CurrencyType, LimitsData> payments = new HashMap<>();
|
||||
|
||||
private boolean informed = false;
|
||||
private boolean reseted = false;
|
||||
|
||||
public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) {
|
||||
paymentsTimes.put(CurrencyType.EXP, time);
|
||||
paymentsTimes.put(CurrencyType.MONEY, time);
|
||||
paymentsTimes.put(CurrencyType.POINTS, time);
|
||||
payments.put(CurrencyType.EXP, Exp);
|
||||
payments.put(CurrencyType.MONEY, Payment);
|
||||
payments.put(CurrencyType.POINTS, Points);
|
||||
|
||||
payments.put(CurrencyType.EXP, new LimitsData(CurrencyType.EXP, time, Exp));
|
||||
payments.put(CurrencyType.MONEY, new LimitsData(CurrencyType.MONEY, time, Payment));
|
||||
payments.put(CurrencyType.POINTS, new LimitsData(CurrencyType.POINTS, time, Points));
|
||||
this.lastAnnouced = lastAnnouced;
|
||||
this.informed = Informed;
|
||||
}
|
||||
|
||||
public PaymentData(CurrencyType type, Double amount) {
|
||||
paymentsTimes.put(type, System.currentTimeMillis());
|
||||
payments.put(type, amount);
|
||||
|
||||
this.lastAnnouced = 0L;
|
||||
this.informed = false;
|
||||
for (CurrencyType one : CurrencyType.values()) {
|
||||
if (one != type)
|
||||
payments.put(one, new LimitsData(one, System.currentTimeMillis(), 0D));
|
||||
}
|
||||
payments.put(type, new LimitsData(type, System.currentTimeMillis(), amount));
|
||||
}
|
||||
|
||||
public PaymentData() {
|
||||
@ -40,19 +34,19 @@ public class PaymentData {
|
||||
}
|
||||
|
||||
public Long getTime(CurrencyType type) {
|
||||
return paymentsTimes.get(type);
|
||||
return payments.get(type).getPaymentsTime();
|
||||
}
|
||||
|
||||
public void setReseted(boolean reseted) {
|
||||
this.reseted = reseted;
|
||||
public void setReseted(CurrencyType type, boolean reseted) {
|
||||
payments.get(type).setReseted(reseted);
|
||||
}
|
||||
|
||||
public boolean isReseted() {
|
||||
return reseted;
|
||||
public boolean isReseted(CurrencyType type) {
|
||||
return payments.get(type).isReseted();
|
||||
}
|
||||
|
||||
public Double getAmount(CurrencyType type) {
|
||||
return !payments.containsKey(type) ? 0D : (int) (payments.get(type) * 100) / 100D;
|
||||
return !payments.containsKey(type) ? 0D : (int) (payments.get(type).getAmount() * 100) / 100D;
|
||||
}
|
||||
|
||||
public Double getAmountBylimit(CurrencyType type, int limit) {
|
||||
@ -80,12 +74,11 @@ public class PaymentData {
|
||||
}
|
||||
|
||||
public void addNewAmount(CurrencyType type, Double Payment, Long time) {
|
||||
paymentsTimes.put(type, time == null ? System.currentTimeMillis() : time);
|
||||
payments.put(type, Payment);
|
||||
payments.put(type, new LimitsData(type, time == null ? System.currentTimeMillis() : time, Payment));
|
||||
}
|
||||
|
||||
public void addAmount(CurrencyType type, Double Payment) {
|
||||
payments.put(type, payments.get(type) + Payment);
|
||||
payments.get(type).addAmount(Payment);
|
||||
}
|
||||
|
||||
public long getLeftTime(CurrencyType type) {
|
||||
@ -96,13 +89,13 @@ public class PaymentData {
|
||||
}
|
||||
|
||||
public boolean isOverLimit(CurrencyType type, int limit) {
|
||||
if (payments.get(type) < limit)
|
||||
if (payments.get(type).getAmount() < limit)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public double percentOverLimit(CurrencyType type, int limit) {
|
||||
return ((payments.get(type) / limit) - 1) * 100;
|
||||
return ((payments.get(type).getAmount() / limit) - 1) * 100;
|
||||
}
|
||||
|
||||
public boolean isOverTimeLimit(CurrencyType type) {
|
||||
@ -117,8 +110,13 @@ public class PaymentData {
|
||||
public void resetLimits() {
|
||||
for (CurrencyType type : CurrencyType.values()) {
|
||||
addNewAmount(type, 0D);
|
||||
setReseted(type, true);
|
||||
}
|
||||
reseted = true;
|
||||
}
|
||||
|
||||
public void resetLimits(CurrencyType type) {
|
||||
addNewAmount(type, 0D);
|
||||
setReseted(type, true);
|
||||
}
|
||||
|
||||
public boolean isReachedLimit(CurrencyType type, int money) {
|
||||
|
Loading…
Reference in New Issue
Block a user