aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaximusbarcz <maxim.baranek@gmail.com>2022-10-07 18:19:35 +0200
committerMaximusbarcz <maxim.baranek@gmail.com>2022-10-07 18:19:35 +0200
commit445a582dd86896145eed4b4c3443cd627794703a (patch)
tree3d891743985bb1d170f351cd8779b1f880a9b091
parent7281ea4ee14d85215707d6700efa7cf28300db41 (diff)
downloadygasi-445a582dd86896145eed4b4c3443cd627794703a.tar.gz
ygasi-445a582dd86896145eed4b4c3443cd627794703a.tar.bz2
ygasi-445a582dd86896145eed4b4c3443cd627794703a.zip
Added Config Creating!
-rw-r--r--src/main/java/dev/mayaqq/ygasi/config/ConfigData.java7
-rw-r--r--src/main/java/dev/mayaqq/ygasi/config/ModData.java6
-rw-r--r--src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java3
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java (renamed from src/main/java/dev/mayaqq/ygasi/CommandRegistry.java)4
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java53
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/StatRegistry.java (renamed from src/main/java/dev/mayaqq/ygasi/StatRegistry.java)2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/ygasi.java6
7 files changed, 77 insertions, 4 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/config/ConfigData.java b/src/main/java/dev/mayaqq/ygasi/config/ConfigData.java
new file mode 100644
index 0000000..9bd5aa5
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/config/ConfigData.java
@@ -0,0 +1,7 @@
+package dev.mayaqq.ygasi.config;
+
+public class ConfigData {
+ public String testString = "String";
+ public boolean testBoolean = false;
+}
+
diff --git a/src/main/java/dev/mayaqq/ygasi/config/ModData.java b/src/main/java/dev/mayaqq/ygasi/config/ModData.java
new file mode 100644
index 0000000..0b5e38f
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/config/ModData.java
@@ -0,0 +1,6 @@
+package dev.mayaqq.ygasi.config;
+
+public class ModData {
+ public String TestUUID = "UUID";
+ public boolean testBoolean = false;
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
index 8848d28..ad90451 100644
--- a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
@@ -1,5 +1,6 @@
package dev.mayaqq.ygasi.mixin;
+import dev.mayaqq.ygasi.config.ConfigData;
import net.minecraft.advancement.AdvancementRewards;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
@@ -10,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import static dev.mayaqq.ygasi.StatRegistry.SKILL_POINTS;
+import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
import static dev.mayaqq.ygasi.ygasi.LOGGER;
@Mixin(AdvancementRewards.class)
diff --git a/src/main/java/dev/mayaqq/ygasi/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
index 47deb24..bf2d2af 100644
--- a/src/main/java/dev/mayaqq/ygasi/CommandRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
@@ -1,4 +1,4 @@
-package dev.mayaqq.ygasi;
+package dev.mayaqq.ygasi.registry;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
@@ -8,7 +8,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
-import static dev.mayaqq.ygasi.StatRegistry.SKILL_POINTS;
+import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
import static net.minecraft.server.command.CommandManager.literal;
public class CommandRegistry {
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
new file mode 100644
index 0000000..e7dd9d8
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
@@ -0,0 +1,53 @@
+package dev.mayaqq.ygasi.registry;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import dev.mayaqq.ygasi.config.ConfigData;
+import dev.mayaqq.ygasi.config.ModData;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.*;
+
+import static dev.mayaqq.ygasi.ygasi.LOGGER;
+
+public class ConfigRegistry {
+ public static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
+ private static ConfigData CONFIG;
+ private static ModData DATA;
+
+ public static ConfigData getConfig() {
+ return CONFIG;
+ }
+
+ public static boolean loadConfig() {
+ boolean success = false;
+ Charset charSet = StandardCharsets.UTF_8;
+
+ CONFIG = null;
+ try {
+ File configDir = Paths.get("", "config", "ygasi").toFile();
+ File dataDir = Paths.get("", "config", "ygasi", "data").toFile();
+ dataDir.mkdirs();
+ File configFile = new File(configDir, "config.json");
+ File dataFile = new File(dataDir, "data.json");
+
+ ConfigData configData = configFile.exists() ? GSON.fromJson(new InputStreamReader(new FileInputStream(configFile), charSet), ConfigData.class) : new ConfigData();
+ ModData modData = dataFile.exists() ? GSON.fromJson(new InputStreamReader(new FileInputStream(dataFile), charSet), ModData.class) : new ModData();
+
+ CONFIG = new ConfigData();
+
+ BufferedWriter configWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), charSet));
+ BufferedWriter dataWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dataFile), charSet));
+ dataWriter.write(GSON.toJson(modData));
+ configWriter.write(GSON.toJson(configData));
+ configWriter.close();
+ dataWriter.close();
+ } catch (IOException e ) {
+ LOGGER.error(String.valueOf(e));
+ }
+ return success;
+ }
+
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/StatRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/StatRegistry.java
index 0b1c986..5d6d165 100644
--- a/src/main/java/dev/mayaqq/ygasi/StatRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/StatRegistry.java
@@ -1,4 +1,4 @@
-package dev.mayaqq.ygasi;
+package dev.mayaqq.ygasi.registry;
import eu.pb4.polymer.api.other.PolymerStat;
import net.minecraft.stat.StatFormatter;
diff --git a/src/main/java/dev/mayaqq/ygasi/ygasi.java b/src/main/java/dev/mayaqq/ygasi/ygasi.java
index ab08648..91037d3 100644
--- a/src/main/java/dev/mayaqq/ygasi/ygasi.java
+++ b/src/main/java/dev/mayaqq/ygasi/ygasi.java
@@ -1,9 +1,14 @@
package dev.mayaqq.ygasi;
+import dev.mayaqq.ygasi.registry.CommandRegistry;
+import dev.mayaqq.ygasi.registry.ConfigRegistry;
+import dev.mayaqq.ygasi.registry.StatRegistry;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+
public class ygasi implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("ygasi");
@@ -11,6 +16,7 @@ public class ygasi implements ModInitializer {
public void onInitialize() {
StatRegistry.skillRegister();
CommandRegistry.RegisterCommands();
+ ConfigRegistry.loadConfig();
LOGGER.info("You've got a skill issue!");
}
}