mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 05:40:01 +00:00
Remove Inventory->sendSlot() and Inventory->sendContents()
the plan is to remove this from inventory entirely and use listeners for this.
This commit is contained in:
parent
7ba1dd3242
commit
8551d1e282
@ -116,7 +116,9 @@ abstract class BaseInventory implements Inventory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($send){
|
if($send){
|
||||||
$this->sendContents($this->getViewers());
|
foreach($this->getViewers() as $viewer){
|
||||||
|
$viewer->getNetworkSession()->syncInventoryContents($this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,35 +382,10 @@ abstract class BaseInventory implements Inventory{
|
|||||||
$listener->onSlotChange($this, $index);
|
$listener->onSlotChange($this, $index);
|
||||||
}
|
}
|
||||||
if($send){
|
if($send){
|
||||||
$this->sendSlot($index, $this->getViewers());
|
foreach($this->viewers as $viewer){
|
||||||
|
$viewer->getNetworkSession()->syncInventorySlot($this, $index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Player|Player[] $target
|
|
||||||
*/
|
|
||||||
public function sendContents($target) : void{
|
|
||||||
if($target instanceof Player){
|
|
||||||
$target = [$target];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($target as $player){
|
|
||||||
$player->getNetworkSession()->syncInventoryContents($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $index
|
|
||||||
* @param Player|Player[] $target
|
|
||||||
*/
|
|
||||||
public function sendSlot(int $index, $target) : void{
|
|
||||||
if($target instanceof Player){
|
|
||||||
$target = [$target];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($target as $player){
|
|
||||||
$player->getNetworkSession()->syncInventorySlot($this, $index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function slotExists(int $slot) : bool{
|
public function slotExists(int $slot) : bool{
|
||||||
|
@ -49,7 +49,7 @@ abstract class ContainerInventory extends BaseInventory{
|
|||||||
$who->sendDataPacket(ContainerOpenPacket::blockInv($windowId, $this->getNetworkType(), $holder->getFloorX(), $holder->getFloorY(), $holder->getFloorZ()));
|
$who->sendDataPacket(ContainerOpenPacket::blockInv($windowId, $this->getNetworkType(), $holder->getFloorX(), $holder->getFloorY(), $holder->getFloorZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->sendContents($who);
|
$who->getNetworkSession()->syncInventoryContents($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onClose(Player $who) : void{
|
protected function onClose(Player $who) : void{
|
||||||
|
@ -107,17 +107,6 @@ interface Inventory{
|
|||||||
*/
|
*/
|
||||||
public function setContents(array $items, bool $send = true) : void;
|
public function setContents(array $items, bool $send = true) : void;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Player|Player[] $target
|
|
||||||
*/
|
|
||||||
public function sendContents($target) : void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $index
|
|
||||||
* @param Player|Player[] $target
|
|
||||||
*/
|
|
||||||
public function sendSlot(int $index, $target) : void;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the inventory contains any Item with the same material data.
|
* Checks if the inventory contains any Item with the same material data.
|
||||||
* It will check id, amount, and metadata (if not null)
|
* It will check id, amount, and metadata (if not null)
|
||||||
|
@ -137,12 +137,12 @@ class PlayerInventory extends BaseInventory{
|
|||||||
if(!is_array($target)){
|
if(!is_array($target)){
|
||||||
$target->sendDataPacket($pk);
|
$target->sendDataPacket($pk);
|
||||||
if($target === $this->getHolder()){
|
if($target === $this->getHolder()){
|
||||||
$this->sendSlot($this->getHeldItemIndex(), $target);
|
$target->getNetworkSession()->syncInventorySlot($this, $this->getHeldItemIndex());
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$this->getHolder()->getWorld()->getServer()->broadcastPacket($target, $pk);
|
$this->getHolder()->getWorld()->getServer()->broadcastPacket($target, $pk);
|
||||||
if(in_array($this->getHolder(), $target, true)){
|
if(in_array($this->getHolder(), $target, true)){
|
||||||
$this->sendSlot($this->getHeldItemIndex(), $this->getHolder());
|
$target->getNetworkSession()->syncInventorySlot($this, $this->getHeldItemIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ class InventoryTransaction{
|
|||||||
|
|
||||||
protected function sendInventories() : void{
|
protected function sendInventories() : void{
|
||||||
foreach($this->inventories as $inventory){
|
foreach($this->inventories as $inventory){
|
||||||
$inventory->sendContents($this->source);
|
$this->source->getNetworkSession()->syncInventoryContents($inventory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ use pocketmine\inventory\Inventory;
|
|||||||
use pocketmine\inventory\transaction\InventoryTransaction;
|
use pocketmine\inventory\transaction\InventoryTransaction;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use function spl_object_id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an action causing a change in an inventory slot.
|
* Represents an action causing a change in an inventory slot.
|
||||||
@ -110,9 +109,9 @@ class SlotChangeAction extends InventoryAction{
|
|||||||
* @param Player $source
|
* @param Player $source
|
||||||
*/
|
*/
|
||||||
public function onExecuteSuccess(Player $source) : void{
|
public function onExecuteSuccess(Player $source) : void{
|
||||||
$viewers = $this->inventory->getViewers();
|
foreach($this->inventory->getViewers() as $viewer){
|
||||||
unset($viewers[spl_object_id($source)]);
|
$viewer->getNetworkSession()->syncInventorySlot($this->inventory, $this->inventorySlot);
|
||||||
$this->inventory->sendSlot($this->inventorySlot, $viewers);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,6 +120,6 @@ class SlotChangeAction extends InventoryAction{
|
|||||||
* @param Player $source
|
* @param Player $source
|
||||||
*/
|
*/
|
||||||
public function onExecuteFail(Player $source) : void{
|
public function onExecuteFail(Player $source) : void{
|
||||||
$this->inventory->sendSlot($this->inventorySlot, $source);
|
$source->getNetworkSession()->syncInventorySlot($this->inventory, $this->inventorySlot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ class InGameSessionHandler extends SessionHandler{
|
|||||||
switch($data->getActionType()){
|
switch($data->getActionType()){
|
||||||
case ReleaseItemTransactionData::ACTION_RELEASE:
|
case ReleaseItemTransactionData::ACTION_RELEASE:
|
||||||
if(!$this->player->releaseHeldItem()){
|
if(!$this->player->releaseHeldItem()){
|
||||||
$this->player->getInventory()->sendContents($this->player);
|
$this->session->syncInventoryContents($this->player->getInventory());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case ReleaseItemTransactionData::ACTION_CONSUME:
|
case ReleaseItemTransactionData::ACTION_CONSUME:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user