@EventHandler (ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onShowCasePlayerSellEvent(ShowCasePlayerSellEvent scpse) {
if (scpse.verify()) {
Player player = scpse.getPlayer();
int amount = scpse.getQuantity();
BuyShop shop = scpse.getShop();
double price = shop.getPrice();
Throwable cause = null;
// fix amount
if (amount > (shop.getMaxAmount()-shop.getAmount()) && !shop.isUnlimited()) {
scpse.setQuantity(shop.getMaxAmount()-shop.getAmount());
amount = scpse.getQuantity();
}
// insufficient permission
if (!scs.canUse(player)) {
cause = new InsufficientPermissionException(Term.ERROR_INSUFFICIENT_PERMISSION.get());
}
// insufficient money
else if (!scs.getBalanceHandler().hasEnough(shop.getOwner(), amount*price)) {
cause = new InsufficientResourcesException(Term.ERROR_INSUFFICIENT_MONEY_COSTUMER.get());
}
if (cause != null) {
scpse.setCancelled(true);