1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Lets upgrade JobsPaymentEvent to properly handle all payments types

This commit is contained in:
Zrips 2019-09-19 14:11:45 +03:00
parent fae5d65a88
commit beb9ef76a9
3 changed files with 52 additions and 19 deletions

View File

@ -1,38 +1,72 @@
package com.gamingmesh.jobs.api;
import java.util.HashMap;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.CurrencyType;
public final class JobsPaymentEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private OfflinePlayer offlinePlayer;
private double money;
private double points;
private boolean cancelled = false;
private HashMap<CurrencyType, Double> payments = new HashMap<CurrencyType, Double>();
@Deprecated
public JobsPaymentEvent(OfflinePlayer offlinePlayer, double money, double points) {
super(true);
this.offlinePlayer = offlinePlayer;
this.money = money;
this.points = points;
payments.put(CurrencyType.MONEY, money);
payments.put(CurrencyType.POINTS, points);
}
public JobsPaymentEvent(OfflinePlayer offlinePlayer, HashMap<CurrencyType, Double> payments) {
super(true);
this.offlinePlayer = offlinePlayer;
this.payments = payments;
}
public OfflinePlayer getPlayer() {
return offlinePlayer;
}
public double getAmount() {
return money;
@Deprecated
public Double getAmount() {
Double amount = this.payments.get(CurrencyType.MONEY);
return amount == null ? 0 : amount;
}
@Deprecated
public double getPoints() {
return points;
Double amount = this.payments.get(CurrencyType.POINTS);
return amount == null ? 0 : amount;
}
@Deprecated
public void setAmount(double amount) {
this.payments.put(CurrencyType.MONEY, amount);
}
@Deprecated
public void setPoints(double points) {
this.points = points;
this.payments.put(CurrencyType.POINTS, points);
}
public Double get(CurrencyType type) {
Double amount = this.payments.get(type);
return amount == null ? 0 : amount;
}
public Double set(CurrencyType type, double amount) {
return this.payments.put(type, amount);
}
public HashMap<CurrencyType, Double> getPayment() {
return payments;
}
@Override
@ -45,10 +79,6 @@ public final class JobsPaymentEvent extends Event implements Cancellable {
this.cancelled = cancelled;
}
public void setAmount(double money) {
this.money = money;
}
@Override
public HandlerList getHandlers() {
return handlers;

View File

@ -179,14 +179,14 @@ public class BufferedEconomy {
continue;
// JobsPayment event
JobsPaymentEvent JobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.get(CurrencyType.MONEY), payment.get(CurrencyType.POINTS));
JobsPaymentEvent JobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.getPayment());
Bukkit.getServer().getPluginManager().callEvent(JobsPaymentEvent);
// If event is canceled, dont do anything
if (JobsPaymentEvent.isCancelled())
continue;
payment.set(CurrencyType.MONEY, JobsPaymentEvent.getAmount());
payment.set(CurrencyType.POINTS, JobsPaymentEvent.getPoints());
// Do we need this?
payment.getPayment().putAll(JobsPaymentEvent.getPayment());
if (Jobs.getGCManager().UseServerAccount) {
if (!hasMoney) {

View File

@ -48,18 +48,21 @@ public class BufferedPayment {
}
@Deprecated
public Double getAmount() {
return this.payments.get(CurrencyType.MONEY);
public Double getAmount() {
Double amount = this.payments.get(CurrencyType.MONEY);
return amount == null ? 0 : amount;
}
@Deprecated
public double getPoints() {
return this.payments.get(CurrencyType.POINTS);
Double amount = this.payments.get(CurrencyType.POINTS);
return amount == null ? 0 : amount;
}
@Deprecated
public double getExp() {
return this.payments.get(CurrencyType.EXP);
Double amount = this.payments.get(CurrencyType.EXP);
return amount == null ? 0 : amount;
}
@Deprecated