diff --git a/src/event/world/WorldDisplayNameChangeEvent.php b/src/event/world/WorldDisplayNameChangeEvent.php new file mode 100644 index 000000000..a3067a1c5 --- /dev/null +++ b/src/event/world/WorldDisplayNameChangeEvent.php @@ -0,0 +1,48 @@ +oldName; + } + + public function getNewName() : string{ + return $this->newName; + } +} diff --git a/src/world/World.php b/src/world/World.php index 52766612f..f499ccb22 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -51,6 +51,7 @@ use pocketmine\event\world\ChunkLoadEvent; use pocketmine\event\world\ChunkPopulateEvent; use pocketmine\event\world\ChunkUnloadEvent; use pocketmine\event\world\SpawnChangeEvent; +use pocketmine\event\world\WorldDisplayNameChangeEvent; use pocketmine\event\world\WorldParticleEvent; use pocketmine\event\world\WorldSaveEvent; use pocketmine\event\world\WorldSoundEvent; @@ -2971,6 +2972,16 @@ class World implements ChunkManager{ return $this->displayName; } + /** + * Sets the World display name. + */ + public function setDisplayName(string $name) : void{ + (new WorldDisplayNameChangeEvent($this, $this->displayName, $name))->call(); + + $this->displayName = $name; + $this->provider->getWorldData()->setName($name); + } + /** * Returns the World folder name. This will not change at runtime and will be unique to a world per runtime. */ diff --git a/src/world/format/io/WorldData.php b/src/world/format/io/WorldData.php index ba60c1ab8..18ac9b1be 100644 --- a/src/world/format/io/WorldData.php +++ b/src/world/format/io/WorldData.php @@ -34,6 +34,8 @@ interface WorldData{ public function getName() : string; + public function setName(string $value) : void; + /** * Returns the generator name */ diff --git a/src/world/format/io/data/BaseNbtWorldData.php b/src/world/format/io/data/BaseNbtWorldData.php index ecd9b483c..cb3f3eb4b 100644 --- a/src/world/format/io/data/BaseNbtWorldData.php +++ b/src/world/format/io/data/BaseNbtWorldData.php @@ -116,6 +116,10 @@ abstract class BaseNbtWorldData implements WorldData{ return $this->compoundTag->getString(self::TAG_LEVEL_NAME); } + public function setName(string $value) : void{ + $this->compoundTag->setString(self::TAG_LEVEL_NAME, $value); + } + public function getGenerator() : string{ return $this->compoundTag->getString(self::TAG_GENERATOR_NAME, "DEFAULT"); }