All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.inventory.transaction.TradingTransaction Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.inventory.transaction;

import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.inventory.transaction.action.InventoryAction;
import cn.nukkit.inventory.transaction.action.SlotChangeAction;
import cn.nukkit.inventory.transaction.action.TradeAction;

import java.util.List;

@PowerNukkitXOnly
@Since("1.19.21-r1")
public class TradingTransaction extends InventoryTransaction {
    public TradingTransaction(Player source, List actions) {
        super(source, actions);
    }

    @Override
    public boolean canExecute() {
        for (var action : this.getActionList()) {
            if (action instanceof TradeAction tradeAction) {
                if (tradeAction.isValid(this.source)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean execute() {
        for (InventoryAction action : this.actions) {
            if (action instanceof SlotChangeAction slotChangeAction) {
                if (slotChangeAction.execute(this.source)) {
                    slotChangeAction.onExecuteSuccess(this.source);
                } else {
                    slotChangeAction.onExecuteFail(this.source);
                }
            }
        }
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy