Skip to content

Commit

Permalink
Fix directory creation for json storage
Browse files Browse the repository at this point in the history
Signed-off-by: DevDrizzy <[email protected]>
  • Loading branch information
DevDrizzy committed Sep 24, 2023
1 parent 982e055 commit bf19b96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions StorageAPI.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.github.paperspigot:1.8.8:1.8.8" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.mongodb:mongo-java-driver:3.12.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.paperspigot:PaperSpigot:1.8.8" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.mongodb:mongo-java-driver:3.12.12" level="project" />
<orderEntry type="library" name="Maven: me.carleslc.Simple-YAML:Simple-Yaml:1.8.3" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.33" level="project" />
</component>
Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<groupId>xyz.refinedev.api</groupId>
<artifactId>StorageAPI</artifactId>
<version>1.6</version>
<version>1.7</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand All @@ -27,7 +27,7 @@
<distributionManagement>
<repository>
<id>refine-releases</id>
<url>https://maven.insidious.cc/repository/maven-releases/</url>
<url>https://maven.refinedev.xyz/repository/maven-releases/</url>
</repository>
</distributionManagement>

Expand All @@ -36,7 +36,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.11.0</version>
<configuration>
<target>${maven.compiler.target}</target>
<source>${maven.compiler.source}</source>
Expand All @@ -45,7 +45,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.5.0</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -98,23 +98,23 @@
<url>https://jitpack.io</url>
</repository>
<repository>
<id>funkemunky-releases</id>
<url>https://nexus.funkemunky.cc/content/repositories/releases/</url>
<id>refine-public</id>
<url>https:/maven.refinedev.xyz/repository/public-repo/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.github.paperspigot</groupId>
<artifactId>1.8.8</artifactId>
<groupId>org.paperspigot</groupId>
<artifactId>PaperSpigot</artifactId>
<version>1.8.8</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.10</version>
<version>3.12.12</version>
<scope>provided</scope>
</dependency>

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/xyz/refinedev/api/storage/JsonStorage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xyz.refinedev.api.storage;

import com.google.common.io.Files;
import com.google.gson.Gson;

import org.apache.logging.log4j.LogManager;
Expand All @@ -12,9 +11,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ForkJoinPool;

/**
* This Project is property of Refine Development © 2021 - 2022
Expand All @@ -35,14 +32,18 @@ public class JsonStorage<T> {
private final Gson gson;

public JsonStorage(String name, JavaPlugin plugin, Gson gson) {
String data = plugin.getDataFolder().getAbsolutePath() + File.separator + "data";
File dir = new File(data);
if (!dir.exists()) {
boolean created = dir.mkdir();
if (!created) LOGGER.info("[Storage] Couldn't create " + name + "'s storage");
this(name, new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "data"), gson);
}

public JsonStorage(String name, File directory, Gson gson) {
if (!directory.exists()) {
boolean created = directory.mkdir();
if (!created) {
LOGGER.info("[Storage] Couldn't create " + name + "'s storage");
}
}

this.file = new File(dir, name + ".json");
this.file = new File(directory, name + ".json");
this.gson = gson;
this.name = name;

Expand Down

0 comments on commit bf19b96

Please sign in to comment.