-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use non-annotated config for storage
- Loading branch information
1 parent
31fb657
commit 2a44a06
Showing
4 changed files
with
94 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/gregtech/api/persistence/PersistentData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package gregtech.api.persistence; | ||
|
||
import gregtech.api.GTValues; | ||
|
||
import net.minecraftforge.common.config.Configuration; | ||
import net.minecraftforge.fml.common.Loader; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
|
||
public final class PersistentData { | ||
|
||
public static final String CATEGORY_NAME = "persistent data"; | ||
|
||
private static final PersistentData INSTANCE = new PersistentData(); | ||
private static final String FILE_NAME = "persistent_data.cfg"; | ||
|
||
private @Nullable Configuration config; | ||
|
||
public static @NotNull PersistentData instance() { | ||
return INSTANCE; | ||
} | ||
|
||
private PersistentData() {} | ||
|
||
/** | ||
* @return the persistent data storage | ||
*/ | ||
public @NotNull Configuration getConfig() { | ||
if (config == null) { | ||
Path configFolderPath = Loader.instance().getConfigDir().toPath().resolve(GTValues.MODID); | ||
File file = configFolderPath.resolve(FILE_NAME).toFile(); | ||
config = new Configuration(file); | ||
} | ||
return config; | ||
} | ||
|
||
@ApiStatus.Internal | ||
public void init() { | ||
Configuration configuration = getConfig(); | ||
configuration.load(); | ||
String comment = """ | ||
GregTech Persistent Data. Items in this file will persist across game loads. | ||
Modifications to this file may be overwritten by GT. | ||
If you are a modpack author, you should ship this file in releases."""; | ||
configuration.addCustomCategoryComment(CATEGORY_NAME, comment); | ||
|
||
if (configuration.hasChanged()) { | ||
configuration.save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters