diff --git a/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java b/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java index 3770df7..e78cb15 100644 --- a/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java +++ b/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java @@ -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(); } /** diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/AccountCheckEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/AccountCheckEvent.java index 2307ce5..8e9b978 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/AccountCheckEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/AccountCheckEvent.java @@ -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; diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java index 0c02f20..5df6716 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java @@ -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); } /** diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java index 923a5ae..81288d1 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java @@ -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; diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java index aaef505..647eaad 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java @@ -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; diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyFormatEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyFormatEvent.java index dbebf0a..a3b0c92 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyFormatEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyFormatEvent.java @@ -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; diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java index d645823..c9213e4 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java @@ -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; diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java index 90ffa27..c5dfab9 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java @@ -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); } /** diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java index 9ce107b..f287e5e 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java @@ -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); } /** diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/EconomicEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/EconomicEvent.java new file mode 100644 index 0000000..90c235e --- /dev/null +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/EconomicEvent.java @@ -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; + } +} diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/EconomyAdapter.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/EconomyAdapter.java index f50c259..5c069b0 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/EconomyAdapter.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/EconomyAdapter.java @@ -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(), diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/ReserveListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/ReserveListener.java index 6377235..ab4fbf0 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/ReserveListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/ReserveListener.java @@ -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); } } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java index 98bd9b1..01091e8 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java @@ -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." + diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java index c917287..08fb5a7 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java @@ -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) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java index 81f7ef1..d3b0480 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java @@ -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; } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java index 904f379..c4b8eb4 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java @@ -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); } } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/CreationFeeGetter.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/CreationFeeGetter.java index a8147bf..754c89d 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/CreationFeeGetter.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/CreationFeeGetter.java @@ -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; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java index daa9771..40502b8 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java @@ -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) {