From 3f4b8a506d46a3fc558d6941a31af1b69b4cede7 Mon Sep 17 00:00:00 2001 From: Maximusbarcz Date: Mon, 19 Dec 2022 20:05:03 +0100 Subject: Im so done lmfao... anyway finally made PlayerDataSaving work so thats amazing, also finished the Branch choosing gui, I think I can finally work on other stuff now. --- .../dev/mayaqq/ygasi/registry/CommandRegistry.java | 40 ++++++++++++----- .../dev/mayaqq/ygasi/registry/ConfigRegistry.java | 6 ++- .../mayaqq/ygasi/registry/PlayerDataRegistry.java | 52 ++++++++++++++++++++++ 3 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java (limited to 'src/main/java/dev/mayaqq/ygasi/registry') diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java index 2d29443..93ccbbd 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java @@ -1,16 +1,16 @@ package dev.mayaqq.ygasi.registry; import com.mojang.brigadier.arguments.IntegerArgumentType; -import dev.mayaqq.ygasi.CreatePlayerData; +import com.mojang.brigadier.context.CommandContext; +import dev.mayaqq.ygasi.gui.BranchGui; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.stat.Stats; import net.minecraft.text.Text; -import java.io.IOException; - import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; import static net.minecraft.server.command.CommandManager.literal; @@ -18,14 +18,32 @@ public class CommandRegistry { public static void RegisterCommands() { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("skilltree") .executes(context -> { - try { - CreatePlayerData.createPlayerData(context.getSource().getPlayerOrThrow().getUuid()); - } catch (IOException e) { - throw new RuntimeException(e); - } - context.getSource().sendMessage(Text.literal("§aSkillData Registered!")); + ServerPlayerEntity player = context.getSource().getPlayer(); + BranchGui.gui(player); return 1; - }))); + }) + .then(literal("Mercenary") + .executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + BranchGui.gui(player); + return 1; + }) + ) + .then(literal("Wizardry") + .executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + BranchGui.gui(player); + return 1; + }) + ) + .then(literal("Druidry") + .executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + BranchGui.gui(player); + return 1; + }) + ) + )); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("ygasi") .requires(source -> source.hasPermissionLevel(4)) .then(literal("reset") @@ -54,4 +72,4 @@ public class CommandRegistry { }))) )); } -} +} \ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java index b34af4b..9e5c075 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java @@ -15,6 +15,7 @@ public class ConfigRegistry { public static Config CONFIG = new Config(); static File modConfFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(),"ygasi"); + private static final File serverDatFile = new File(FabricLoader.getInstance().getConfigDir().toFile() + "/ygasi/players"); private static File configFile = new File(modConfFolder,"config.json"); private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); @@ -23,7 +24,9 @@ public class ConfigRegistry { if (!modConfFolder.exists()) { modConfFolder.mkdir(); } - + if (!serverDatFile.exists()) { + serverDatFile.mkdir(); + } if (!configFile.exists()) { try { configFile.createNewFile(); @@ -50,6 +53,7 @@ public class ConfigRegistry { public static class Config { //the thing to write in the config file public int pointsRewarded = 1; + public int branchCost = 16; public Config() {} } } diff --git a/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java new file mode 100644 index 0000000..620ee89 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java @@ -0,0 +1,52 @@ +package dev.mayaqq.ygasi.registry; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.annotations.SerializedName; +import net.fabricmc.loader.api.FabricLoader; + +import java.io.*; +import java.util.*; + +public class PlayerDataRegistry { + public static PlayerData PLAYERDATA = new PlayerData(); + private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + + public static void load(UUID uuid) { + File playerDatFile = new File(FabricLoader.getInstance().getConfigDir().toFile() + "/ygasi/players/" + uuid + ".json"); + if (!playerDatFile.exists()) { + try { + playerDatFile.createNewFile(); + save(uuid); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + try { + PLAYERDATA = gson.fromJson(new FileReader(playerDatFile), PlayerData.class); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + } + + public static void save(UUID uuid) { + try { + File playerDatFile = new File(FabricLoader.getInstance().getConfigDir().toFile() + "/ygasi/players/" + uuid + ".json"); + var writer = new FileWriter(playerDatFile); + writer.write(gson.toJson(PLAYERDATA)); + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static class PlayerData { + @SerializedName("branches") + public Map branches = new HashMap<>(); + @SerializedName("skills") + public Map skills = new HashMap<>(); + public PlayerData() {} + } +} \ No newline at end of file -- cgit