mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 15:05:33 +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();
|
$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);
|
$pk->items[$i] = $this->getItem($i);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($target as $player){
|
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);
|
$this->close($player);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -431,7 +433,7 @@ abstract class BaseInventory implements Inventory{
|
|||||||
$pk->item = $this->getItem($index);
|
$pk->item = $this->getItem($index);
|
||||||
|
|
||||||
foreach($target as $player){
|
foreach($target as $player){
|
||||||
if(($id = $player->getWindowId($this)) === -1){
|
if(($id = $player->getWindowId($this)) === ContainerIds::NONE){
|
||||||
$this->close($player);
|
$this->close($player);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -52,35 +52,6 @@ class PlayerCursorInventory extends BaseInventory{
|
|||||||
return WindowTypes::INVENTORY; //This should never be spawned to clients
|
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.
|
* This override is here for documentation and code completion purposes only.
|
||||||
* @return Player
|
* @return Player
|
||||||
|
@ -128,18 +128,6 @@ class PlayerInventory extends BaseInventory{
|
|||||||
return $this->getItem($hotbarSlot);
|
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
|
* @deprecated
|
||||||
* @return int
|
* @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(){
|
public function sendCreativeContents(){
|
||||||
$pk = new InventoryContentPacket();
|
$pk = new InventoryContentPacket();
|
||||||
$pk->windowId = ContainerIds::CREATIVE;
|
$pk->windowId = ContainerIds::CREATIVE;
|
||||||
@ -454,35 +414,6 @@ class PlayerInventory extends BaseInventory{
|
|||||||
$this->getHolder()->dataPacket($pk);
|
$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.
|
* This override is here for documentation and code completion purposes only.
|
||||||
* @return Human|Player
|
* @return Human|Player
|
||||||
|
Loading…
x
Reference in New Issue
Block a user