json parsing stuff

This commit is contained in:
0x01FE 2025-02-17 14:32:33 -06:00
parent cc1a3ec840
commit 754d9c6420
3 changed files with 61 additions and 1 deletions

View File

@ -20,5 +20,10 @@
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20250107</version>
</dependency>
</dependencies>
</project>

View File

@ -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<MythicItem> getMythics() {
ArrayList<MythicItem> 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();

View File

@ -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
}