mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 06:55:29 +00:00
Improved safe_var_dump(), Inventory::addItem() Inventory::removeItem() using argument unpacking
This commit is contained in:
parent
759d7e2545
commit
8e9da9c84e
@ -20,9 +20,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
function safe_var_dump(){
|
function safe_var_dump(...$params){
|
||||||
static $cnt = 0;
|
static $cnt = 0;
|
||||||
foreach(func_get_args() as $var){
|
foreach($params as $var){
|
||||||
switch(true){
|
switch(true){
|
||||||
case is_array($var):
|
case is_array($var):
|
||||||
echo str_repeat(" ", $cnt) . "array(" . count($var) . ") {" . PHP_EOL;
|
echo str_repeat(" ", $cnt) . "array(" . count($var) . ") {" . PHP_EOL;
|
||||||
|
@ -225,9 +225,8 @@ abstract class BaseInventory implements Inventory{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addItem(){
|
public function addItem(...$slots){
|
||||||
/** @var Item[] $slots */
|
/** @var Item[] $slots */
|
||||||
$slots = func_get_args();
|
|
||||||
foreach($slots as $i => $slot){
|
foreach($slots as $i => $slot){
|
||||||
$slots[$i] = clone $slot;
|
$slots[$i] = clone $slot;
|
||||||
}
|
}
|
||||||
@ -264,9 +263,8 @@ abstract class BaseInventory implements Inventory{
|
|||||||
return $slots;
|
return $slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeItem(){
|
public function removeItem(...$slots){
|
||||||
/** @var Item[] $slots */
|
/** @var Item[] $slots */
|
||||||
$slots = func_get_args();
|
|
||||||
for($i = 0; $i < $this->getSize(); ++$i){
|
for($i = 0; $i < $this->getSize(); ++$i){
|
||||||
$item = $this->getItem($i);
|
$item = $this->getItem($i);
|
||||||
if($item->getID() === Item::AIR){
|
if($item->getID() === Item::AIR){
|
||||||
|
@ -73,7 +73,7 @@ interface Inventory{
|
|||||||
*
|
*
|
||||||
* @return Item[]
|
* @return Item[]
|
||||||
*/
|
*/
|
||||||
public function addItem();
|
public function addItem(...$slots);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given Item can be added to the inventory
|
* Checks if a given Item can be added to the inventory
|
||||||
@ -92,7 +92,7 @@ interface Inventory{
|
|||||||
*
|
*
|
||||||
* @return Item[]
|
* @return Item[]
|
||||||
*/
|
*/
|
||||||
public function removeItem();
|
public function removeItem(...$slots);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Item[]
|
* @return Item[]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user