mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-17 07:45:09 +01:00
Fix transaction message getting sent twice when server economy account is set
This was due to the ServerAccountCorrector calling the economy events another time with the new account. Directly setting the new account is the far better approach and has been adjusted for all currency events.
This commit is contained in:
parent
0fcbcbbb11
commit
a413e86ccf
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user