mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
World: added setDisplayName()
this is an obvious use case, and I'm not really sure why it wasn't supported sooner.
This commit is contained in:
parent
29694c19af
commit
096daef0d0
48
src/event/world/WorldDisplayNameChangeEvent.php
Normal file
48
src/event/world/WorldDisplayNameChangeEvent.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event\world;
|
||||
|
||||
use pocketmine\world\World;
|
||||
|
||||
/**
|
||||
* Called when a world's display name is changed.
|
||||
*/
|
||||
final class WorldDisplayNameChangeEvent extends WorldEvent{
|
||||
|
||||
public function __construct(
|
||||
World $world,
|
||||
private string $oldName,
|
||||
private string $newName
|
||||
){
|
||||
parent::__construct($world);
|
||||
}
|
||||
|
||||
public function getOldName() : string{
|
||||
return $this->oldName;
|
||||
}
|
||||
|
||||
public function getNewName() : string{
|
||||
return $this->newName;
|
||||
}
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
@ -34,6 +34,8 @@ interface WorldData{
|
||||
|
||||
public function getName() : string;
|
||||
|
||||
public function setName(string $value) : void;
|
||||
|
||||
/**
|
||||
* Returns the generator name
|
||||
*/
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user