本文整理汇总了PHP中pocketmine\inventory\BaseTransaction类的典型用法代码示例。如果您正苦于以下问题:PHP BaseTransaction类的具体用法?PHP BaseTransaction怎么用?PHP BaseTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseTransaction类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleDataPacket
//.........这里部分代码省略.........
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if (Item::getCreativeItemIndex($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem() === $transaction->getTargetItem() and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 8) {
if ($this->currentTransaction !== null) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
$achievements = [];
示例2: handleDataPacket
//.........这里部分代码省略.........
break;
case ProtocolInfo::CONTAINER_CLOSE_PACKET:
if ($this->spawned === false or $packet->windowid === 0) {
break;
}
$this->craftingType = 0;
$this->currentTransaction = null;
if (isset($this->windowIndex[$packet->windowid])) {
$this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowid], $this));
$this->removeWindow($this->windowIndex[$packet->windowid]);
} else {
unset($this->windowIndex[$packet->windowid]);
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if (Item::getCreativeItemIndex($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem()->equals($transaction->getTargetItem(), true) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 8) {
if ($this->currentTransaction instanceof SimpleTransactionGroup) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
if ($this->currentTransaction->execute()) {
示例3: handleDataPacket
//.........这里部分代码省略.........
break;
case ProtocolInfo::CONTAINER_CLOSE_PACKET:
if ($this->spawned === false or $packet->windowid === 0) {
break;
}
$this->craftingType = 0;
$this->currentTransaction = null;
if (isset($this->windowIndex[$packet->windowid])) {
$this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowid], $this));
$this->removeWindow($this->windowIndex[$packet->windowid]);
} else {
unset($this->windowIndex[$packet->windowid]);
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if ($this->getCreativeBlock($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === 0x78) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem()->equals($transaction->getTargetItem(), true) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 0.5) {
if ($this->currentTransaction instanceof SimpleTransactionGroup) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
if (!$this->currentTransaction->execute()) {
示例4: handleDataPacket
//.........这里部分代码省略.........
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if (Item::getCreativeItemIndex($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
/** @var $packet \pocketmine\network\protocol\ContainerSetSlotPacket */
if ($inv instanceof EnchantInventory and $packet->item->hasEnchantments()) {
$inv->onEnchant($this, $inv->getItem($packet->slot), $packet->item);
}
if ($inv instanceof AnvilInventory) {
if ($packet->slot == 2) {
if ($packet->item->getId() != Item::AIR) {
$this->anvilItem = $packet->item;
} elseif ($this->anvilItem != null) {
if (!$inv->onRename($this->anvilItem, $this)) {
break;
//maybe cheating!
}
$this->anvilItem = null;
}
}
}
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem()->deepEquals($transaction->getTargetItem()) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
示例5: handleDataPacket
//.........这里部分代码省略.........
case Item::STONE_PICKAXE:
case Item::GOLD_PICKAXE:
case Item::IRON_PICKAXE:
case Item::DIAMOND_PICKAXE:
$this->awardAchievement("buildBetterPickaxe");
break;
case Item::WOODEN_SWORD:
$this->awardAchievement("buildSword");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
break;
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if (Item::getCreativeItemIndex($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem()->deepEquals($transaction->getTargetItem()) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 8) {
if ($this->currentTransaction !== null) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
$achievements = [];