From 754d9c6420358f864273098fb6a376d1c9e55181 Mon Sep 17 00:00:00 2001 From: 0x01FE Date: Mon, 17 Feb 2025 14:32:33 -0600 Subject: [PATCH] json parsing stuff --- pom.xml | 5 ++ .../hexa/MythicItems/Mythics/MythicItem.java | 46 ++++++++++++++++++- .../resources/mythic-items/terra-pickaxe.json | 11 +++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/mythic-items/terra-pickaxe.json diff --git a/pom.xml b/pom.xml index 53b973a..bee2213 100644 --- a/pom.xml +++ b/pom.xml @@ -20,5 +20,10 @@ 1.21.4-R0.1-SNAPSHOT provided + + org.json + json + 20250107 + diff --git a/src/main/java/net/hexa/MythicItems/Mythics/MythicItem.java b/src/main/java/net/hexa/MythicItems/Mythics/MythicItem.java index 06fe510..75e4afa 100644 --- a/src/main/java/net/hexa/MythicItems/Mythics/MythicItem.java +++ b/src/main/java/net/hexa/MythicItems/Mythics/MythicItem.java @@ -1,15 +1,59 @@ package net.hexa.MythicItems.Mythics; +import org.json.*; + +import com.google.gson.JsonObject; + +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -public abstract class MythicItem { +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class MythicItem { + private static final String MYTHIC_DIR = "resources/mythic-items"; + public ItemStack item; public MythicItem() {} + // Parse a mythic item from a json file + public MythicItem(JSONObject json) { + String item_id = json.getString("item_id"); + + this.item = new ItemStack(Material.getMaterial(item_id)); + + ItemMeta item_metadata = item.getItemMeta(); + + JSONObject enchantments = json.getJSONObject("Enchantments"); + for (String enchanment_key : enchantments.keys()) { + + } + } + + // Parse all mythic items in the resources/mythics-items/ directory + public static List getMythics() { + ArrayList mythic_items = new ArrayList<>(); + + File mythic_directory = new File(MYTHIC_DIR); + File[] mythic_jsons = mythic_directory.listFiles(); + + if (mythic_jsons != null) { + for (File mythic_json : mythic_jsons) { + String json_content = new Scanner(mythic_json).useDelimiter("\\Z").next(); + + mythic_items.add(new MythicItem(new JSONObject(json_content))); + } + } + + return mythic_items; + } + public static int getMythicId(ItemStack item) { PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer(); diff --git a/src/main/resources/mythic-items/terra-pickaxe.json b/src/main/resources/mythic-items/terra-pickaxe.json new file mode 100644 index 0000000..643cae7 --- /dev/null +++ b/src/main/resources/mythic-items/terra-pickaxe.json @@ -0,0 +1,11 @@ +{ + "item_id" : "minecraft:netherite_pickaxe", + "Enchantments" : { + "UNBREAKING" : 9, + "EFFICIENCY" : 9 + }, + "Name" : "Terra Pickaxe", + "Lore" : "and the land thrashes in furious pain...", + "Unbreakable" : true, + "mythic_id" : 1 +} \ No newline at end of file