本文整理汇总了PHP中pocketmine\level\Location::setLevel方法的典型用法代码示例。如果您正苦于以下问题:PHP Location::setLevel方法的具体用法?PHP Location::setLevel怎么用?PHP Location::setLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\level\Location
的用法示例。
在下文中一共展示了Location::setLevel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onCommand
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
{
if ($cmd->getName() != "mobster") {
return false;
}
if (isset($args[0]) && strtolower($args[0]) == "spawn") {
array_shift($args);
}
if (!$sender->hasPermission("mobsters.cmd.spawn")) {
$sender->sendMessage("You are not allowed to do that!");
return true;
}
if (count($args) != 2) {
return false;
}
$mob = strtolower(array_shift($args));
if (($class = $this->mobClass($mob)) === null) {
$sender->sendMessage("Unknown mob class: {$mob}");
return true;
}
$location = explode(":", array_shift($args), 2);
if (count($location) < 2) {
if ($sender instanceof Player) {
$level = $sender->getLevel();
} else {
$level = $this->getServer()->getDefaultLevel();
}
} else {
$level = $this->getServer()->getLevelByName($location[1]);
if ($level === null) {
$sender->sendMessage("Unknown level: " . $location[1]);
return true;
}
}
$location = array_map("floatval", explode(",", $location[0], 5));
if (count($location) < 3) {
$sender->sendMessage("Invalid location specified");
return false;
}
$location = new Location(...$location);
$location->setLevel($level);
$this->spawnMob($class, $location);
$sender->sendMessage("Spawned {$mob}");
return true;
}