aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMaximusbarcz <maxim.baranek@gmail.com>2022-12-23 11:29:31 +0100
committerMaximusbarcz <maxim.baranek@gmail.com>2022-12-23 11:29:31 +0100
commite5bc4dae41d2d3e04440a4fe02793d4084427437 (patch)
tree739ad7936b322f506b4a845cada07372ac40576a /src/main/java
parentca23a48ec1efa4ebcc578c8dc876a0e8794a885b (diff)
downloadygasi-e5bc4dae41d2d3e04440a4fe02793d4084427437.tar.gz
ygasi-e5bc4dae41d2d3e04440a4fe02793d4084427437.tar.bz2
ygasi-e5bc4dae41d2d3e04440a4fe02793d4084427437.zip
Added DataGen to the build.gradle (not done yet)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java20
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java41
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java41
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java41
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/AdvancementRegistry.java4
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java17
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/DataGenRegistry.java11
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java29
8 files changed, 190 insertions, 14 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
index c7b9950..ac19478 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
@@ -1,9 +1,8 @@
package dev.mayaqq.ygasi.gui;
-import dev.mayaqq.ygasi.registry.ConfigRegistry;
-import dev.mayaqq.ygasi.registry.PlayerDataRegistry;
import eu.pb4.sgui.api.elements.*;
import eu.pb4.sgui.api.gui.SimpleGui;
+
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
@@ -17,6 +16,9 @@ import java.util.UUID;
import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
+import dev.mayaqq.ygasi.registry.ConfigRegistry;
+import dev.mayaqq.ygasi.registry.PlayerDataRegistry;
+
public class BranchGui {
public static void gui(ServerPlayerEntity player) {
try {
@@ -65,7 +67,7 @@ public class BranchGui {
.glow()
.setName(Text.literal("Mercenary")
.setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)))
- .setCallback((index, clickType, actionType) -> gui.close())
+ .setCallback((index, clickType, actionType) -> MercenaryGui.gui(player))
);
}
@@ -83,7 +85,7 @@ public class BranchGui {
.glow()
.setName(Text.literal("Wizardry")
.setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.DARK_PURPLE)))
- .setCallback((index, clickType, actionType) -> gui.close())
+ .setCallback((index, clickType, actionType) -> WizardryGui.gui(player))
);
}
@@ -101,7 +103,7 @@ public class BranchGui {
.glow()
.setName(Text.literal("Druidry")
.setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.GREEN)))
- .setCallback((index, clickType, actionType) -> gui.close())
+ .setCallback((index, clickType, actionType) -> DruidryGui.gui(player))
);
}
gui.open();
@@ -116,6 +118,14 @@ public class BranchGui {
PlayerDataRegistry.PLAYERDATA.branches.put(branch, true);
PlayerDataRegistry.save(player.getUuid());
player.closeHandledScreen();
+ if (branch.equals("mercenary")) {
+ MercenaryGui.gui(player);
+ } else if (branch.equals("wizardry")) {
+ WizardryGui.gui(player);
+ } else if (branch.equals("druidry")) {
+ DruidryGui.gui(player);
+ }
+
} else {
player.sendMessage(Text.literal("You don't have enough skill points to unlock this branch!").setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)), false);
player.closeHandledScreen();
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java
new file mode 100644
index 0000000..4054ead
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java
@@ -0,0 +1,41 @@
+package dev.mayaqq.ygasi.gui;
+
+import dev.mayaqq.ygasi.registry.PlayerDataRegistry;
+import eu.pb4.sgui.api.elements.GuiElementBuilder;
+import eu.pb4.sgui.api.gui.SimpleGui;
+import net.minecraft.item.Items;
+import net.minecraft.screen.ScreenHandlerType;
+import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.stat.Stats;
+import net.minecraft.text.Text;
+
+import java.util.UUID;
+
+import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
+
+public class DruidryGui {
+ public static void gui(ServerPlayerEntity player) {
+ try {
+ UUID playerUUID = player.getUuid();
+ PlayerDataRegistry.load(playerUUID);
+ if (PlayerDataRegistry.PLAYERDATA.branches.get("druidry") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("druidry")) {
+ player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false);
+ BranchGui.gui(player);
+ } else {
+ SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) {};
+
+ gui.setTitle(Text.of( "§a§lDruidry " + "§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))));
+
+ for (int x = 0; x <= 53; x++) {
+ gui.setSlot(x, new GuiElementBuilder()
+ .setItem(Items.GRAY_STAINED_GLASS_PANE)
+ .setName(Text.of(" "))
+ );
+ }
+ gui.open();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java
new file mode 100644
index 0000000..5c95eb2
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java
@@ -0,0 +1,41 @@
+package dev.mayaqq.ygasi.gui;
+
+import dev.mayaqq.ygasi.registry.PlayerDataRegistry;
+import eu.pb4.sgui.api.elements.GuiElementBuilder;
+import eu.pb4.sgui.api.gui.SimpleGui;
+import net.minecraft.item.Items;
+import net.minecraft.screen.ScreenHandlerType;
+import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.stat.Stats;
+import net.minecraft.text.Text;
+
+import java.util.UUID;
+
+import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
+
+public class MercenaryGui {
+ public static void gui(ServerPlayerEntity player) {
+ try {
+ UUID playerUUID = player.getUuid();
+ PlayerDataRegistry.load(playerUUID);
+ if (PlayerDataRegistry.PLAYERDATA.branches.get("mercenary") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("mercenary")) {
+ player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false);
+ BranchGui.gui(player);
+ } else {
+ SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) {};
+
+ gui.setTitle(Text.of( "§c§lMercenary " + "§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))));
+
+ for (int x = 0; x <= 53; x++) {
+ gui.setSlot(x, new GuiElementBuilder()
+ .setItem(Items.GRAY_STAINED_GLASS_PANE)
+ .setName(Text.of(" "))
+ );
+ }
+ gui.open();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java
new file mode 100644
index 0000000..c48b0c1
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java
@@ -0,0 +1,41 @@
+package dev.mayaqq.ygasi.gui;
+
+import dev.mayaqq.ygasi.registry.PlayerDataRegistry;
+import eu.pb4.sgui.api.elements.GuiElementBuilder;
+import eu.pb4.sgui.api.gui.SimpleGui;
+import net.minecraft.item.Items;
+import net.minecraft.screen.ScreenHandlerType;
+import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.stat.Stats;
+import net.minecraft.text.Text;
+
+import java.util.UUID;
+
+import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
+
+public class WizardryGui {
+ public static void gui(ServerPlayerEntity player) {
+ try {
+ UUID playerUUID = player.getUuid();
+ PlayerDataRegistry.load(playerUUID);
+ if (PlayerDataRegistry.PLAYERDATA.branches.get("wizardry") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("wizardry")) {
+ player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false);
+ BranchGui.gui(player);
+ } else {
+ SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) {};
+
+ gui.setTitle(Text.of( "§5§lWizardry " + "§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))));
+
+ for (int x = 0; x <= 53; x++) {
+ gui.setSlot(x, new GuiElementBuilder()
+ .setItem(Items.GRAY_STAINED_GLASS_PANE)
+ .setName(Text.of(" "))
+ );
+ }
+ gui.open();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/AdvancementRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/AdvancementRegistry.java
new file mode 100644
index 0000000..09aa2c5
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/registry/AdvancementRegistry.java
@@ -0,0 +1,4 @@
+package dev.mayaqq.ygasi.registry;
+
+public class AdvancementRegistry {
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
index 190002b..62d8dea 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
@@ -3,7 +3,11 @@ package dev.mayaqq.ygasi.registry;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import dev.mayaqq.ygasi.gui.BranchGui;
+import dev.mayaqq.ygasi.gui.DruidryGui;
+import dev.mayaqq.ygasi.gui.MercenaryGui;
+import dev.mayaqq.ygasi.gui.WizardryGui;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
+import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
@@ -11,6 +15,8 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
+import java.io.File;
+
import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
import static net.minecraft.server.command.CommandManager.literal;
@@ -25,21 +31,21 @@ public class CommandRegistry {
.then(literal("Mercenary")
.executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
- BranchGui.gui(player);
+ MercenaryGui.gui(player);
return 1;
})
)
.then(literal("Wizardry")
.executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
- BranchGui.gui(player);
+ WizardryGui.gui(player);
return 1;
})
)
.then(literal("Druidry")
.executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
- BranchGui.gui(player);
+ DruidryGui.gui(player);
return 1;
})
)
@@ -51,7 +57,10 @@ public class CommandRegistry {
.executes(context -> {
ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "target");
player.resetStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS));
- context.getSource().sendMessage(Text.literal("§aSkill Points reset to 0 for " + player.getEntityName() + "."));
+ File playerData = new File(FabricLoader.getInstance().getGameDir().toFile() + "/ygasi/" + player.getUuid() + ".json");
+ playerData.delete();
+ PlayerDataRegistry.load(player.getUuid());
+ context.getSource().sendMessage(Text.literal("§aSkill Points reset to 0 and all skill data deleted for " + player.getEntityName() + "."));
return 1;
})))
.then(literal("add")
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/DataGenRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/DataGenRegistry.java
new file mode 100644
index 0000000..a060c42
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/registry/DataGenRegistry.java
@@ -0,0 +1,11 @@
+package dev.mayaqq.ygasi.registry;
+
+import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
+import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
+
+public class DataGenRegistry implements DataGeneratorEntrypoint {
+ @Override
+ public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) {
+
+ }
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java
index 811d8e0..d3fd387 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java
@@ -4,19 +4,19 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import net.fabricmc.loader.api.FabricLoader;
-import net.minecraft.server.MinecraftServer;
import java.io.*;
import java.util.*;
public class PlayerDataRegistry {
public static PlayerData PLAYERDATA = new PlayerData();
+ public static EmptyPlayerData EMPTYPLAYERDATA = new EmptyPlayerData();
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
public static void load(UUID uuid) {
//this isnt working :sob:
- File playerDataFolder = new File(MinecraftServer::getSavePath, "ygasi");
+ File playerDataFolder = new File(FabricLoader.getInstance().getGameDir().toFile(), "ygasi");
File playerDatFile = new File(FabricLoader.getInstance().getGameDir().toFile() + "/ygasi/" + uuid + ".json");
if (!playerDataFolder.exists()) {
playerDataFolder.mkdir();
@@ -24,7 +24,7 @@ public class PlayerDataRegistry {
if (!playerDatFile.exists()) {
try {
playerDatFile.createNewFile();
- save(uuid);
+ saveEmpty(uuid);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -47,13 +47,32 @@ public class PlayerDataRegistry {
throw new RuntimeException(e);
}
}
+ public static void saveEmpty(UUID uuid) {
+ try {
+ File playerDatFile = new File(FabricLoader.getInstance().getGameDir().toFile() + "/ygasi/" + uuid + ".json");
+ var writer = new FileWriter(playerDatFile);
+ writer.write(gson.toJson(EMPTYPLAYERDATA));
+ writer.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
public static class PlayerData {
@SerializedName("branches")
- public Map<String, Boolean> branches = new HashMap<>();
+ public static Map<String, Boolean> branches = new HashMap<>();
@SerializedName("skills")
- public Map<String, Map<String, Integer>> skills = new HashMap<>();
+ public static Map<String, Integer> skills = new HashMap<>();
public PlayerData() {}
}
+
+ public static class EmptyPlayerData {
+ @SerializedName("branches")
+ public static Map<String, Boolean> branches = new HashMap<>();
+ @SerializedName("skills")
+ public static Map<String, Integer> skills = new HashMap<>();
+
+ public EmptyPlayerData() {}
+ }
} \ No newline at end of file