mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-08 08:08:05 +01:00
Add ability to mark all economic events as handled
This resolves issues when multiple listeners try to handle the same events e.g. for group support which would've passed it onto the normal listeners leading to errors
This commit is contained in:
parent
d868fe8af6
commit
24d89dbc44
@ -41,7 +41,7 @@ public class Economy {
|
||||
CurrencyAddEvent event = new CurrencyAddEvent(BigDecimal.valueOf(amount), name, world);
|
||||
ChestShop.callEvent(event);
|
||||
|
||||
return event.isAdded();
|
||||
return event.wasHandled();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,7 +52,7 @@ public class Economy {
|
||||
CurrencySubtractEvent event = new CurrencySubtractEvent(BigDecimal.valueOf(amount), name, world);
|
||||
ChestShop.callEvent(event);
|
||||
|
||||
return event.isSubtracted();
|
||||
return event.wasHandled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -11,10 +10,10 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class AccountCheckEvent extends Event {
|
||||
public class AccountCheckEvent extends EconomicEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
boolean outcome = false;
|
||||
private boolean outcome = false;
|
||||
|
||||
private UUID account;
|
||||
private World world;
|
||||
|
@ -2,7 +2,6 @@ package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -15,11 +14,9 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencyAddEvent extends Event {
|
||||
public class CurrencyAddEvent extends EconomicEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
boolean added = false;
|
||||
|
||||
private BigDecimal amount;
|
||||
private UUID target;
|
||||
private World world;
|
||||
@ -70,18 +67,22 @@ public class CurrencyAddEvent extends Event {
|
||||
|
||||
/**
|
||||
* @return Was the money already added to the account?
|
||||
* @deprecated Use {@link #wasHandled()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isAdded() {
|
||||
return added;
|
||||
return wasHandled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the money was added to the account
|
||||
*
|
||||
* @param added Was the money added?
|
||||
* @deprecated Use {@link #setHandled(boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setAdded(boolean added) {
|
||||
this.added = added;
|
||||
setHandled(added);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,6 @@ package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -13,7 +12,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencyAmountEvent extends Event {
|
||||
public class CurrencyAmountEvent extends EconomicEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private BigDecimal amount = BigDecimal.ZERO;
|
||||
|
@ -2,7 +2,6 @@ package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -13,7 +12,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencyCheckEvent extends Event {
|
||||
public class CurrencyCheckEvent extends EconomicEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private boolean outcome = false;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -10,7 +9,7 @@ import java.math.BigDecimal;
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencyFormatEvent extends Event {
|
||||
public class CurrencyFormatEvent extends EconomicEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final BigDecimal amount;
|
||||
|
@ -2,7 +2,6 @@ package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -13,10 +12,10 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencyHoldEvent extends Event {
|
||||
public class CurrencyHoldEvent extends EconomicEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
boolean canHold = true;
|
||||
private boolean canHold = true;
|
||||
|
||||
private BigDecimal amount;
|
||||
private UUID account;
|
||||
|
@ -15,11 +15,9 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencySubtractEvent extends Event {
|
||||
public class CurrencySubtractEvent extends EconomicEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
boolean subtracted = false;
|
||||
|
||||
private BigDecimal amount;
|
||||
private UUID target;
|
||||
private World world;
|
||||
@ -70,18 +68,22 @@ public class CurrencySubtractEvent extends Event {
|
||||
|
||||
/**
|
||||
* @return Was the money already subtracted?
|
||||
* @deprecated Use {@link #wasHandled()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isSubtracted() {
|
||||
return subtracted;
|
||||
return wasHandled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the money was subtracted from the account
|
||||
*
|
||||
* @param subtracted Was the money subtracted?
|
||||
* @deprecated Use {@link #setHandled(boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSubtracted(boolean subtracted) {
|
||||
this.subtracted = subtracted;
|
||||
setHandled(subtracted);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencyTransferEvent extends Event {
|
||||
public class CurrencyTransferEvent extends EconomicEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private BigDecimal amountSent;
|
||||
@ -24,7 +24,6 @@ public class CurrencyTransferEvent extends Event {
|
||||
private UUID partner;
|
||||
|
||||
private Direction direction;
|
||||
private boolean success = false;
|
||||
|
||||
public CurrencyTransferEvent(BigDecimal amount, Player initiator, UUID partner, Direction direction) {
|
||||
this(amount, amount, initiator, partner, direction);
|
||||
@ -126,18 +125,22 @@ public class CurrencyTransferEvent extends Event {
|
||||
|
||||
/**
|
||||
* @return If the currency has been successfully transferred
|
||||
* @deprecated Use {@link #wasHandled()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasBeenTransferred() {
|
||||
return success;
|
||||
return wasHandled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the transaction's outcome
|
||||
*
|
||||
* @param success If the currency has been successfully transferred
|
||||
* @deprecated Use {@link #setHandled(boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setTransferred(boolean success) {
|
||||
this.success = success;
|
||||
setHandled(success);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public abstract class EconomicEvent extends Event {
|
||||
|
||||
private boolean handled = false;
|
||||
|
||||
/**
|
||||
* Get whether or not this event was successfully handled by a listener
|
||||
*
|
||||
* @return Whether or not the amount was successfully handled
|
||||
*/
|
||||
public boolean wasHandled() {
|
||||
return handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not this event was successfully handled by a listener
|
||||
*
|
||||
* @param handled Whether or not the amount was successfully handled
|
||||
*/
|
||||
public void setHandled(boolean handled) {
|
||||
this.handled = handled;
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ public abstract class EconomyAdapter implements Listener {
|
||||
* @param event The CurrencyTransferEvent to process
|
||||
*/
|
||||
protected void processTransfer(CurrencyTransferEvent event) {
|
||||
if (event.hasBeenTransferred()) {
|
||||
if (event.wasHandled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -47,10 +47,10 @@ public abstract class EconomyAdapter implements Listener {
|
||||
if (!NameManager.isAdminShop(event.getSender())) {
|
||||
ChestShop.callEvent(currencySubtractEvent);
|
||||
} else {
|
||||
currencySubtractEvent.setSubtracted(true);
|
||||
currencySubtractEvent.setHandled(true);
|
||||
}
|
||||
|
||||
if (!currencySubtractEvent.isSubtracted()) {
|
||||
if (!currencySubtractEvent.wasHandled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -59,11 +59,11 @@ public abstract class EconomyAdapter implements Listener {
|
||||
if (!NameManager.isAdminShop(event.getReceiver())) {
|
||||
ChestShop.callEvent(currencyAddEvent);
|
||||
} else {
|
||||
currencyAddEvent.setAdded(true);
|
||||
currencyAddEvent.setHandled(true);
|
||||
}
|
||||
|
||||
if (currencyAddEvent.isAdded()) {
|
||||
event.setTransferred(true);
|
||||
if (currencyAddEvent.wasHandled()) {
|
||||
event.setHandled(true);
|
||||
} else {
|
||||
CurrencyAddEvent currencyResetEvent = new CurrencyAddEvent(
|
||||
currencySubtractEvent.getAmount(),
|
||||
|
@ -65,55 +65,59 @@ public class ReserveListener extends EconomyAdapter {
|
||||
|
||||
@EventHandler
|
||||
public void onAmountCheck(CurrencyAmountEvent event) {
|
||||
if (!provided() || !event.getAmount().equals(BigDecimal.ZERO)) {
|
||||
if (!provided() || event.wasHandled() || !event.getAmount().equals(BigDecimal.ZERO)) {
|
||||
return;
|
||||
}
|
||||
event.setAmount(economyAPI.getHoldings(event.getAccount(), event.getWorld().getName()));
|
||||
event.setHandled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencyCheck(CurrencyCheckEvent event) {
|
||||
if (!provided() || event.hasEnough()) {
|
||||
if (!provided() || event.wasHandled() || event.hasEnough()) {
|
||||
return;
|
||||
}
|
||||
event.hasEnough(economyAPI.hasHoldings(event.getAccount(),
|
||||
event.getAmount(),
|
||||
event.getWorld().getName()));
|
||||
event.setHandled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAccountCheck(AccountCheckEvent event) {
|
||||
if (!provided() || event.hasAccount()) {
|
||||
if (!provided() || event.wasHandled() || event.hasAccount()) {
|
||||
return;
|
||||
}
|
||||
event.hasAccount(economyAPI.hasAccount(event.getAccount()));
|
||||
event.setHandled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencyFormat(CurrencyFormatEvent event) {
|
||||
if (!event.getFormattedAmount().isEmpty()) {
|
||||
if ( event.wasHandled() || !event.getFormattedAmount().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (provided()) {
|
||||
event.setFormattedAmount(economyAPI.format(event.getAmount()));
|
||||
event.setHandled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencyAdd(CurrencyAddEvent event) {
|
||||
if (!provided() || event.isAdded()) {
|
||||
if (!provided() || event.wasHandled()) {
|
||||
return;
|
||||
}
|
||||
event.setAdded(economyAPI.addHoldings(event.getTarget(), event.getAmount(), event.getWorld().getName()));
|
||||
event.setHandled(economyAPI.addHoldings(event.getTarget(), event.getAmount(), event.getWorld().getName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencySubtraction(CurrencySubtractEvent event) {
|
||||
if (!provided() || event.isSubtracted()) {
|
||||
if (!provided() || event.wasHandled()) {
|
||||
return;
|
||||
}
|
||||
event.setSubtracted(economyAPI.removeHoldings(event.getTarget(), event.getAmount(), event.getWorld().getName()));
|
||||
event.setHandled(economyAPI.removeHoldings(event.getTarget(), event.getAmount(), event.getWorld().getName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -123,7 +127,7 @@ public class ReserveListener extends EconomyAdapter {
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
||||
if (event.getAccount() == null || !transactionCanFail() || event.canHold()) {
|
||||
if (event.getAccount() == null || event.wasHandled() || !transactionCanFail() || event.canHold()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -134,5 +138,6 @@ public class ReserveListener extends EconomyAdapter {
|
||||
}
|
||||
|
||||
event.canHold(economyAPI.canAddHoldings(event.getAccount(), event.getAmount(), world));
|
||||
event.setHandled(true);
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
@EventHandler
|
||||
public void onAmountCheck(CurrencyAmountEvent event) {
|
||||
if (!checkSetup() || !event.getAmount().equals(BigDecimal.ZERO)) {
|
||||
if (!checkSetup() || event.wasHandled() || !event.getAmount().equals(BigDecimal.ZERO)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -118,6 +118,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
if (balance > Double.MAX_VALUE) {
|
||||
balance = Double.MAX_VALUE;
|
||||
}
|
||||
event.setHandled(true);
|
||||
} else {
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "The server could not get the OfflinePlayer with the UUID " + event.getAccount() + " to check balance?");
|
||||
}
|
||||
@ -127,7 +128,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencyCheck(CurrencyCheckEvent event) {
|
||||
if (!checkSetup() || event.hasEnough()) {
|
||||
if (!checkSetup() || event.wasHandled() || event.hasEnough()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -136,6 +137,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
try {
|
||||
event.hasEnough(lastSeen != null && provider.has(lastSeen, world.getName(), event.getAmount().doubleValue()));
|
||||
event.setHandled(true);
|
||||
} catch (Exception e) {
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "Could not check if account of " + lastSeen.getUniqueId() + "/" + lastSeen.getName() + " has " + event.getAmount() + "." +
|
||||
"This is probably due to https://github.com/MilkBowl/Vault/issues/746 and has to be fixed in either Vault directly or your economy plugin." +
|
||||
@ -145,7 +147,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
@EventHandler
|
||||
public void onAccountCheck(AccountCheckEvent event) {
|
||||
if (!checkSetup() || event.hasAccount()) {
|
||||
if (!checkSetup() || event.wasHandled() || event.hasAccount()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -155,6 +157,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
try {
|
||||
event.hasAccount(lastSeen != null && provider.hasAccount(lastSeen, world.getName()));
|
||||
event.setHandled(true);
|
||||
} catch (Exception e) {
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "Could not check account balance of "+ lastSeen.getUniqueId() + "/" + lastSeen.getName() + "." +
|
||||
"This is probably due to https://github.com/MilkBowl/Vault/issues/746 and has to be fixed in either Vault directly or your economy plugin." +
|
||||
@ -164,17 +167,18 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencyFormat(CurrencyFormatEvent event) {
|
||||
if (!checkSetup() || !event.getFormattedAmount().isEmpty()) {
|
||||
if (!checkSetup() || event.wasHandled() || !event.getFormattedAmount().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String formatted = provider.format(event.getAmount().doubleValue());
|
||||
event.setFormattedAmount(formatted);
|
||||
event.setHandled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencyAdd(CurrencyAddEvent event) {
|
||||
if (!checkSetup() || event.isAdded()) {
|
||||
if (!checkSetup() || event.wasHandled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -185,7 +189,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
if (lastSeen != null) {
|
||||
try {
|
||||
EconomyResponse response = provider.depositPlayer(lastSeen, world.getName(), event.getAmount().doubleValue());
|
||||
event.setAdded(response.type == EconomyResponse.ResponseType.SUCCESS);
|
||||
event.setHandled(response.type == EconomyResponse.ResponseType.SUCCESS);
|
||||
} catch (Exception e) {
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "Could not add money to account of " + lastSeen.getUniqueId() + "/" + lastSeen.getName() + "." +
|
||||
"This is probably due to https://github.com/MilkBowl/Vault/issues/746 and has to be fixed in either Vault directly or your economy plugin." +
|
||||
@ -198,7 +202,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencySubtraction(CurrencySubtractEvent event) {
|
||||
if (!checkSetup() || event.isSubtracted()) {
|
||||
if (!checkSetup() || event.wasHandled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -209,7 +213,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
if (lastSeen != null) {
|
||||
try {
|
||||
EconomyResponse response = provider.withdrawPlayer(lastSeen, world.getName(), event.getAmount().doubleValue());
|
||||
event.setSubtracted(response.type == EconomyResponse.ResponseType.SUCCESS);
|
||||
event.setHandled(response.type == EconomyResponse.ResponseType.SUCCESS);
|
||||
} catch (Exception e) {
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "Could not add money to account of " + lastSeen.getUniqueId() + "/" + lastSeen.getName() + "." +
|
||||
"This is probably due to https://github.com/MilkBowl/Vault/issues/746 and has to be fixed in either Vault directly or your economy plugin." +
|
||||
@ -230,7 +234,7 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
@EventHandler
|
||||
public void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
||||
if (!checkSetup() || event.getAccount() == null || !transactionCanFail() || event.canHold()) {
|
||||
if (!checkSetup() || event.wasHandled() || event.getAccount() == null || !transactionCanFail() || event.canHold()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -254,10 +258,12 @@ public class VaultListener extends EconomyAdapter {
|
||||
|
||||
if (!response.transactionSuccess()) {
|
||||
event.canHold(false);
|
||||
event.setHandled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
provider.withdrawPlayer(lastSeen, world, event.getAmount().doubleValue());
|
||||
event.setHandled(true);
|
||||
} catch (Exception e) {
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "Could not check if account of " + lastSeen.getUniqueId() + "/" + lastSeen.getName() + " can hold " + event.getAmount() + "." +
|
||||
"This is probably due to https://github.com/MilkBowl/Vault/issues/746 and has to be fixed in either Vault directly or your economy plugin." +
|
||||
|
@ -27,7 +27,7 @@ public class ServerAccountCorrector implements Listener {
|
||||
Account account = NameManager.getServerEconomyAccount();
|
||||
target = account != null ? account.getUuid() : null;
|
||||
|
||||
event.setAdded(true);
|
||||
event.setHandled(true);
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
@ -35,7 +35,7 @@ public class ServerAccountCorrector implements Listener {
|
||||
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(event.getAmount(), target, event.getWorld());
|
||||
ChestShop.callEvent(currencyAddEvent);
|
||||
|
||||
event.setAdded(currencyAddEvent.isAdded());
|
||||
event.setHandled(currencyAddEvent.wasHandled());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@ -49,7 +49,7 @@ public class ServerAccountCorrector implements Listener {
|
||||
Account account = NameManager.getServerEconomyAccount();
|
||||
target = account != null ? account.getUuid() : null;
|
||||
|
||||
event.setSubtracted(true);
|
||||
event.setHandled(true);
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
@ -57,7 +57,7 @@ public class ServerAccountCorrector implements Listener {
|
||||
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(event.getAmount(), target, event.getWorld());
|
||||
ChestShop.callEvent(currencySubtractEvent);
|
||||
|
||||
event.setSubtracted(currencySubtractEvent.isSubtracted());
|
||||
event.setHandled(currencySubtractEvent.wasHandled());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@ -83,8 +83,7 @@ public class ServerAccountCorrector implements Listener {
|
||||
event.getDirection()
|
||||
);
|
||||
ChestShop.callEvent(currencyTransferEvent);
|
||||
event.setTransferred(currencyTransferEvent.hasBeenTransferred());
|
||||
return;
|
||||
event.setHandled(currencyTransferEvent.wasHandled());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
|
@ -37,7 +37,7 @@ public class TaxModule implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public static void onCurrencyTransfer(CurrencyTransferEvent event) {
|
||||
if (event.hasBeenTransferred()) {
|
||||
if (event.wasHandled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class EconomicModule implements Listener {
|
||||
event.getTransactionType() == BUY ? CurrencyTransferEvent.Direction.PARTNER : CurrencyTransferEvent.Direction.INITIATOR
|
||||
);
|
||||
ChestShop.callEvent(currencyTransferEvent);
|
||||
if (!currencyTransferEvent.hasBeenTransferred()) {
|
||||
if (!currencyTransferEvent.wasHandled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class CreationFeeGetter implements Listener {
|
||||
CurrencySubtractEvent subtractionEvent = new CurrencySubtractEvent(shopCreationPrice, player);
|
||||
ChestShop.callEvent(subtractionEvent);
|
||||
|
||||
if (!subtractionEvent.isSubtracted()) {
|
||||
if (!subtractionEvent.wasHandled()) {
|
||||
event.setOutcome(PreShopCreationEvent.CreationOutcome.NOT_ENOUGH_MONEY);
|
||||
event.setSignLines(new String[4]);
|
||||
return;
|
||||
|
@ -109,16 +109,16 @@ public class PartialTransactionModule implements Listener {
|
||||
|
||||
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), MathContext.DECIMAL128);
|
||||
|
||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(owner, client.getWorld());
|
||||
ChestShop.callEvent(currencyAmountEvent);
|
||||
|
||||
BigDecimal walletMoney = currencyAmountEvent.getAmount();
|
||||
|
||||
if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory())) {
|
||||
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(event.getExactPrice(), owner, client.getWorld());
|
||||
ChestShop.callEvent(currencyCheckEvent);
|
||||
|
||||
if (!currencyCheckEvent.hasEnough()) {
|
||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(owner, client.getWorld());
|
||||
ChestShop.callEvent(currencyAmountEvent);
|
||||
|
||||
BigDecimal walletMoney = currencyAmountEvent.getAmount();
|
||||
int amountAffordable = getAmountOfAffordableItems(walletMoney, pricePerItem);
|
||||
|
||||
if (amountAffordable < 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user