Merge branch 'master' into mcpe-1.6-master

This commit is contained in:
Dylan K. Taylor 2018-08-26 18:06:18 +01:00
commit fa77a4fa58
15 changed files with 75 additions and 70 deletions

View File

@ -1897,7 +1897,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->gamemode = $this->server->getGamemode(); $this->gamemode = $this->server->getGamemode();
} }
$this->setAllowFlight($this->isCreative()); $this->allowFlight = $this->isCreative();
$this->keepMovement = $this->isSpectator() || $this->allowMovementCheats(); $this->keepMovement = $this->isSpectator() || $this->allowMovementCheats();
if($this->isOp()){ if($this->isOp()){
$this->setRemoveFormat(false); $this->setRemoveFormat(false);

View File

@ -1140,18 +1140,12 @@ class Server{
* Searches all levels for the entity with the specified ID. * Searches all levels for the entity with the specified ID.
* Useful for tracking entities across multiple worlds without needing strong references. * Useful for tracking entities across multiple worlds without needing strong references.
* *
* @param int $entityId * @param int $entityId
* @param Level|null $expectedLevel Level to look in first for the target
* *
* @return Entity|null * @return Entity|null
*/ */
public function findEntity(int $entityId, Level $expectedLevel = null){ public function findEntity(int $entityId){
$levels = $this->levels; foreach($this->levels as $level){
if($expectedLevel !== null){
array_unshift($levels, $expectedLevel);
}
foreach($levels as $level){
assert(!$level->isClosed()); assert(!$level->isClosed());
if(($entity = $level->getEntity($entityId)) instanceof Entity){ if(($entity = $level->getEntity($entityId)) instanceof Entity){
return $entity; return $entity;

View File

@ -302,9 +302,9 @@ class SimpleCommandMap implements CommandMap{
} }
$targets = []; $targets = [];
$bad = [];
$recursive = [];
$bad = "";
$recursive = "";
foreach($commandStrings as $commandString){ foreach($commandStrings as $commandString){
$args = explode(" ", $commandString); $args = explode(" ", $commandString);
$commandName = ""; $commandName = "";
@ -312,27 +312,21 @@ class SimpleCommandMap implements CommandMap{
if($command === null){ if($command === null){
if(strlen($bad) > 0){ $bad[] = $commandString;
$bad .= ", ";
}
$bad .= $commandString;
}elseif($commandName === $alias){ }elseif($commandName === $alias){
if($recursive !== ""){ $recursive[] = $commandString;
$recursive .= ", ";
}
$recursive .= $commandString;
}else{ }else{
$targets[] = $commandString; $targets[] = $commandString;
} }
} }
if($recursive !== ""){ if(!empty($recursive)){
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.recursive", [$alias, $recursive])); $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.recursive", [$alias, implode(", ", $recursive)]));
continue; continue;
} }
if(strlen($bad) > 0){ if(!empty($bad)){
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.notFound", [$alias, $bad])); $this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.notFound", [$alias, implode(", ", $bad)]));
continue; continue;
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\TranslationContainer;
use pocketmine\plugin\Plugin;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
class PluginsCommand extends VanillaCommand{ class PluginsCommand extends VanillaCommand{
@ -43,20 +44,12 @@ class PluginsCommand extends VanillaCommand{
if(!$this->testPermission($sender)){ if(!$this->testPermission($sender)){
return true; return true;
} }
$this->sendPluginList($sender);
$list = array_map(function(Plugin $plugin) : string{
return ($plugin->isEnabled() ? TextFormat::GREEN : TextFormat::RED) . $plugin->getDescription()->getFullName();
}, $sender->getServer()->getPluginManager()->getPlugins());
$sender->sendMessage(new TranslationContainer("pocketmine.command.plugins.success", [count($list), implode(TextFormat::WHITE . ", ", $list)]));
return true; return true;
} }
private function sendPluginList(CommandSender $sender){
$list = "";
foreach(($plugins = $sender->getServer()->getPluginManager()->getPlugins()) as $plugin){
if(strlen($list) > 0){
$list .= TextFormat::WHITE . ", ";
}
$list .= $plugin->isEnabled() ? TextFormat::GREEN : TextFormat::RED;
$list .= $plugin->getDescription()->getFullName();
}
$sender->sendMessage(new TranslationContainer("pocketmine.command.plugins.success", [count($plugins), $list]));
}
} }

View File

@ -49,7 +49,7 @@ class TeleportCommand extends VanillaCommand{
} }
$args = array_values(array_filter($args, function($arg){ $args = array_values(array_filter($args, function($arg){
return strlen($arg) > 0; return $arg !== "";
})); }));
if(count($args) < 1 or count($args) > 6){ if(count($args) < 1 or count($args) > 6){
throw new InvalidCommandSyntaxException(); throw new InvalidCommandSyntaxException();

View File

@ -731,7 +731,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public function getOwningEntity() : ?Entity{ public function getOwningEntity() : ?Entity{
$eid = $this->getOwningEntityId(); $eid = $this->getOwningEntityId();
if($eid !== null){ if($eid !== null){
return $this->server->findEntity($eid, $this->level); return $this->server->findEntity($eid);
} }
return null; return null;
@ -771,7 +771,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public function getTargetEntity() : ?Entity{ public function getTargetEntity() : ?Entity{
$eid = $this->getTargetEntityId(); $eid = $this->getTargetEntityId();
if($eid !== null){ if($eid !== null){
return $this->server->findEntity($eid, $this->level); return $this->server->findEntity($eid);
} }
return null; return null;
@ -1010,8 +1010,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$hasUpdate = true; $hasUpdate = true;
} }
if($this->isOnFire()){ if($this->isOnFire() and $this->doOnFireTick($tickDiff)){
$hasUpdate = ($hasUpdate || $this->doOnFireTick($tickDiff)); $hasUpdate = true;
} }
if($this->noDamageTicks > 0){ if($this->noDamageTicks > 0){

View File

@ -650,7 +650,9 @@ abstract class Living extends Entity implements Damageable{
$hasUpdate = parent::entityBaseTick($tickDiff); $hasUpdate = parent::entityBaseTick($tickDiff);
$this->doEffectsTick($tickDiff); if($this->doEffectsTick($tickDiff)){
$hasUpdate = true;
}
if($this->isAlive()){ if($this->isAlive()){
if($this->isInsideOfSolid()){ if($this->isInsideOfSolid()){
@ -659,12 +661,8 @@ abstract class Living extends Entity implements Damageable{
$this->attack($ev); $this->attack($ev);
} }
if(!$this->canBreathe()){ if($this->doAirSupplyTick($tickDiff)){
$this->setBreathing(false); $hasUpdate = true;
$this->doAirSupplyTick($tickDiff);
}elseif(!$this->isBreathing()){
$this->setBreathing(true);
$this->setAirSupplyTicks($this->getMaxAirSupplyTicks());
} }
} }
@ -677,7 +675,7 @@ abstract class Living extends Entity implements Damageable{
return $hasUpdate; return $hasUpdate;
} }
protected function doEffectsTick(int $tickDiff = 1) : void{ protected function doEffectsTick(int $tickDiff = 1) : bool{
foreach($this->effects as $instance){ foreach($this->effects as $instance){
$type = $instance->getType(); $type = $instance->getType();
if($type->canTick($instance)){ if($type->canTick($instance)){
@ -688,25 +686,47 @@ abstract class Living extends Entity implements Damageable{
$this->removeEffect($instance->getId()); $this->removeEffect($instance->getId());
} }
} }
return !empty($this->effects);
} }
/** /**
* Ticks the entity's air supply when it cannot breathe. * Ticks the entity's air supply, consuming it when underwater and regenerating it when out of water.
*
* @param int $tickDiff * @param int $tickDiff
*
* @return bool
*/ */
protected function doAirSupplyTick(int $tickDiff) : void{ protected function doAirSupplyTick(int $tickDiff) : bool{
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or $ticks = $this->getAirSupplyTicks();
lcg_value() <= (1 / ($respirationLevel + 1)) $oldTicks = $ticks;
){ if(!$this->canBreathe()){
$ticks = $this->getAirSupplyTicks() - $tickDiff; $this->setBreathing(false);
if($ticks <= -20){ if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or
$this->setAirSupplyTicks(0); lcg_value() <= (1 / ($respirationLevel + 1))
$this->onAirExpired(); ){
}else{ $ticks -= $tickDiff;
$this->setAirSupplyTicks($ticks); if($ticks <= -20){
$ticks = 0;
$this->onAirExpired();
}
}
}elseif(!$this->isBreathing()){
if($ticks < ($max = $this->getMaxAirSupplyTicks())){
$ticks += $tickDiff * 5;
}
if($ticks >= $max){
$ticks = $max;
$this->setBreathing(true);
} }
} }
if($ticks !== $oldTicks){
$this->setAirSupplyTicks($ticks);
}
return $ticks !== $oldTicks;
} }
/** /**

View File

@ -147,7 +147,7 @@ class ExperienceOrb extends Entity{
return null; return null;
} }
$entity = $this->server->findEntity($this->targetPlayerRuntimeId, $this->level); $entity = $this->server->findEntity($this->targetPlayerRuntimeId);
if($entity instanceof Human){ if($entity instanceof Human){
return $entity; return $entity;
} }

View File

@ -51,6 +51,6 @@ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{
* @return Entity|null * @return Entity|null
*/ */
public function getChild() : ?Entity{ public function getChild() : ?Entity{
return $this->getEntity()->getLevel()->getServer()->findEntity($this->childEntityEid, $this->getEntity()->getLevel()); return $this->getEntity()->getLevel()->getServer()->findEntity($this->childEntityEid);
} }
} }

View File

@ -69,7 +69,7 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
* @return Entity|null * @return Entity|null
*/ */
public function getDamager() : ?Entity{ public function getDamager() : ?Entity{
return $this->getEntity()->getLevel()->getServer()->findEntity($this->damagerEntityId, $this->getEntity()->getLevel()); return $this->getEntity()->getLevel()->getServer()->findEntity($this->damagerEntityId);
} }
/** /**

View File

@ -246,6 +246,8 @@ class ItemFactory{
self::registerItem(new Item(Item::NAUTILUS_SHELL, 0, "Nautilus Shell")); self::registerItem(new Item(Item::NAUTILUS_SHELL, 0, "Nautilus Shell"));
self::registerItem(new GoldenAppleEnchanted()); self::registerItem(new GoldenAppleEnchanted());
self::registerItem(new Item(Item::HEART_OF_THE_SEA, 0, "Heart of the Sea")); self::registerItem(new Item(Item::HEART_OF_THE_SEA, 0, "Heart of the Sea"));
self::registerItem(new Item(Item::TURTLE_SHELL_PIECE, 0, "Scute"));
//TODO: TURTLE_HELMET
//TODO: COMPOUND //TODO: COMPOUND
//TODO: RECORD_13 //TODO: RECORD_13

View File

@ -235,6 +235,8 @@ interface ItemIds extends BlockIds{
public const NAUTILUS_SHELL = 465; public const NAUTILUS_SHELL = 465;
public const APPLEENCHANTED = 466, APPLE_ENCHANTED = 466, ENCHANTED_GOLDEN_APPLE = 466; public const APPLEENCHANTED = 466, APPLE_ENCHANTED = 466, ENCHANTED_GOLDEN_APPLE = 466;
public const HEART_OF_THE_SEA = 467; public const HEART_OF_THE_SEA = 467;
public const TURTLE_SHELL_PIECE = 468;
public const TURTLE_HELMET = 469;
public const COMPOUND = 499; public const COMPOUND = 499;
public const RECORD_13 = 500; public const RECORD_13 = 500;

View File

@ -377,7 +377,7 @@ class LevelDB extends BaseLevelProvider{
/** @var CompoundTag[] $entities */ /** @var CompoundTag[] $entities */
$entities = []; $entities = [];
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and strlen($entityData) > 0){ if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and $entityData !== ""){
$entities = $nbt->read($entityData, true); $entities = $nbt->read($entityData, true);
if(!is_array($entities)){ if(!is_array($entities)){
$entities = [$entities]; $entities = [$entities];
@ -392,7 +392,7 @@ class LevelDB extends BaseLevelProvider{
} }
$tiles = []; $tiles = [];
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and strlen($tileData) > 0){ if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and $tileData !== ""){
$tiles = $nbt->read($tileData, true); $tiles = $nbt->read($tileData, true);
if(!is_array($tiles)){ if(!is_array($tiles)){
$tiles = [$tiles]; $tiles = [$tiles];
@ -402,7 +402,7 @@ class LevelDB extends BaseLevelProvider{
//TODO: extra data should be converted into blockstorage layers (first they need to be implemented!) //TODO: extra data should be converted into blockstorage layers (first they need to be implemented!)
/* /*
$extraData = []; $extraData = [];
if(($extraRawData = $this->db->get($index . self::TAG_BLOCK_EXTRA_DATA)) !== false and strlen($extraRawData) > 0){ if(($extraRawData = $this->db->get($index . self::TAG_BLOCK_EXTRA_DATA)) !== false and $extraRawData !== ""){
$binaryStream->setBuffer($extraRawData, 0); $binaryStream->setBuffer($extraRawData, 0);
$count = $binaryStream->getLInt(); $count = $binaryStream->getLInt();
for($i = 0; $i < $count; ++$i){ for($i = 0; $i < $count; ++$i){

View File

@ -177,7 +177,7 @@ class RCONInstance extends Thread{
$disconnect[$id] = $sock; $disconnect[$id] = $sock;
break; break;
} }
if(strlen($payload) > 0){ if($payload !== ""){
$this->cmd = ltrim($payload); $this->cmd = ltrim($payload);
$this->synchronized(function(){ $this->synchronized(function(){
$this->notifier->wakeupSleeper(); $this->notifier->wakeupSleeper();

View File

@ -168,7 +168,7 @@ class BanEntry{
} }
$expire = trim(array_shift($str)); $expire = trim(array_shift($str));
if(strtolower($expire) !== "forever" and strlen($expire) > 0){ if($expire !== "" and strtolower($expire) !== "forever"){
$entry->setExpires(self::parseDate($expire)); $entry->setExpires(self::parseDate($expire));
} }
if(empty($str)){ if(empty($str)){