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