Renaming "Level" -> "World" (#2907)

This has been a pain point for a long time due to the misleading nature of the name "level". It's also confusing when trying to do things like getting the XP level of the player or such, and also does not translate well to other languages.

This transition was already executed on the UI some time ago (language strings) and now it's time for the same change to occur on the API.

This will burn a lot of plugins, but they'll acclimatize. Despite the scary size of this PR, there isn't actually so many changes to make. Most of this came from renaming `Position->getLevel()` to `Position->getWorld()`, or cosmetic changes like changing variable names or doc comments.
This commit is contained in:
Dylan T
2019-05-07 14:47:28 +01:00
committed by GitHub
parent 427e334426
commit 3cd6e12e71
310 changed files with 1647 additions and 1628 deletions

View File

@ -23,10 +23,10 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe;
use pocketmine\level\ChunkListener;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\world\ChunkListener;
use pocketmine\world\format\Chunk;
use pocketmine\world\World;
use function spl_object_id;
use function strlen;
@ -43,15 +43,15 @@ class ChunkCache implements ChunkListener{
/**
* Fetches the ChunkCache instance for the given world. This lazily creates cache systems as needed.
*
* @param Level $world
* @param World $world
*
* @return ChunkCache
*/
public static function getInstance(Level $world) : self{
public static function getInstance(World $world) : self{
return self::$instances[spl_object_id($world)] ?? (self::$instances[spl_object_id($world)] = new self($world));
}
/** @var Level */
/** @var World */
private $world;
/** @var CompressBatchPromise[] */
@ -63,9 +63,9 @@ class ChunkCache implements ChunkListener{
private $misses = 0;
/**
* @param Level $world
* @param World $world
*/
private function __construct(Level $world){
private function __construct(World $world){
$this->world = $world;
}
@ -79,7 +79,7 @@ class ChunkCache implements ChunkListener{
*/
public function request(int $chunkX, int $chunkZ) : CompressBatchPromise{
$this->world->registerChunkListener($this, $chunkX, $chunkZ);
$chunkHash = Level::chunkHash($chunkX, $chunkZ);
$chunkHash = World::chunkHash($chunkX, $chunkZ);
if(isset($this->caches[$chunkHash])){
++$this->hits;
@ -113,7 +113,7 @@ class ChunkCache implements ChunkListener{
}
private function destroy(int $chunkX, int $chunkZ) : bool{
$chunkHash = Level::chunkHash($chunkX, $chunkZ);
$chunkHash = World::chunkHash($chunkX, $chunkZ);
$existing = $this->caches[$chunkHash] ?? null;
unset($this->caches[$chunkHash]);
@ -129,7 +129,7 @@ class ChunkCache implements ChunkListener{
* @throws \InvalidArgumentException
*/
private function restartPendingRequest(int $chunkX, int $chunkZ) : void{
$chunkHash = Level::chunkHash($chunkX, $chunkZ);
$chunkHash = World::chunkHash($chunkX, $chunkZ);
$existing = $this->caches[$chunkHash];
if($existing === null or $existing->hasResult()){
throw new \InvalidArgumentException("Restart can only be applied to unresolved promises");
@ -147,7 +147,7 @@ class ChunkCache implements ChunkListener{
* @throws \InvalidArgumentException
*/
private function destroyOrRestart(int $chunkX, int $chunkZ) : void{
$cache = $this->caches[Level::chunkHash($chunkX, $chunkZ)] ?? null;
$cache = $this->caches[World::chunkHash($chunkX, $chunkZ)] ?? null;
if($cache !== null){
if(!$cache->hasResult()){
//some requesters are waiting for this chunk, so their request needs to be fulfilled

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe;
use pocketmine\level\format\Chunk;
use pocketmine\world\format\Chunk;
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
use pocketmine\scheduler\AsyncTask;

View File

@ -30,7 +30,6 @@ use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\form\Form;
use pocketmine\GameMode;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\network\BadPacketException;
use pocketmine\network\mcpe\handler\DeathSessionHandler;
@ -70,6 +69,7 @@ use pocketmine\PlayerInfo;
use pocketmine\Server;
use pocketmine\timings\Timings;
use pocketmine\utils\BinaryDataException;
use pocketmine\world\Position;
use function bin2hex;
use function count;
use function get_class;
@ -761,18 +761,18 @@ class NetworkSession{
}
public function startUsingChunk(int $chunkX, int $chunkZ, bool $spawn = false) : void{
ChunkCache::getInstance($this->player->getLevel())->request($chunkX, $chunkZ)->onResolve(
ChunkCache::getInstance($this->player->getWorld())->request($chunkX, $chunkZ)->onResolve(
//this callback may be called synchronously or asynchronously, depending on whether the promise is resolved yet
function(CompressBatchPromise $promise) use($chunkX, $chunkZ, $spawn){
if(!$this->isConnected()){
return;
}
$this->player->level->timings->syncChunkSendTimer->startTiming();
$this->player->world->timings->syncChunkSendTimer->startTiming();
try{
$this->queueCompressed($promise);
foreach($this->player->getLevel()->getChunkEntities($chunkX, $chunkZ) as $entity){
foreach($this->player->getWorld()->getChunkEntities($chunkX, $chunkZ) as $entity){
if($entity !== $this->player and !$entity->isClosed() and !$entity->isFlaggedForDespawn()){
$entity->spawnTo($this->player);
}
@ -783,14 +783,14 @@ class NetworkSession{
$this->onTerrainReady();
}
}finally{
$this->player->level->timings->syncChunkSendTimer->stopTiming();
$this->player->world->timings->syncChunkSendTimer->stopTiming();
}
}
);
}
public function stopUsingChunk(int $chunkX, int $chunkZ) : void{
foreach($this->player->getLevel()->getChunkEntities($chunkX, $chunkZ) as $entity){
foreach($this->player->getWorld()->getChunkEntities($chunkX, $chunkZ) as $entity){
if($entity !== $this->player){
$entity->despawnFrom($this->player);
}

View File

@ -64,12 +64,12 @@ class PreSpawnSessionHandler extends SessionHandler{
$pk->seed = -1;
$pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly
$pk->worldGamemode = NetworkSession::getClientFriendlyGamemode($this->server->getGamemode());
$pk->difficulty = $this->player->getLevel()->getDifficulty();
$pk->difficulty = $this->player->getWorld()->getDifficulty();
$pk->spawnX = $spawnPosition->getFloorX();
$pk->spawnY = $spawnPosition->getFloorY();
$pk->spawnZ = $spawnPosition->getFloorZ();
$pk->hasAchievementsDisabled = true;
$pk->time = $this->player->getLevel()->getTime();
$pk->time = $this->player->getWorld()->getTime();
$pk->eduMode = false;
$pk->rainLevel = 0; //TODO: implement these properly
$pk->lightningLevel = 0;
@ -83,7 +83,7 @@ class PreSpawnSessionHandler extends SessionHandler{
$this->player->setImmobile(); //HACK: fix client-side falling pre-spawn
$this->player->getLevel()->sendTime($this->player);
$this->player->getWorld()->sendTime($this->player);
$this->session->syncAttributes($this->player, true);
$this->session->syncAvailableCommands();

View File

@ -281,7 +281,7 @@ class SimpleSessionHandler extends SessionHandler{
}
private function handleUseItemOnEntityTransaction(UseItemOnEntityTransactionData $data) : bool{
$target = $this->player->getLevel()->getEntity($data->getEntityRuntimeId());
$target = $this->player->getWorld()->getEntity($data->getEntityRuntimeId());
if($target === null){
return false;
}
@ -448,7 +448,7 @@ class SimpleSessionHandler extends SessionHandler{
return false;
}
$block = $this->player->getLevel()->getBlock($pos);
$block = $this->player->getWorld()->getBlock($pos);
try{
$offset = 0;
$nbt = (new NetworkNbtSerializer())->read($packet->namedtag, $offset, 512)->getTag();
@ -466,7 +466,7 @@ class SimpleSessionHandler extends SessionHandler{
try{
if(!$block->updateText($this->player, $text)){
$this->player->getLevel()->sendBlocks([$this->player], [$block]);
$this->player->getWorld()->sendBlocks([$this->player], [$block]);
}
}catch(\UnexpectedValueException $e){
throw new BadPacketException($e->getMessage(), 0, $e);
@ -509,7 +509,7 @@ class SimpleSessionHandler extends SessionHandler{
}
public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{
$block = $this->player->getLevel()->getBlockAt($packet->x, $packet->y, $packet->z);
$block = $this->player->getWorld()->getBlockAt($packet->x, $packet->y, $packet->z);
if($block instanceof ItemFrame and $block->getFramedItem() !== null){
return $this->player->attackBlock(new Vector3($packet->x, $packet->y, $packet->z), $block->getFacing());
}
@ -588,7 +588,7 @@ class SimpleSessionHandler extends SessionHandler{
}
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
$this->player->getLevel()->broadcastPacketToViewers($this->player->asVector3(), $packet);
$this->player->getWorld()->broadcastPacketToViewers($this->player->asVector3(), $packet);
return true;
}