aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/mayaqq/ygasi
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/dev/mayaqq/ygasi')
-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.java5
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java4
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java104
-rw-r--r--src/main/java/dev/mayaqq/ygasi/util/updatePlayerData.java17
-rw-r--r--src/main/java/dev/mayaqq/ygasi/ygasi.java2
7 files changed, 87 insertions, 58 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/config/ConfigData.java b/src/main/java/dev/mayaqq/ygasi/config/ConfigData.java
deleted file mode 100644
index 9bd5aa5..0000000
--- a/src/main/java/dev/mayaqq/ygasi/config/ConfigData.java
+++ /dev/null
@@ -1,7 +0,0 @@
-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
deleted file mode 100644
index 0b5e38f..0000000
--- a/src/main/java/dev/mayaqq/ygasi/config/ModData.java
+++ /dev/null
@@ -1,6 +0,0 @@
-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 ad90451..444ecb8 100644
--- a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
@@ -1,6 +1,6 @@
package dev.mayaqq.ygasi.mixin;
-import dev.mayaqq.ygasi.config.ConfigData;
+import dev.mayaqq.ygasi.registry.ConfigRegistry;
import net.minecraft.advancement.AdvancementRewards;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
@@ -21,8 +21,7 @@ public class AdvancementRewardsMixin {
@Inject(method = "apply",at = @At("HEAD"))
private void inject(ServerPlayerEntity player, CallbackInfo ci) {
if (recipes.length == 0) {
- LOGGER.info("Skill point unlocked");
- player.increaseStat(SKILL_POINTS, 1);
+ player.increaseStat(SKILL_POINTS, ConfigRegistry.CONFIG.pointsRewarded);
}
}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
index bf2d2af..b386727 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
@@ -1,6 +1,7 @@
package dev.mayaqq.ygasi.registry;
import com.mojang.brigadier.arguments.IntegerArgumentType;
+import dev.mayaqq.ygasi.util.updatePlayerData;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.CommandManager;
@@ -15,8 +16,7 @@ public class CommandRegistry {
public static void RegisterCommands() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("skilltree")
.executes(context -> {
- context.getSource().sendMessage(Text.literal("Surely this opened a skilltree that is definitely implemented..."));
-
+ updatePlayerData.createPlayerData(context.getSource().getPlayerOrThrow().getUuid());
return 1;
})));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("ygasi")
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
index e7dd9d8..799506e 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
@@ -2,52 +2,78 @@ 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 net.fabricmc.loader.api.FabricLoader;
import java.io.*;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.*;
-
-import static dev.mayaqq.ygasi.ygasi.LOGGER;
+import java.nio.file.Files;
+import java.util.HashMap;
+import java.util.Map;
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 Config CONFIG = new Config();
+ public static ServerData SERVERDATA = new ServerData();
+
+ private static File modConfFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(),"ygasi");
+ private static File configFile = new File(modConfFolder,"config.json");
+ private static File serverDatFile = new File(modConfFolder,"serverDat.json");
+ private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ public static void load() {
+ //we do bunch of checking here mainly if the file exists
+ if (!modConfFolder.exists()) {
+ modConfFolder.mkdir();
+ }
- 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));
+ if (!configFile.exists()) {
+ try {
+ configFile.createNewFile();
+ saveConfig();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ try {
+ CONFIG = gson.fromJson(new FileReader(configFile), Config.class);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (!serverDatFile.exists()) {
+ try {
+ serverDatFile.createNewFile();
+ saveServerData();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ try {
+ SERVERDATA = gson.fromJson(new FileReader(serverDatFile), ServerData.class);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ }
}
- return success;
}
+ public static void saveConfig() throws IOException {
+ //Write some info into the file under here
+ var writer = new FileWriter(configFile);
+ writer.write(gson.toJson(CONFIG));
+ writer.close();
+ }
+ public static void saveServerData() throws IOException {
+ var Writer = new FileWriter(serverDatFile);
+ Writer.write(gson.toJson(SERVERDATA));
+ Writer.close();
+ }
+ public static class Config {
+ //the thing to write in the config file
+ public int pointsRewarded = 1;
+ public Config() {}
+ }
+ public static class ServerData {
+ //the things to write in the serverData file, this is only temporary for now
+ public String Comment = "This File should store all the data for the players when they open the gui. Maybe this will get removed when I learn SQL? (never)";
+ public ServerData() {}
+ }
}
diff --git a/src/main/java/dev/mayaqq/ygasi/util/updatePlayerData.java b/src/main/java/dev/mayaqq/ygasi/util/updatePlayerData.java
new file mode 100644
index 0000000..6a8dd7e
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/util/updatePlayerData.java
@@ -0,0 +1,17 @@
+package dev.mayaqq.ygasi.util;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import net.minecraft.server.command.ServerCommandSource;
+import net.minecraft.server.network.ServerPlayerEntity;
+
+import java.util.Map;
+import java.util.UUID;
+
+import static dev.mayaqq.ygasi.ygasi.LOGGER;
+
+public class updatePlayerData {
+ public static void createPlayerData(UUID player) {
+ LOGGER.info(player.toString());
+ }
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/ygasi.java b/src/main/java/dev/mayaqq/ygasi/ygasi.java
index 91037d3..81f2b5b 100644
--- a/src/main/java/dev/mayaqq/ygasi/ygasi.java
+++ b/src/main/java/dev/mayaqq/ygasi/ygasi.java
@@ -16,7 +16,7 @@ public class ygasi implements ModInitializer {
public void onInitialize() {
StatRegistry.skillRegister();
CommandRegistry.RegisterCommands();
- ConfigRegistry.loadConfig();
+ ConfigRegistry.load();
LOGGER.info("You've got a skill issue!");
}
}