json parsing stuff
This commit is contained in:
parent
cc1a3ec840
commit
754d9c6420
5
pom.xml
5
pom.xml
@ -20,5 +20,10 @@
|
|||||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20250107</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,15 +1,59 @@
|
|||||||
package net.hexa.MythicItems.Mythics;
|
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.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
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 ItemStack item;
|
||||||
|
|
||||||
public MythicItem() {}
|
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) {
|
public static int getMythicId(ItemStack item) {
|
||||||
PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer();
|
PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer();
|
||||||
|
|
||||||
|
|||||||
11
src/main/resources/mythic-items/terra-pickaxe.json
Normal file
11
src/main/resources/mythic-items/terra-pickaxe.json
Normal 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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user