PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
SpawnpointCommand.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\command\defaults;
25
34use function count;
35use function round;
36
38
39 public function __construct(string $namespace, string $name){
40 parent::__construct(
41 $namespace,
42 $name,
43 KnownTranslationFactory::pocketmine_command_spawnpoint_description(),
44 KnownTranslationFactory::commands_spawnpoint_usage()
45 );
46 $this->setPermissions([
47 DefaultPermissionNames::COMMAND_SPAWNPOINT_SELF,
48 DefaultPermissionNames::COMMAND_SPAWNPOINT_OTHER
49 ]);
50 }
51
52 public function execute(CommandSender $sender, string $commandLabel, array $args){
53 $target = $this->fetchPermittedPlayerTarget($commandLabel, $sender, $args[0] ?? null, DefaultPermissionNames::COMMAND_SPAWNPOINT_SELF, DefaultPermissionNames::COMMAND_SPAWNPOINT_OTHER);
54 if($target === null){
55 return true;
56 }
57
58 if(count($args) === 4){
59 $world = $target->getWorld();
60 $pos = $sender instanceof Player ? $sender->getPosition() : $world->getSpawnLocation();
61 $x = $this->getRelativeDouble($pos->x, $sender, $args[1]);
62 $y = $this->getRelativeDouble($pos->y, $sender, $args[2], World::Y_MIN, World::Y_MAX);
63 $z = $this->getRelativeDouble($pos->z, $sender, $args[3]);
64 $target->setSpawn(new Position($x, $y, $z, $world));
65
66 Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_spawnpoint_success($target->getName(), (string) round($x, 2), (string) round($y, 2), (string) round($z, 2)));
67
68 return true;
69 }elseif(count($args) <= 1 && $sender instanceof Player){
70 $cpos = $sender->getPosition();
71 $pos = Position::fromObject($cpos->floor(), $cpos->getWorld());
72 $target->setSpawn($pos);
73
74 Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_spawnpoint_success($target->getName(), (string) round($pos->x, 2), (string) round($pos->y, 2), (string) round($pos->z, 2)));
75 return true;
76 }
77
79 }
80}
setPermissions(array $permissions)
Definition Command.php:106
execute(CommandSender $sender, string $commandLabel, array $args)