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 5df6716..6384d22 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java @@ -99,6 +99,13 @@ public class CurrencyAddEvent extends EconomicEvent { return target; } + /** + * @param target Account from which the currency is subtracted + */ + public void setTarget(UUID target) { + this.target = target; + } + public HandlerList getHandlers() { return handlers; } 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 81288d1..f8cd738 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java @@ -76,6 +76,13 @@ public class CurrencyAmountEvent extends EconomicEvent { return account; } + /** + * @param account Account that is checked + */ + public void setAccount(UUID account) { + this.account = account; + } + public HandlerList getHandlers() { return handlers; } 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 647eaad..0c522a7 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java @@ -103,9 +103,7 @@ public class CurrencyCheckEvent extends EconomicEvent { * Sets the account name * * @param account Account name - * @deprecated The account should not be changed! */ - @Deprecated public void setAccount(UUID account) { this.account = 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 c5dfab9..d3eedff 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.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; @@ -100,6 +99,13 @@ public class CurrencySubtractEvent extends EconomicEvent { return target; } + /** + * @param target Account from which the currency is subtracted + */ + public void setTarget(UUID target) { + this.target = target; + } + public HandlerList getHandlers() { return handlers; } 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 737fa33..a9de422 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java @@ -3,7 +3,6 @@ package com.Acrobot.ChestShop.Events.Economy; import com.Acrobot.ChestShop.Events.TransactionEvent; import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import java.math.BigDecimal; @@ -182,6 +181,15 @@ public class CurrencyTransferEvent extends EconomicEvent { return partner; } + /** + * Set the partner of the transaction + * + * @param partner the new partner of this transaction + */ + public void setPartner(UUID partner) { + this.partner = partner; + } + /** * @return The world in which the transaction occurs */ 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 9413511..67839d7 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java @@ -1,6 +1,5 @@ package com.Acrobot.ChestShop.Listeners.Economy; -import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Database.Account; import com.Acrobot.ChestShop.Events.Economy.*; import com.Acrobot.ChestShop.UUIDs.NameManager; @@ -27,15 +26,12 @@ public class ServerAccountCorrector implements Listener { Account account = NameManager.getServerEconomyAccount(); target = account != null ? account.getUuid() : null; - event.setHandled(true); if (target == null) { + event.setHandled(true); return; } - CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(event.getAmount(), target, event.getWorld()); - ChestShop.callEvent(currencyAddEvent); - - event.setHandled(currencyAddEvent.wasHandled()); + event.setTarget(target); } @EventHandler(priority = EventPriority.LOWEST) @@ -49,15 +45,12 @@ public class ServerAccountCorrector implements Listener { Account account = NameManager.getServerEconomyAccount(); target = account != null ? account.getUuid() : null; - event.setHandled(true); if (target == null) { + event.setHandled(true); return; } - CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(event.getAmount(), target, event.getWorld()); - ChestShop.callEvent(currencySubtractEvent); - - event.setHandled(currencySubtractEvent.wasHandled()); + event.setTarget(target); } @EventHandler(priority = EventPriority.LOWEST) @@ -75,16 +68,7 @@ public class ServerAccountCorrector implements Listener { return; } - CurrencyTransferEvent currencyTransferEvent = new CurrencyTransferEvent( - event.getAmountSent(), - event.getAmountReceived(), - event.getInitiator(), - partner, - event.getDirection(), - event.getTransactionEvent() - ); - ChestShop.callEvent(currencyTransferEvent); - event.setHandled(currencyTransferEvent.wasHandled()); + event.setPartner(partner); } @EventHandler(priority = EventPriority.LOWEST) @@ -103,10 +87,7 @@ public class ServerAccountCorrector implements Listener { return; } - CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(event.getAmount(), target, event.getWorld()); - ChestShop.callEvent(currencyCheckEvent); - - event.hasEnough(currencyCheckEvent.hasEnough()); + event.setAccount(target); } @EventHandler(priority = EventPriority.LOWEST) @@ -117,8 +98,15 @@ public class ServerAccountCorrector implements Listener { return; } - event.canHold(true); - event.setAccount(null); + Account account = NameManager.getServerEconomyAccount(); + target = account != null ? account.getUuid() : null; + + if (target == null) { + event.canHold(true); + return; + } + + event.setAccount(target); } @EventHandler(priority = EventPriority.LOWEST) @@ -137,9 +125,6 @@ public class ServerAccountCorrector implements Listener { return; } - CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(target, event.getWorld()); - ChestShop.callEvent(currencyAmountEvent); - - event.setAmount(currencyAmountEvent.getAmount()); + event.setAccount(target); } }