1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Transaction event issues

Discussion in 'Help' started by esh123cookie, May 6, 2020.

  1. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    104
    GitHub:
    esh123cookie
    For some reason, this code doesn't do anything. No internal error nor does it do anything. How do I fix it?

    Thats the code ->

    public function onInventoryTransaction(InventoryTransactionEvent $event) : void{
    $transaction = $event->getTransaction();
    $player = $transaction->getSource();
    $inv = $player->getInventory();
    if (count($actions) === 2) {
    $actions = array_values($transaction->getActions());
    foreach ($actions as $i => $action) {
    $item = Item::get(373, 0, 1);
    $eye = Item::get(351, 0, 1);
    $stick = Item::get(280, 0, 1);
    if ($action instanceof SlotChangeAction && ($otherAction = $actions[($i + 1) % 2]) instanceof SlotChangeAction && ($itemClickedWith = $action->getTargetItem())->getId() === $eye && ($itemClicked = $action->getSourceItem())->getId() !== ItemIds::AIR) {
    $player->sendMessage("Unable to craft this item");
    $mergeSuccessful = false;
    if ($itemClicked == $eye) {
    $inv->removeItem($item);
    $action->getInventory()->setItem($action->getSlot(), $stick);
    $player->sendMessage("§7(§a!§7) §aYou have crafted an awkward potion");
    $mergeSuccessful = true;
    }
    if ($mergeSuccessful) {
    $event->setCancelled();
    $otherAction->getInventory()->setItem($otherAction->getSlot(), Item::get(Item::AIR));
    }
    }
    }
    }
    }
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Try adding some log messages to see how far the code reaches $this->getLogger()->info("got here");
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.