コード例 #1
0
 public function execute(Player $source) : bool
 {
     $droppedItem = $this->getTargetItem();
     if (!$source->getServer()->getAllowInvCheats() and !$source->isCreative()) {
         if (!$source->getFloatingInventory()->contains($droppedItem)) {
             return false;
         }
         $source->getFloatingInventory()->removeItem($droppedItem);
     }
     $source->dropItem($droppedItem);
     return true;
 }
コード例 #2
0
 public function onRename(Player $player, Item $resultItem) : bool
 {
     if (!$resultItem->deepEquals($this->getItem(self::TARGET), true, false, true)) {
         //Item does not match target item. Everything must match except the tags.
         return false;
     }
     if ($player->getExpLevel() < $resultItem->getRepairCost()) {
         //Not enough exp
         return false;
     }
     $player->setExpLevel($player->getExpLevel() - $resultItem->getRepairCost());
     $this->clearAll();
     if (!$player->getServer()->allowInventoryCheats and !$player->isCreative()) {
         if (!$player->getFloatingInventory()->canAddItem($resultItem)) {
             return false;
         }
         $player->getFloatingInventory()->addItem($resultItem);
     }
     return true;
 }
コード例 #3
0
 /**
  * @param Player $source
  * @return bool
  *
  * Handles transaction execution. Returns whether transaction was successful or not.
  */
 public function execute(Player $source) : bool
 {
     if ($this->getInventory()->processSlotChange($this)) {
         //This means that the transaction should be handled the normal way
         if (!$source->getServer()->getAllowInvCheats() and !$source->isCreative()) {
             $change = $this->getChange();
             if ($change === null) {
                 //No changes to make, ignore this transaction
                 return true;
             }
             /* Verify that we have the required items */
             if ($change["out"] instanceof Item) {
                 if (!$this->getInventory()->slotContains($this->getSlot(), $change["out"])) {
                     return false;
                 }
             }
             if ($change["in"] instanceof Item) {
                 if (!$source->getFloatingInventory()->contains($change["in"])) {
                     return false;
                 }
             }
             /* All checks passed, make changes to floating inventory
              * This will not be reached unless all requirements are met */
             if ($change["out"] instanceof Item) {
                 $source->getFloatingInventory()->addItem($change["out"]);
             }
             if ($change["in"] instanceof Item) {
                 $source->getFloatingInventory()->removeItem($change["in"]);
             }
         }
         $this->getInventory()->setItem($this->getSlot(), $this->getTargetItem(), false);
     }
     /* Process transaction achievements, like getting iron from a furnace */
     foreach ($this->achievements as $achievement) {
         $source->awardAchievement($achievement);
     }
     return true;
 }