mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-07 00:38:42 +01:00
Lets upgrade JobsPaymentEvent to properly handle all payments types
This commit is contained in:
parent
fae5d65a88
commit
beb9ef76a9
@ -1,38 +1,72 @@
|
|||||||
package com.gamingmesh.jobs.api;
|
package com.gamingmesh.jobs.api;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import com.gamingmesh.jobs.container.CurrencyType;
|
||||||
|
|
||||||
public final class JobsPaymentEvent extends Event implements Cancellable {
|
public final class JobsPaymentEvent extends Event implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private OfflinePlayer offlinePlayer;
|
private OfflinePlayer offlinePlayer;
|
||||||
private double money;
|
|
||||||
private double points;
|
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
|
||||||
|
private HashMap<CurrencyType, Double> payments = new HashMap<CurrencyType, Double>();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public JobsPaymentEvent(OfflinePlayer offlinePlayer, double money, double points) {
|
public JobsPaymentEvent(OfflinePlayer offlinePlayer, double money, double points) {
|
||||||
super(true);
|
super(true);
|
||||||
this.offlinePlayer = offlinePlayer;
|
this.offlinePlayer = offlinePlayer;
|
||||||
this.money = money;
|
payments.put(CurrencyType.MONEY, money);
|
||||||
this.points = points;
|
payments.put(CurrencyType.POINTS, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JobsPaymentEvent(OfflinePlayer offlinePlayer, HashMap<CurrencyType, Double> payments) {
|
||||||
|
super(true);
|
||||||
|
this.offlinePlayer = offlinePlayer;
|
||||||
|
this.payments = payments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OfflinePlayer getPlayer() {
|
public OfflinePlayer getPlayer() {
|
||||||
return offlinePlayer;
|
return offlinePlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getAmount() {
|
@Deprecated
|
||||||
return money;
|
public Double getAmount() {
|
||||||
|
Double amount = this.payments.get(CurrencyType.MONEY);
|
||||||
|
return amount == null ? 0 : amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public double getPoints() {
|
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) {
|
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
|
@Override
|
||||||
@ -45,10 +79,6 @@ public final class JobsPaymentEvent extends Event implements Cancellable {
|
|||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAmount(double money) {
|
|
||||||
this.money = money;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -179,14 +179,14 @@ public class BufferedEconomy {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// JobsPayment event
|
// 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);
|
Bukkit.getServer().getPluginManager().callEvent(JobsPaymentEvent);
|
||||||
// If event is canceled, dont do anything
|
// If event is canceled, dont do anything
|
||||||
if (JobsPaymentEvent.isCancelled())
|
if (JobsPaymentEvent.isCancelled())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
payment.set(CurrencyType.MONEY, JobsPaymentEvent.getAmount());
|
// Do we need this?
|
||||||
payment.set(CurrencyType.POINTS, JobsPaymentEvent.getPoints());
|
payment.getPayment().putAll(JobsPaymentEvent.getPayment());
|
||||||
|
|
||||||
if (Jobs.getGCManager().UseServerAccount) {
|
if (Jobs.getGCManager().UseServerAccount) {
|
||||||
if (!hasMoney) {
|
if (!hasMoney) {
|
||||||
|
@ -48,18 +48,21 @@ public class BufferedPayment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Double getAmount() {
|
public Double getAmount() {
|
||||||
return this.payments.get(CurrencyType.MONEY);
|
Double amount = this.payments.get(CurrencyType.MONEY);
|
||||||
|
return amount == null ? 0 : amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public double getPoints() {
|
public double getPoints() {
|
||||||
return this.payments.get(CurrencyType.POINTS);
|
Double amount = this.payments.get(CurrencyType.POINTS);
|
||||||
|
return amount == null ? 0 : amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public double getExp() {
|
public double getExp() {
|
||||||
return this.payments.get(CurrencyType.EXP);
|
Double amount = this.payments.get(CurrencyType.EXP);
|
||||||
|
return amount == null ? 0 : amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
Loading…
Reference in New Issue
Block a user