Added /setworldspawn

This commit is contained in:
Shoghi Cervantes 2014-04-10 18:50:41 +02:00
parent 1dc3d42b78
commit e9aba34e6b
3 changed files with 74 additions and 0 deletions

View File

@ -44,6 +44,7 @@ use pocketmine\command\defaults\SaveOffCommand;
use pocketmine\command\defaults\SaveOnCommand; use pocketmine\command\defaults\SaveOnCommand;
use pocketmine\command\defaults\SayCommand; use pocketmine\command\defaults\SayCommand;
use pocketmine\command\defaults\SeedCommand; use pocketmine\command\defaults\SeedCommand;
use pocketmine\command\defaults\SetWorldSpawnCommand;
use pocketmine\command\defaults\SpawnpointCommand; use pocketmine\command\defaults\SpawnpointCommand;
use pocketmine\command\defaults\StatusCommand; use pocketmine\command\defaults\StatusCommand;
use pocketmine\command\defaults\StopCommand; use pocketmine\command\defaults\StopCommand;
@ -97,6 +98,7 @@ class SimpleCommandMap implements CommandMap{
$this->register("pocketmine", new GamemodeCommand("gamemode")); $this->register("pocketmine", new GamemodeCommand("gamemode"));
$this->register("pocketmine", new KillCommand("kill")); $this->register("pocketmine", new KillCommand("kill"));
$this->register("pocketmine", new SpawnpointCommand("spawnpoint")); $this->register("pocketmine", new SpawnpointCommand("spawnpoint"));
$this->register("pocketmine", new SetWorldSpawnCommand("setworldspawn"));
$this->register("pocketmine", new TeleportCommand("tp")); $this->register("pocketmine", new TeleportCommand("tp"));
$this->register("pocketmine", new ReloadCommand("reload")); $this->register("pocketmine", new ReloadCommand("reload"));

View File

@ -0,0 +1,70 @@
<?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/
*
*
*/
namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
class SetWorldSpawnCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"Sets a worlds's spawn point. If no coordinates are specified, the player's coordinates will be used.",
"/setworldspawn OR /setworldspawn <x> <y> <z>"
);
$this->setPermission("pocketmine.command.setworldspawn");
}
public function execute(CommandSender $sender, $currentAlias, array $args){
if(!$this->testPermission($sender)){
return true;
}
if(count($args) === 0){
if($sender instanceof Player){
$level = $sender->getLevel();
$pos = $sender->round();
}else{
$sender->sendMessage(TextFormat::RED . "You can only perform this command as a player");
return true;
}
}elseif(count($args) === 3){
$level = Server::getInstance()->getDefaultLevel();
$pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2]));
}else{
$sender->sendMessage(TextFormat::RED . "Usage: ".$this->usageMessage);
return true;
}
$level->setSpawn($pos);
Command::broadcastCommandMessage($sender, "Set world ".$level->getName()."'s spawnpoint to ".$pos->x.", ".$pos->y.", ".$pos->z);
return true;
}
}

View File

@ -107,6 +107,8 @@ abstract class DefaultPermissions{
self::registerPermission(new Permission(self::ROOT . ".command.defaultgamemode", "Allows the user to change the default gamemode", Permission::DEFAULT_OP), $commands); self::registerPermission(new Permission(self::ROOT . ".command.defaultgamemode", "Allows the user to change the default gamemode", Permission::DEFAULT_OP), $commands);
self::registerPermission(new Permission(self::ROOT . ".command.seed", "Allows the user to view the seed of the world", Permission::DEFAULT_OP), $commands); self::registerPermission(new Permission(self::ROOT . ".command.seed", "Allows the user to view the seed of the world", Permission::DEFAULT_OP), $commands);
self::registerPermission(new Permission(self::ROOT . ".command.status", "Allows the user to view the server performance", Permission::DEFAULT_OP), $commands); self::registerPermission(new Permission(self::ROOT . ".command.status", "Allows the user to view the server performance", Permission::DEFAULT_OP), $commands);
self::registerPermission(new Permission(self::ROOT . ".command.spawnpoint", "Allows the user to change player's spawnpoint", Permission::DEFAULT_OP), $commands);
self::registerPermission(new Permission(self::ROOT . ".command.setworldspawn", "Allows the user to change the world spawn", Permission::DEFAULT_OP), $commands);
$commands->recalculatePermissibles(); $commands->recalculatePermissibles();