Implement difficulty per-world (#878)

* Moved Server::getDifficultyFromString() to Level
* Added ability to set difficulty in worlds section of pocketmine.yml for generation
This commit is contained in:
Dylan K. Taylor
2017-09-26 11:16:51 +01:00
committed by GitHub
parent e64076ec81
commit 38fad4b963
9 changed files with 132 additions and 50 deletions

View File

@ -27,8 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer;
use pocketmine\network\mcpe\protocol\SetDifficultyPacket;
use pocketmine\Server;
use pocketmine\level\Level;
class DifficultyCommand extends VanillaCommand{
@ -50,18 +49,19 @@ class DifficultyCommand extends VanillaCommand{
throw new InvalidCommandSyntaxException();
}
$difficulty = Server::getDifficultyFromString($args[0]);
$difficulty = Level::getDifficultyFromString($args[0]);
if($sender->getServer()->isHardcore()){
$difficulty = 3;
$difficulty = Level::DIFFICULTY_HARD;
}
if($difficulty !== -1){
$sender->getServer()->setConfigInt("difficulty", $difficulty);
$pk = new SetDifficultyPacket();
$pk->difficulty = $sender->getServer()->getDifficulty();
$sender->getServer()->broadcastPacket($sender->getServer()->getOnlinePlayers(), $pk);
//TODO: add per-world support
foreach($sender->getServer()->getLevels() as $level){
$level->setDifficulty($difficulty);
}
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.difficulty.success", [$difficulty]));
}else{