Move data files into sub-directory
MelanX opened this issue ยท 0 comments
Describe your idea
Currently, there are two files in <world>/data/
for Skyblock Builder. These are skyblock_builder.dat
and skyblock_template.dat
. It should be moved to a separate sub-directory.
skyblock_builder.dat
->skyblockbuilder/main.dat
skyblock_template.dat
->skyblockbuilder/template.dat
Here's a patch for this
Index: src/main/java/de/melanx/skyblockbuilder/data/SkyblockSavedData.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/de/melanx/skyblockbuilder/data/SkyblockSavedData.java b/src/main/java/de/melanx/skyblockbuilder/data/SkyblockSavedData.java
--- a/src/main/java/de/melanx/skyblockbuilder/data/SkyblockSavedData.java (revision 29cab642f8cfd84347c0ff8b0d8d8667e08aa310)
+++ b/src/main/java/de/melanx/skyblockbuilder/data/SkyblockSavedData.java (date 1721466992207)
@@ -36,6 +36,9 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
import java.util.*;
/*
@@ -45,7 +48,7 @@
@SuppressWarnings({"unused", "UnusedReturnValue"})
public class SkyblockSavedData extends SavedData {
- private static final String NAME = "skyblock_builder";
+ private static final String NAME = "skyblockbuilder/main";
private static SkyblockSavedData clientInstance;
public static final UUID SPAWN_ID = Util.NIL_UUID;
@@ -541,6 +544,19 @@
super.setDirty();
}
+ @Override
+ public void save(@Nonnull File file) {
+ if (this.isDirty()) {
+ try {
+ Files.createDirectories(file.toPath().getParent());
+ } catch (IOException e) {
+ SkyblockBuilder.getLogger().error("Could not create directory: {}", file.getAbsolutePath(), e);
+ }
+ }
+
+ super.save(file);
+ }
+
@Nullable
public ServerLevel getLevel() {
return this.level;
Index: src/main/java/de/melanx/skyblockbuilder/data/TemplateData.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/de/melanx/skyblockbuilder/data/TemplateData.java b/src/main/java/de/melanx/skyblockbuilder/data/TemplateData.java
--- a/src/main/java/de/melanx/skyblockbuilder/data/TemplateData.java (revision 29cab642f8cfd84347c0ff8b0d8d8667e08aa310)
+++ b/src/main/java/de/melanx/skyblockbuilder/data/TemplateData.java (date 1692293772000)
@@ -1,5 +1,6 @@
package de.melanx.skyblockbuilder.data;
+import de.melanx.skyblockbuilder.SkyblockBuilder;
import de.melanx.skyblockbuilder.template.ConfiguredTemplate;
import de.melanx.skyblockbuilder.template.TemplateLoader;
import net.minecraft.nbt.CompoundTag;
@@ -8,10 +9,13 @@
import net.minecraft.world.level.storage.DimensionDataStorage;
import javax.annotation.Nonnull;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
public class TemplateData extends SavedData {
- private static final String NAME = "skyblock_template";
+ private static final String NAME = "skyblockbuilder/template";
private final ConfiguredTemplate template;
@@ -38,6 +42,19 @@
return this.template.write(compound);
}
+ @Override
+ public void save(@Nonnull File file) {
+ if (this.isDirty()) {
+ try {
+ Files.createDirectories(file.toPath().getParent());
+ } catch (IOException e) {
+ SkyblockBuilder.getLogger().error("Could not create directory: {}", file.getAbsolutePath(), e);
+ }
+ }
+
+ super.save(file);
+ }
+
public void refreshTemplate() {
this.template.read(TemplateLoader.getConfiguredTemplate().write(new CompoundTag()));
this.setDirty();