mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Implemented Respawn Anchor (#6646)
PlayerRespawnAnchorUseEvent is also added with options SET_SPAWN and EXPLODE, which allows plugins to customise the outcome of using the anchor in PM, which currently doesn't support dimensions. The event is also cancellable.
This commit is contained in:
@ -26,6 +26,7 @@ namespace pocketmine\player;
|
||||
use pocketmine\block\BaseSign;
|
||||
use pocketmine\block\Bed;
|
||||
use pocketmine\block\BlockTypeTags;
|
||||
use pocketmine\block\RespawnAnchor;
|
||||
use pocketmine\block\UnknownBlock;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\command\CommandSender;
|
||||
@ -136,6 +137,7 @@ use pocketmine\world\sound\EntityAttackNoDamageSound;
|
||||
use pocketmine\world\sound\EntityAttackSound;
|
||||
use pocketmine\world\sound\FireExtinguishSound;
|
||||
use pocketmine\world\sound\ItemBreakSound;
|
||||
use pocketmine\world\sound\RespawnAnchorDepleteSound;
|
||||
use pocketmine\world\sound\Sound;
|
||||
use pocketmine\world\World;
|
||||
use pocketmine\YmlServerProperties;
|
||||
@ -2538,6 +2540,21 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
}
|
||||
$this->logger->debug("Respawn position located, completing respawn");
|
||||
$ev = new PlayerRespawnEvent($this, $safeSpawn);
|
||||
$spawnPosition = $ev->getRespawnPosition();
|
||||
$spawnBlock = $spawnPosition->getWorld()->getBlock($spawnPosition);
|
||||
if($spawnBlock instanceof RespawnAnchor){
|
||||
if($spawnBlock->getCharges() > 0){
|
||||
$spawnPosition->getWorld()->setBlock($spawnPosition, $spawnBlock->setCharges($spawnBlock->getCharges() - 1));
|
||||
$spawnPosition->getWorld()->addSound($spawnPosition, new RespawnAnchorDepleteSound());
|
||||
}else{
|
||||
$defaultSpawn = $this->server->getWorldManager()->getDefaultWorld()?->getSpawnLocation();
|
||||
if($defaultSpawn !== null){
|
||||
$this->setSpawn($defaultSpawn);
|
||||
$ev->setRespawnPosition($defaultSpawn);
|
||||
$this->sendMessage(KnownTranslationFactory::tile_respawn_anchor_notValid()->prefix(TextFormat::GRAY));
|
||||
}
|
||||
}
|
||||
}
|
||||
$ev->call();
|
||||
|
||||
$realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getWorld());
|
||||
|
Reference in New Issue
Block a user