Merge branch 'php-5.6'

This commit is contained in:
Shoghi Cervantes 2014-08-27 21:24:52 +02:00
commit 812ae09a06
9 changed files with 74 additions and 79 deletions

View File

@ -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;
@ -263,8 +263,8 @@ namespace pocketmine {
$errors = 0; $errors = 0;
if(version_compare("5.5.0", PHP_VERSION) > 0){ if(version_compare("5.6.0", PHP_VERSION) > 0){
$logger->critical("Use PHP >= 5.5.0"); $logger->critical("You must use PHP >= 5.6");
++$errors; ++$errors;
} }

View File

@ -1489,7 +1489,7 @@ class Server{
Level::$COMPRESSION_LEVEL = $this->getProperty("chunk-sending.compression-level", 7); 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()); @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion());
} }

View File

@ -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){

View File

@ -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[]

View File

@ -393,63 +393,63 @@ class Item{
public static function init(){ public static function init(){
if(count(self::$list) === 0){ if(count(self::$list) === 0){
self::$list = array( self::$list = array(
self::SUGARCANE => new Sugarcane(), self::SUGARCANE => Sugarcane::class,
self::WHEAT_SEEDS => new WheatSeeds(), self::WHEAT_SEEDS => WheatSeeds::class,
self::PUMPKIN_SEEDS => new PumpkinSeeds(), self::PUMPKIN_SEEDS => PumpkinSeeds::class,
self::MELON_SEEDS => new MelonSeeds(), self::MELON_SEEDS => MelonSeeds::class,
self::MUSHROOM_STEW => new MushroomStew(), self::MUSHROOM_STEW => MushroomStew::class,
self::BEETROOT_SOUP => new BeetrootSoup(), self::BEETROOT_SOUP => BeetrootSoup::class,
self::CARROT => new Carrot(), self::CARROT => Carrot::class,
self::POTATO => new Potato(), self::POTATO => Potato::class,
self::BEETROOT_SEEDS => new BeetrootSeeds(), self::BEETROOT_SEEDS => BeetrootSeeds::class,
self::SIGN => new Sign(), self::SIGN => Sign::class,
self::WOODEN_DOOR => new WoodenDoor(), self::WOODEN_DOOR => WoodenDoor::class,
self::BUCKET => new Bucket(), self::BUCKET => Bucket::class,
self::IRON_DOOR => new IronDoor(), self::IRON_DOOR => IronDoor::class,
self::CAKE => new Cake(), self::CAKE => Cake::class,
self::BED => new Bed(), self::BED => Bed::class,
self::PAINTING => new Painting(), self::PAINTING => Painting::class,
self::COAL => new Coal(), self::COAL => Coal::class,
self::APPLE => new Apple(), self::APPLE => Apple::class,
self::SPAWN_EGG => new SpawnEgg(), self::SPAWN_EGG => SpawnEgg::class,
self::DIAMOND => new Diamond(), self::DIAMOND => Diamond::class,
self::STICK => new Stick(), self::STICK => Stick::class,
self::BOWL => new Bowl(), self::BOWL => Bowl::class,
self::FEATHER => new Feather(), self::FEATHER => Feather::class,
self::BRICK => new Brick(), self::BRICK => Brick::class,
self::IRON_SWORD => new IronSword(), self::IRON_SWORD => IronSword::class,
self::IRON_INGOT => new IronIngot(), self::IRON_INGOT => IronIngot::class,
self::GOLD_INGOT => new GoldIngot(), self::GOLD_INGOT => GoldIngot::class,
self::IRON_SHOVEL => new IronShovel(), self::IRON_SHOVEL => IronShovel::class,
self::IRON_PICKAXE => new IronPickaxe(), self::IRON_PICKAXE => IronPickaxe::class,
self::IRON_AXE => new IronAxe(), self::IRON_AXE => IronAxe::class,
self::IRON_HOE => new IronHoe(), self::IRON_HOE => IronHoe::class,
self::DIAMOND_SWORD => new DiamondSword(), self::DIAMOND_SWORD => DiamondSword::class,
self::DIAMOND_SHOVEL => new DiamondShovel(), self::DIAMOND_SHOVEL => DiamondShovel::class,
self::DIAMOND_PICKAXE => new DiamondPickaxe(), self::DIAMOND_PICKAXE => DiamondPickaxe::class,
self::DIAMOND_AXE => new DiamondAxe(), self::DIAMOND_AXE => DiamondAxe::class,
self::DIAMOND_HOE => new DiamondHoe(), self::DIAMOND_HOE => DiamondHoe::class,
self::GOLD_SWORD => new GoldSword(), self::GOLD_SWORD => GoldSword::class,
self::GOLD_SHOVEL => new GoldShovel(), self::GOLD_SHOVEL => GoldShovel::class,
self::GOLD_PICKAXE => new GoldPickaxe(), self::GOLD_PICKAXE => GoldPickaxe::class,
self::GOLD_AXE => new GoldAxe(), self::GOLD_AXE => GoldAxe::class,
self::GOLD_HOE => new GoldHoe(), self::GOLD_HOE => GoldHoe::class,
self::STONE_SWORD => new StoneSword(), self::STONE_SWORD => StoneSword::class,
self::STONE_SHOVEL => new StoneShovel(), self::STONE_SHOVEL => StoneShovel::class,
self::STONE_PICKAXE => new StonePickaxe(), self::STONE_PICKAXE => StonePickaxe::class,
self::STONE_AXE => new StoneAxe(), self::STONE_AXE => StoneAxe::class,
self::STONE_HOE => new StoneHoe(), self::STONE_HOE => StoneHoe::class,
self::WOODEN_SWORD => new WoodenSword(), self::WOODEN_SWORD => WoodenSword::class,
self::WOODEN_SHOVEL => new WoodenShovel(), self::WOODEN_SHOVEL => WoodenShovel::class,
self::WOODEN_PICKAXE => new WoodenPickaxe(), self::WOODEN_PICKAXE => WoodenPickaxe::class,
self::WOODEN_AXE => new WoodenAxe(), self::WOODEN_AXE => WoodenAxe::class,
self::WOODEN_HOE => new WoodenHoe(), self::WOODEN_HOE => WoodenHoe::class,
self::FLINT_STEEL => new FlintSteel(), self::FLINT_STEEL => FlintSteel::class,
self::SHEARS => new Shears(), self::SHEARS => Shears::class,
self::BOW => new Bow(), self::BOW => Bow::class,
); );
foreach(Block::$list as $id => $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){ public static function get($id, $meta = 0, $count = 1){
if(isset(self::$list[$id])){ if(isset(self::$list[$id])){
$item = clone self::$list[$id]; $class = self::$list[$id];
$item->setDamage($meta); if($id < 256){
$item->setCount($count); $item = new ItemBlock(new $class($meta), $meta, $count);
}else{
$item = new $class($meta, $count);
}
}else{ }else{
$item = new Item($id, $meta, $count); $item = new Item($id, $meta, $count);
} }

View File

@ -100,9 +100,7 @@ class ChunkRequestTask extends AsyncTask{
} }
} }
$biomeColors = $this->biomeColors; $biomeColors = pack("N*", ...$this->biomeColors);
array_unshift($biomeColors, "N*");
$biomeColors = call_user_func_array("pack", $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); $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);

View File

@ -122,9 +122,7 @@ class McRegion extends BaseLevelProvider{
} }
} }
$biomeColors = $chunk->getBiomeColorArray(); $biomeColors = pack("N*", ...$chunk->getBiomeColorArray());
array_unshift($biomeColors, "N*");
$biomeColors = call_user_func_array("pack", $biomeColors);
$ordered = zlib_encode( $ordered = zlib_encode(
Binary::writeLInt($x) . Binary::writeLInt($z) . Binary::writeLInt($x) . Binary::writeLInt($z) .

View File

@ -37,8 +37,6 @@ class IntArray extends NamedTag{
public function write(NBT $nbt){ public function write(NBT $nbt){
$nbt->putInt(count($this->value)); $nbt->putInt(count($this->value));
$ints = $this->value; $nbt->put(pack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", ...$this->value));
array_unshift($ints, $nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*");
$nbt->put(call_user_func_array("pack", $ints));
} }
} }

View File

@ -33,7 +33,7 @@ class MethodEventExecutor implements EventExecutor{
} }
public function execute(Listener $listener, Event $event){ public function execute(Listener $listener, Event $event){
call_user_func(array($listener, $this->method), $event); $listener->{$this->getMethod()}($event);
} }
public function getMethod(){ public function getMethod(){