From 759d7e2545cd614af3793f859afa382647c3c5c4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 27 Aug 2014 12:21:01 +0200 Subject: [PATCH 1/4] Initial PHP 5.6 features support --- src/pocketmine/PocketMine.php | 4 ++-- src/pocketmine/level/format/anvil/ChunkRequestTask.php | 4 +--- src/pocketmine/level/format/mcregion/McRegion.php | 4 +--- src/pocketmine/nbt/tag/IntArray.php | 4 +--- src/pocketmine/plugin/MethodEventExecutor.php | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 5b1d820a2..cca5cb1ad 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -263,8 +263,8 @@ namespace pocketmine { $errors = 0; - if(version_compare("5.5.0", PHP_VERSION) > 0){ - $logger->critical("Use PHP >= 5.5.0"); + if(version_compare("5.6.0", PHP_VERSION) > 0){ + $logger->critical("You must use PHP >= 5.6"); ++$errors; } diff --git a/src/pocketmine/level/format/anvil/ChunkRequestTask.php b/src/pocketmine/level/format/anvil/ChunkRequestTask.php index cd2661f7f..1d5c8007e 100644 --- a/src/pocketmine/level/format/anvil/ChunkRequestTask.php +++ b/src/pocketmine/level/format/anvil/ChunkRequestTask.php @@ -100,9 +100,7 @@ class ChunkRequestTask extends AsyncTask{ } } - $biomeColors = $this->biomeColors; - array_unshift($biomeColors, "N*"); - $biomeColors = call_user_func_array("pack", $biomeColors); + $biomeColors = pack("N*", ...$this->biomeColors); $ordered = zlib_encode(Binary::writeLInt($this->chunkX) . Binary::writeLInt($this->chunkZ) . $orderedIds . $orderedData . $orderedSkyLight . $orderedLight . $this->biomeIds . $biomeColors . $this->tiles, ZLIB_ENCODING_DEFLATE, $this->compressionLevel); diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index 5e6a4e19f..5cca7ba47 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -122,9 +122,7 @@ class McRegion extends BaseLevelProvider{ } } - $biomeColors = $chunk->getBiomeColorArray(); - array_unshift($biomeColors, "N*"); - $biomeColors = call_user_func_array("pack", $biomeColors); + $biomeColors = pack("N*", ...$chunk->getBiomeColorArray()); $ordered = zlib_encode( Binary::writeLInt($x) . Binary::writeLInt($z) . diff --git a/src/pocketmine/nbt/tag/IntArray.php b/src/pocketmine/nbt/tag/IntArray.php index b79b904fe..ad39c148b 100644 --- a/src/pocketmine/nbt/tag/IntArray.php +++ b/src/pocketmine/nbt/tag/IntArray.php @@ -37,8 +37,6 @@ class IntArray extends NamedTag{ public function write(NBT $nbt){ $nbt->putInt(count($this->value)); - $ints = $this->value; - array_unshift($ints, $nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*"); - $nbt->put(call_user_func_array("pack", $ints)); + $nbt->put(pack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", ...$this->value)); } } \ No newline at end of file diff --git a/src/pocketmine/plugin/MethodEventExecutor.php b/src/pocketmine/plugin/MethodEventExecutor.php index 43137db8e..a47239572 100644 --- a/src/pocketmine/plugin/MethodEventExecutor.php +++ b/src/pocketmine/plugin/MethodEventExecutor.php @@ -33,7 +33,7 @@ class MethodEventExecutor implements EventExecutor{ } public function execute(Listener $listener, Event $event){ - call_user_func(array($listener, $this->method), $event); + $listener->{$this->getMethod()}($event); } public function getMethod(){ From 8e9da9c84e9f9259456337150131b6d5fd4e3e20 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 27 Aug 2014 12:29:04 +0200 Subject: [PATCH 2/4] Improved safe_var_dump(), Inventory::addItem() Inventory::removeItem() using argument unpacking --- src/pocketmine/PocketMine.php | 4 ++-- src/pocketmine/inventory/BaseInventory.php | 6 ++---- src/pocketmine/inventory/Inventory.php | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index cca5cb1ad..4095c090f 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -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; diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index e36dfbdd7..75583b7d5 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -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){ diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index a61baae75..fc3fc3bbf 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -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[] From 8f66d03d990562bd3091cddc50cb8952074f72cb Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 27 Aug 2014 12:43:54 +0200 Subject: [PATCH 3/4] Improved Item::get() --- src/pocketmine/item/Item.php | 119 ++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 1fbd56b51..d1ba1b96a 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -393,63 +393,63 @@ class Item{ public static function init(){ if(count(self::$list) === 0){ self::$list = array( - self::SUGARCANE => new Sugarcane(), - self::WHEAT_SEEDS => new WheatSeeds(), - self::PUMPKIN_SEEDS => new PumpkinSeeds(), - self::MELON_SEEDS => new MelonSeeds(), - self::MUSHROOM_STEW => new MushroomStew(), - self::BEETROOT_SOUP => new BeetrootSoup(), - self::CARROT => new Carrot(), - self::POTATO => new Potato(), - self::BEETROOT_SEEDS => new BeetrootSeeds(), - self::SIGN => new Sign(), - self::WOODEN_DOOR => new WoodenDoor(), - self::BUCKET => new Bucket(), - self::IRON_DOOR => new IronDoor(), - self::CAKE => new Cake(), - self::BED => new Bed(), - self::PAINTING => new Painting(), - self::COAL => new Coal(), - self::APPLE => new Apple(), - self::SPAWN_EGG => new SpawnEgg(), - self::DIAMOND => new Diamond(), - self::STICK => new Stick(), - self::BOWL => new Bowl(), - self::FEATHER => new Feather(), - self::BRICK => new Brick(), - self::IRON_SWORD => new IronSword(), - self::IRON_INGOT => new IronIngot(), - self::GOLD_INGOT => new GoldIngot(), - self::IRON_SHOVEL => new IronShovel(), - self::IRON_PICKAXE => new IronPickaxe(), - self::IRON_AXE => new IronAxe(), - self::IRON_HOE => new IronHoe(), - self::DIAMOND_SWORD => new DiamondSword(), - self::DIAMOND_SHOVEL => new DiamondShovel(), - self::DIAMOND_PICKAXE => new DiamondPickaxe(), - self::DIAMOND_AXE => new DiamondAxe(), - self::DIAMOND_HOE => new DiamondHoe(), - self::GOLD_SWORD => new GoldSword(), - self::GOLD_SHOVEL => new GoldShovel(), - self::GOLD_PICKAXE => new GoldPickaxe(), - self::GOLD_AXE => new GoldAxe(), - self::GOLD_HOE => new GoldHoe(), - self::STONE_SWORD => new StoneSword(), - self::STONE_SHOVEL => new StoneShovel(), - self::STONE_PICKAXE => new StonePickaxe(), - self::STONE_AXE => new StoneAxe(), - self::STONE_HOE => new StoneHoe(), - self::WOODEN_SWORD => new WoodenSword(), - self::WOODEN_SHOVEL => new WoodenShovel(), - self::WOODEN_PICKAXE => new WoodenPickaxe(), - self::WOODEN_AXE => new WoodenAxe(), - self::WOODEN_HOE => new WoodenHoe(), - self::FLINT_STEEL => new FlintSteel(), - self::SHEARS => new Shears(), - self::BOW => new Bow(), + self::SUGARCANE => Sugarcane::class, + self::WHEAT_SEEDS => WheatSeeds::class, + self::PUMPKIN_SEEDS => PumpkinSeeds::class, + self::MELON_SEEDS => MelonSeeds::class, + self::MUSHROOM_STEW => MushroomStew::class, + self::BEETROOT_SOUP => BeetrootSoup::class, + self::CARROT => Carrot::class, + self::POTATO => Potato::class, + self::BEETROOT_SEEDS => BeetrootSeeds::class, + self::SIGN => Sign::class, + self::WOODEN_DOOR => WoodenDoor::class, + self::BUCKET => Bucket::class, + self::IRON_DOOR => IronDoor::class, + self::CAKE => Cake::class, + self::BED => Bed::class, + self::PAINTING => Painting::class, + self::COAL => Coal::class, + self::APPLE => Apple::class, + self::SPAWN_EGG => SpawnEgg::class, + self::DIAMOND => Diamond::class, + self::STICK => Stick::class, + self::BOWL => Bowl::class, + self::FEATHER => Feather::class, + self::BRICK => Brick::class, + self::IRON_SWORD => IronSword::class, + self::IRON_INGOT => IronIngot::class, + self::GOLD_INGOT => GoldIngot::class, + self::IRON_SHOVEL => IronShovel::class, + self::IRON_PICKAXE => IronPickaxe::class, + self::IRON_AXE => IronAxe::class, + self::IRON_HOE => IronHoe::class, + self::DIAMOND_SWORD => DiamondSword::class, + self::DIAMOND_SHOVEL => DiamondShovel::class, + self::DIAMOND_PICKAXE => DiamondPickaxe::class, + self::DIAMOND_AXE => DiamondAxe::class, + self::DIAMOND_HOE => DiamondHoe::class, + self::GOLD_SWORD => GoldSword::class, + self::GOLD_SHOVEL => GoldShovel::class, + self::GOLD_PICKAXE => GoldPickaxe::class, + self::GOLD_AXE => GoldAxe::class, + self::GOLD_HOE => GoldHoe::class, + self::STONE_SWORD => StoneSword::class, + self::STONE_SHOVEL => StoneShovel::class, + self::STONE_PICKAXE => StonePickaxe::class, + self::STONE_AXE => StoneAxe::class, + self::STONE_HOE => StoneHoe::class, + self::WOODEN_SWORD => WoodenSword::class, + self::WOODEN_SHOVEL => WoodenShovel::class, + self::WOODEN_PICKAXE => WoodenPickaxe::class, + self::WOODEN_AXE => WoodenAxe::class, + self::WOODEN_HOE => WoodenHoe::class, + self::FLINT_STEEL => FlintSteel::class, + self::SHEARS => Shears::class, + self::BOW => Bow::class, ); foreach(Block::$list as $id => $class){ - self::$list[$id] = new ItemBlock(new $class); + self::$list[$id] = $class; } } @@ -457,9 +457,12 @@ class Item{ public static function get($id, $meta = 0, $count = 1){ if(isset(self::$list[$id])){ - $item = clone self::$list[$id]; - $item->setDamage($meta); - $item->setCount($count); + $class = self::$list[$id]; + if($id < 256){ + $item = new ItemBlock(new $class($meta), $meta, $count); + }else{ + $item = new $class($meta, $count); + } }else{ $item = new Item($id, $meta, $count); } From e6234c4c4d0697bb5e13f6d0ce22898fa2774519 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 27 Aug 2014 12:45:14 +0200 Subject: [PATCH 4/4] Removed cli_set_process_title() check --- src/pocketmine/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index fc0521186..cd927edde 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1489,7 +1489,7 @@ class Server{ Level::$COMPRESSION_LEVEL = $this->getProperty("chunk-sending.compression-level", 7); - if(defined("pocketmine\\DEBUG") and \pocketmine\DEBUG >= 0 and function_exists("cli_set_process_title")){ + if(defined("pocketmine\\DEBUG") and \pocketmine\DEBUG >= 0){ @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion()); }