@@ -125,10 +125,8 @@ struct GMSidebar::Impl {
125125 }
126126 }
127127 void saveConfig (std::filesystem::path const & path) { ll::config::saveConfig (mConfig , path); }
128- void loadData () {
129- auto & selfMod = Entry::getInstance ().getSelf ();
130- auto & logger = selfMod.getLogger ();
131- auto path = selfMod.getDataDir () / u8" data.nbt" ;
128+ void loadData (std::filesystem::path const & path) {
129+ auto & logger = Entry::getInstance ().getSelf ().getLogger ();
132130 try {
133131 if (auto content = ll::file_utils::readFile (path, true ); content) {
134132 if (auto nbt = CompoundTag::fromBinaryNbt (*content); nbt) {
@@ -150,9 +148,9 @@ struct GMSidebar::Impl {
150148 ll::error_utils::printCurrentException (logger);
151149 }
152150 }
153- void saveData () {
151+ void saveData (std::filesystem::path const & path ) {
154152 ll::file_utils::writeFile (
155- Entry::getInstance (). getSelf (). getDataDir () / u8" data.nbt " ,
153+ path ,
156154 ll::reflection::serialize<CompoundTagVariant>(mPlayerSidebarEnabled )->get <CompoundTag>().toBinaryNbt (),
157155 true
158156 );
@@ -328,6 +326,14 @@ void GMSidebar::saveConfig(std::optional<std::filesystem::path> const& path) {
328326 if (!pImpl) throw std::runtime_error (" GMSidebar is not enabled" );
329327 pImpl->saveConfig (path.value_or (Entry::getInstance ().getSelf ().getConfigDir () / u8" config.json" ));
330328}
329+ void GMSidebar::loadData (std::optional<std::filesystem::path> const & path) {
330+ if (!pImpl) throw std::runtime_error (" GMSidebar is not enabled" );
331+ pImpl->loadData (path.value_or (Entry::getInstance ().getSelf ().getConfigDir () / u8" data.nbt" ));
332+ }
333+ void GMSidebar::saveData (std::optional<std::filesystem::path> const & path) {
334+ if (!pImpl) throw std::runtime_error (" GMSidebar is not enabled" );
335+ pImpl->saveData (path.value_or (Entry::getInstance ().getSelf ().getConfigDir () / u8" data.nbt" ));
336+ }
331337bool GMSidebar::isPlayerSidebarEnabled (mce::UUID const & uuid) {
332338 if (!pImpl) throw std::runtime_error (" GMSidebar is not enabled" );
333339 if (auto it = pImpl->mPlayerSidebarEnabled .find (uuid); it != pImpl->mPlayerSidebarEnabled .end ()) {
@@ -349,6 +355,7 @@ void GMSidebar::setPlayerSidebarEnabled(mce::UUID const& uuid, bool enable) {
349355 }
350356 }
351357 }
358+ saveData (std::nullopt );
352359}
353360void GMSidebar::clearPlayerCache (mce::UUID const & uuid) {
354361 if (!pImpl) throw std::runtime_error (" GMSidebar is not enabled" );
0 commit comments