Skip to content

Commit

Permalink
fix sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackjack200 committed Jun 16, 2023
1 parent 85245fe commit 4c1ee1e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/blackjack200/worldsx/command/GameRuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
}

[$name, $value] = $args;
$world = WorldUtil::findWorldByFolderName($worldName);
$world = WorldUtil::findWorldByFolderName($worldName, true);
if ($world === null) {
$sender->sendMessage($this->lang->translateString('command.gamerule.world-not-exists', [$worldName]));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace blackjack200\worldsx\command\subcommand\impl;

use blackjack200\worldsx\command\subcommand\SubCommand;
use blackjack200\worldsx\session\WorldGameRules;
use blackjack200\worldsx\world\WorldUtil;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
Expand All @@ -18,7 +19,8 @@ public function execute(CommandSender $sender, array $args) : void {
$this->mustSendTranslation($sender, 'command.load.loaded', [$worldName]);
} else {
try {
WorldUtil::loadWorld($worldName);
$w = WorldUtil::loadWorld($worldName);
var_dump(WorldGameRules::mustGetGameRuleCollection($w));
$this->mustSendTranslation($sender, 'command.load.success', [$worldName]);
} catch (Throwable $thr) {
$this->mustSendTranslation($sender, 'command.load.error', [$worldName, $thr->getMessage()]);
Expand Down
1 change: 1 addition & 0 deletions src/blackjack200/worldsx/world/GameRuleUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static function parse(BaseNbtWorldData $data) : ?GameRuleCollection {
}

public static function save(BaseNbtWorldData $data, GameRuleCollection $rules) : void {
var_dump($rules);
$data->getCompoundTag()->setTag('GameRules', $rules->toCompoundTag());
$data->save();
}
Expand Down
7 changes: 5 additions & 2 deletions src/blackjack200/worldsx/world/WorldUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
use Symfony\Component\Filesystem\Path;

class WorldUtil {
public static function findWorldByFolderName(string $name) : ?World {
public static function findWorldByFolderName(string $name, bool $tryLoad = false) : ?World {
// Assume that folderName is unique
$worlds = Server::getInstance()->getWorldManager()->getWorlds();
foreach ($worlds as $world) {
if ($world->getFolderName() === $name) {
return $world;
}
}
return self::tryLoadWorld($name);
if($tryLoad) {
return self::tryLoadWorld($name);
}
return null;
}

public static function unloadWorldByFolderName(string $name) : void {
Expand Down

0 comments on commit 4c1ee1e

Please sign in to comment.