mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
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:
@ -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{
|
||||
|
Reference in New Issue
Block a user