mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Remove redundant duplicated code for sendContents() and sendSlot()
This commit is contained in:
parent
136ab1dba1
commit
1323d89139
@ -403,12 +403,14 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
|
||||
$pk = new InventoryContentPacket();
|
||||
for($i = 0; $i < $this->getSize(); ++$i){
|
||||
|
||||
//Using getSize() here allows PlayerInventory to report that it's 4 slots smaller than it actually is (armor hack)
|
||||
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
||||
$pk->items[$i] = $this->getItem($i);
|
||||
}
|
||||
|
||||
foreach($target as $player){
|
||||
if(($id = $player->getWindowId($this)) === -1 or $player->spawned !== true){
|
||||
if(($id = $player->getWindowId($this)) === ContainerIds::NONE or $player->spawned !== true){
|
||||
$this->close($player);
|
||||
continue;
|
||||
}
|
||||
@ -431,7 +433,7 @@ abstract class BaseInventory implements Inventory{
|
||||
$pk->item = $this->getItem($index);
|
||||
|
||||
foreach($target as $player){
|
||||
if(($id = $player->getWindowId($this)) === -1){
|
||||
if(($id = $player->getWindowId($this)) === ContainerIds::NONE){
|
||||
$this->close($player);
|
||||
continue;
|
||||
}
|
||||
|
@ -52,35 +52,6 @@ class PlayerCursorInventory extends BaseInventory{
|
||||
return WindowTypes::INVENTORY; //This should never be spawned to clients
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param Player|Player[] $target
|
||||
*/
|
||||
public function sendSlot(int $index, $target){
|
||||
if($target instanceof Player){
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new InventorySlotPacket();
|
||||
$pk->inventorySlot = $index;
|
||||
$pk->item = $this->getItem($index);
|
||||
|
||||
foreach($target as $player){
|
||||
if($player === $this->getHolder()){
|
||||
/** @var Player $player */
|
||||
$pk->windowId = ContainerIds::CURSOR;
|
||||
$player->dataPacket(clone $pk);
|
||||
}else{
|
||||
if(($id = $player->getWindowId($this)) === ContainerIds::NONE){
|
||||
$this->close($player);
|
||||
continue;
|
||||
}
|
||||
$pk->windowId = $id;
|
||||
$player->dataPacket(clone $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Player
|
||||
|
@ -128,18 +128,6 @@ class PlayerInventory extends BaseInventory{
|
||||
return $this->getItem($hotbarSlot);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is only used when sending inventory contents. Since we now assume that all hotbar slots are the same as
|
||||
* their respective inventory slots, we simply fill this wil 0-8.
|
||||
*/
|
||||
private function sendHotbar(){
|
||||
$pk = new PlayerHotbarPacket();
|
||||
$pk->windowId = ContainerIds::INVENTORY;
|
||||
$pk->selectedHotbarSlot = $this->getHeldItemIndex();
|
||||
$pk->slots = range(0, $this->getHotbarSize() - 1, 1);
|
||||
$this->getHolder()->dataPacket($pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return int
|
||||
@ -413,34 +401,6 @@ class PlayerInventory extends BaseInventory{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player|Player[] $target
|
||||
*/
|
||||
public function sendContents($target){
|
||||
if($target instanceof Player){
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new InventoryContentPacket();
|
||||
|
||||
for($i = 0; $i < $this->getSize(); ++$i){ //Do not send armor by error here
|
||||
$pk->items[$i] = $this->getItem($i);
|
||||
}
|
||||
|
||||
foreach($target as $player){
|
||||
if(($id = $player->getWindowId($this)) === -1 or $player->spawned !== true){
|
||||
$this->close($player);
|
||||
continue;
|
||||
}
|
||||
$pk->windowId = $id;
|
||||
$player->dataPacket(clone $pk);
|
||||
|
||||
if($player === $this->getHolder()){
|
||||
$this->sendHotbar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function sendCreativeContents(){
|
||||
$pk = new InventoryContentPacket();
|
||||
$pk->windowId = ContainerIds::CREATIVE;
|
||||
@ -454,35 +414,6 @@ class PlayerInventory extends BaseInventory{
|
||||
$this->getHolder()->dataPacket($pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param Player|Player[] $target
|
||||
*/
|
||||
public function sendSlot(int $index, $target){
|
||||
if($target instanceof Player){
|
||||
$target = [$target];
|
||||
}
|
||||
|
||||
$pk = new InventorySlotPacket();
|
||||
$pk->inventorySlot = $index;
|
||||
$pk->item = $this->getItem($index);
|
||||
|
||||
foreach($target as $player){
|
||||
if($player === $this->getHolder()){
|
||||
/** @var Player $player */
|
||||
$pk->windowId = ContainerIds::INVENTORY;
|
||||
$player->dataPacket(clone $pk);
|
||||
}else{
|
||||
if(($id = $player->getWindowId($this)) === -1){
|
||||
$this->close($player);
|
||||
continue;
|
||||
}
|
||||
$pk->windowId = $id;
|
||||
$player->dataPacket(clone $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Human|Player
|
||||
|
Loading…
x
Reference in New Issue
Block a user