Skip to content

Commit a0b76a2

Browse files
committed
4.2.2 working on a config solution
1 parent 047cfd8 commit a0b76a2

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SimpAPI v4.2.1
1+
# SimpAPI v4.2.2
22
****
33
SimpAPI, finally a good API that can make coding MC Plugins much easier and less painful.
44
This API includes all of my primary utilities like *Menu Manager*, *Command Manager*, *ColorTranslator*, and more.
@@ -25,7 +25,7 @@ JavaDocs: https://kodysimpson.github.io/SimpAPI/index.html
2525
<dependency>
2626
<groupId>com.github.KodySimpson</groupId>
2727
<artifactId>SimpAPI</artifactId>
28-
<version>4.2.1</version>
28+
<version>4.2.2</version>
2929
</dependency>
3030
```
3131

@@ -51,7 +51,7 @@ repositories {
5151
Groovy/Kotlin:
5252
```groovy
5353
dependencies {
54-
implementation 'com.github.KodySimpson:SimpAPI:4.2.1'
54+
implementation 'com.github.KodySimpson:SimpAPI:4.2.2'
5555
}
5656
```
5757

pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.kodysimpson</groupId>
88
<artifactId>SimpAPI</artifactId>
9-
<version>4.2.1</version>
9+
<version>4.2.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimpAPI</name>
@@ -89,6 +89,17 @@
8989
<version>21.0.1</version>
9090
<scope>compile</scope>
9191
</dependency>
92+
<dependency>
93+
<groupId>com.fasterxml.jackson.core</groupId>
94+
<artifactId>jackson-databind</artifactId>
95+
<version>2.12.4</version>
96+
</dependency>
97+
<dependency>
98+
<groupId>com.fasterxml.jackson.dataformat</groupId>
99+
<artifactId>jackson-dataformat-yaml</artifactId>
100+
<version>2.12.4</version>
101+
<scope>compile</scope>
102+
</dependency>
92103
</dependencies>
93104

94105
<!-- <reporting>-->
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package me.kodysimpson.simpapi.config;
2+
3+
import com.fasterxml.jackson.core.JsonFactory;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.lang.reflect.InvocationTargetException;
11+
12+
public class ConfigManager {
13+
14+
enum FileType{
15+
JSON, YAML
16+
}
17+
18+
public static <T> T loadConfig(JavaPlugin plugin, Class<T> configClass, String fileName, FileType fileType) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
19+
20+
T config = null;
21+
File messagesConfigFile = null;
22+
ObjectMapper mapper = null;
23+
24+
if (fileType == FileType.YAML){
25+
messagesConfigFile = new File(plugin.getDataFolder(), fileName + ".yml");
26+
mapper = new ObjectMapper(new YAMLFactory());
27+
}else if(fileType == FileType.JSON){
28+
messagesConfigFile = new File(plugin.getDataFolder(), fileName + ".json");
29+
mapper = new ObjectMapper(new JsonFactory());
30+
}
31+
32+
if (!messagesConfigFile.exists()){
33+
config = configClass.getConstructor().newInstance();
34+
35+
try {
36+
mapper.writeValue(messagesConfigFile, config);
37+
} catch (IOException e) {
38+
e.printStackTrace();
39+
}
40+
}else{
41+
//since it exists already, load the values into the object
42+
try {
43+
return mapper.readValue(messagesConfigFile, configClass);
44+
} catch (IOException e) {
45+
e.printStackTrace();
46+
}
47+
}
48+
return config;
49+
}
50+
51+
}

src/main/java/me/kodysimpson/simpapi/filesystem/FileDataManager.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)