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