ChestShop-3/src/main/java/com/Acrobot/ChestShop/Events/TransactionEvent.java
Phoenix616 f0bc277566 Move to BigDecimal in all events and use the CurrencyTransferEvent
Also add tax bypass permissions (#204, ChestShop.notax.buy/sell). When buying with that permission the buyer does not have to pay the tax (the seller will still get the reduced amount), when selling the seller will get the full amount instead of one lowered by the tax.
The permissions of the shop owner play no role due to there not being a good way of checking offline player permissions and it being a bit non-obvious for the buying/selling player if a shop would be with or without tax. This way all that gets changed is the amount the player pays/receives and not the shop owner (and the player should know their permissions/rank already)

The transfer event was necessary in order to correctly resolve who triggered the transaction. Economy adapters are now required to implement a listener for each of the events. It's also recommended that economy adapters that support transfers directly use that instead of passing it through subtract and add with the processTransfer method.
2019-04-25 18:44:22 +01:00

180 lines
4.2 KiB
Java

package com.Acrobot.ChestShop.Events;
import com.Acrobot.ChestShop.Database.Account;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.math.BigDecimal;
/**
* Represents a state after transaction has occured
*
* @author Acrobot
*/
public class TransactionEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final TransactionType type;
private final Inventory ownerInventory;
private final Inventory clientInventory;
private final Player client;
private final Account ownerAccount;
private final ItemStack[] stock;
private final BigDecimal exactPrice;
private final Sign sign;
private boolean cancelled = false;
public TransactionEvent(PreTransactionEvent event, Sign sign) {
this.type = event.getTransactionType();
this.ownerInventory = event.getOwnerInventory();
this.clientInventory = event.getClientInventory();
this.client = event.getClient();
this.ownerAccount = event.getOwnerAccount();
this.stock = event.getStock();
this.exactPrice = event.getExactPrice();
this.sign = sign;
}
public TransactionEvent(TransactionType type, Inventory ownerInventory, Inventory clientInventory, Player client, Account ownerAccount, ItemStack[] stock, BigDecimal exactPrice, Sign sign) {
this.type = type;
this.ownerInventory = ownerInventory;
this.clientInventory = clientInventory;
this.client = client;
this.ownerAccount = ownerAccount;
this.stock = stock;
this.exactPrice = exactPrice;
this.sign = sign;
}
/**
* @deprecated Use {@link #TransactionEvent(TransactionType, Inventory, Inventory, Player, Account, ItemStack[], BigDecimal, Sign)}
*/
@Deprecated
public TransactionEvent(TransactionType type, Inventory ownerInventory, Inventory clientInventory, Player client, Account ownerAccount, ItemStack[] stock, double price, Sign sign) {
this(type, ownerInventory, clientInventory, client, ownerAccount, stock, BigDecimal.valueOf(price), sign);
}
/**
* @return Type of the transaction
*/
public TransactionType getTransactionType() {
return type;
}
/**
* @return Owner's inventory
*/
public Inventory getOwnerInventory() {
return ownerInventory;
}
/**
* @return Client's inventory
*/
public Inventory getClientInventory() {
return clientInventory;
}
/**
* @return Shop's client
*/
public Player getClient() {
return client;
}
/**
* @return Account of the shop's owner
*/
public Account getOwnerAccount() {
return ownerAccount;
}
/**
* @return Shop's owner
* @deprecated Use {@link #getOwnerAccount}
*/
@Deprecated
public OfflinePlayer getOwner() {
return Bukkit.getOfflinePlayer(ownerAccount.getUuid());
}
/**
* @return Stock available
*/
public ItemStack[] getStock() {
return stock;
}
/**
* Get the exact total price
*
* @return Exact total price of the items
*/
public BigDecimal getExactPrice() {
return exactPrice;
}
/**
* Get the total price
*
* @return Total price of the items
* @deprecated Use {@link #getExactPrice()}
*/
@Deprecated
public double getPrice() {
return exactPrice.doubleValue();
}
/**
* @return Shop's sign
*/
public Sign getSign() {
return sign;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
/**
* Possible transaction types
*/
public enum TransactionType {
BUY,
SELL
}
}