◆ __construct()
- Parameters
-
Inventory | $inventory | |
int | $slot | |
Item | $targetItem | |
| string[] | $achievements |
int | $transactionType | |
54 $this->slot = (int)
$slot;
56 $this->creationTime = microtime(
true);
◆ addAchievement()
addAchievement |
( |
string |
$achievementName | ) |
|
- Parameters
-
153 $this->achievements[] = $achievementName;
◆ addFailure()
◆ execute()
- Parameters
-
- Returns
- bool
Handles transaction execution. Returns whether transaction was successful or not.
Implements Transaction.
234 if(!$source->getServer()->allowInventoryCheats and !$source->isCreative()){
237 if($change === null){
242 if($change[
"out"] instanceof Item){
247 if($change[
"in"] instanceof Item){
248 if(!$source->getFloatingInventory()->contains($change[
"in"])){
255 if($change[
"out"] instanceof Item){
256 $source->getFloatingInventory()->addItem($change[
"out"]);
258 if($change[
"in"] instanceof Item){
259 $source->getFloatingInventory()->removeItem($change[
"in"]);
266 foreach($this->achievements as $achievement){
267 $source->awardAchievement($achievement);
◆ getAchievements()
◆ getChange()
Returns the change in inventory resulting from this transaction
- Returns
- array ("in" => items added to the inventory, "out" => items removed from the inventory) ]
184 $sourceItem = $this->
getInventory()->getItem($this->slot);
186 if($sourceItem->equals($this->targetItem,
true,
true,
true)){
190 }elseif($sourceItem->equals($this->targetItem)){
191 $item = clone $sourceItem;
192 $countDiff = $this->targetItem->getCount() - $sourceItem->getCount();
193 $item->setCount(abs($countDiff));
196 return [
"in" => null,
198 }elseif($countDiff > 0){
207 }elseif($sourceItem->getId() !==
Item::AIR and $this->targetItem->getId() ===
Item::AIR){
209 return [
"in" => null,
210 "out" => clone $sourceItem];
212 }elseif($sourceItem->getId() ===
Item::AIR and $this->targetItem->getId() !==
Item::AIR){
220 "out" => clone $sourceItem];
◆ getCreationTime()
◆ getFailures()
◆ getInventory()
◆ getSlot()
◆ getSourceItem()
- Returns
- Item
Implements Transaction.
93 return clone $this->inventory->getItem($this->slot);
◆ getTargetItem()
◆ getTransactionType()
◆ hasAchievements()
- Returns
- bool
146 return count($this->achievements) !== 0;
◆ sendSlotUpdate()
sendSlotUpdate |
( |
Player |
$source | ) |
|
- Parameters
-
Player | $source | Sends a slot update to inventory viewers For successful transactions, update non-source viewers (source does not need updating) For failed transactions, update the source (non-source viewers will see nothing anyway) |
164 if($this->
getInventory() instanceof TemporaryInventory){
168 if($this->wasSuccessful){
170 unset($targets[spl_object_hash($source)]);
172 $targets = [$source];
174 $this->inventory->sendSlot($this->slot, $targets);
◆ setSuccess()
setSuccess |
( |
|
$value = true | ) |
|
- Parameters
-
125 $this->wasSuccessful = $value;
◆ setTargetItem()
setTargetItem |
( |
Item |
$item | ) |
|
- Parameters
-
100 $this->targetItem = clone $item;
◆ succeeded()
◆ $achievements
◆ $creationTime
◆ $failures
◆ $inventory
◆ $slot
◆ $targetItem
◆ $transactionType
◆ $wasSuccessful
The documentation for this class was generated from the following file:
- src/pocketmine/inventory/BaseTransaction.php