|
1 | 1 | package kr.toxicity.test; |
2 | 2 |
|
| 3 | +import com.google.gson.Gson; |
| 4 | +import com.google.gson.JsonObject; |
3 | 5 | import com.google.gson.JsonParser; |
| 6 | +import com.google.gson.stream.JsonWriter; |
4 | 7 | import kr.toxicity.libraries.datacomponent.DataComponentAPIBukkit; |
5 | 8 | import kr.toxicity.libraries.datacomponent.api.DataComponentAPI; |
6 | 9 | import kr.toxicity.libraries.datacomponent.api.DataComponentType; |
7 | 10 | import kr.toxicity.libraries.datacomponent.api.NMS; |
8 | | -import kr.toxicity.libraries.datacomponent.api.wrapper.Rarity; |
| 11 | +import kr.toxicity.libraries.datacomponent.api.wrapper.*; |
9 | 12 | import net.kyori.adventure.text.Component; |
10 | 13 | import org.bukkit.Material; |
| 14 | +import org.bukkit.configuration.file.YamlConfiguration; |
11 | 15 | import org.bukkit.inventory.ItemStack; |
12 | 16 | import org.bukkit.plugin.java.JavaPlugin; |
13 | 17 |
|
| 18 | +import java.io.BufferedWriter; |
| 19 | +import java.io.File; |
| 20 | +import java.io.FileWriter; |
| 21 | +import java.util.HashMap; |
| 22 | + |
14 | 23 | public class TestPlugin extends JavaPlugin { |
15 | 24 | @Override |
16 | 25 | public void onEnable() { |
17 | 26 | DataComponentAPIBukkit.load(); |
18 | 27 |
|
19 | | - var apply = DataComponentAPI.api().adapter(new ItemStack(Material.DIAMOND_SWORD)); |
| 28 | + var apply = DataComponentAPI.api().adapter(new ItemStack(Material.NETHERITE_SWORD)); |
20 | 29 | apply.set(DataComponentType.DAMAGE, 3); |
21 | | - apply.set(DataComponentType.REPAIR_COST, 20); |
22 | | - apply.set(DataComponentType.RARITY, Rarity.EPIC); |
23 | | - getLogger().info(apply.serialize().toString()); |
24 | | - |
25 | | - // Serialization. |
26 | | - var data = DataComponentAPI.api().deserializer().deserialize( |
27 | | - JsonParser.parseString("{\"damage\":3,\"max_stack_size\":1,\"repair_cost\":20,\"tool\":{\"rules\":[{\"blocks\":\"minecraft:cobweb\",\"speed\":15.0,\"correct_for_drops\":true},{\"blocks\":\"#minecraft:sword_efficient\",\"speed\":1.5}],\"damage_per_block\":2},\"max_damage\":1561,\"item_lore\":[],\"rarity\":\"epic\"}").getAsJsonObject() |
28 | | - ); |
29 | | - var diamond = DataComponentAPI.api().adapter(new ItemStack(Material.DIAMOND)); |
30 | | - getLogger().info(diamond.serialize().toString()); |
31 | | - data.set(diamond); |
32 | | - getLogger().info(diamond.serialize().toString()); |
33 | | - |
34 | | - var value = data.get(NMS.nms().rarity()); |
35 | | - if (value != null) getLogger().info(value.name()); |
36 | | - |
37 | | - for (Material material : Material.values()) { |
38 | | - if (material.isItem()) { |
39 | | - try { |
40 | | - DataComponentAPI.api().adapter(new ItemStack(material)).serialize(); |
41 | | - } catch (Exception e) { |
42 | | - getLogger().info(material.name()); |
43 | | - } |
44 | | - } |
| 30 | + apply.set(DataComponentType.REPAIR_COST, 10); |
| 31 | + apply.set(DataComponentType.ENCHANTMENT_GLINT_OVERRIDE, false); |
| 32 | + apply.set(DataComponentType.ITEM_NAME, Component.text("Hello")); |
| 33 | + apply.set(DataComponentType.CUSTOM_NAME, Component.text("World")); |
| 34 | + apply.set(DataComponentType.CUSTOM_MODEL_DATA, new CustomModelData(1)); |
| 35 | + |
| 36 | + var map = new HashMap<String, Tag<?>>(); |
| 37 | + map.put("a", new Tag<>(Tag.INT, 1)); |
| 38 | + map.put("b", new Tag<>(Tag.STRING, "ddd")); |
| 39 | + map.put("c", new Tag<>(Tag.INT_ARRAY, new int[] {1, 2, 3})); |
| 40 | + apply.set(DataComponentType.CUSTOM_DATA, new CustomData(new CompoundTag(map))); |
| 41 | + |
| 42 | + var get = apply.build(); |
| 43 | + |
| 44 | + var data = getDataFolder(); |
| 45 | + if (!data.exists()) data.mkdirs(); |
| 46 | + |
| 47 | + var result = new File(data, "result.json"); |
| 48 | + var compare = new File(data, "compare.yml"); |
| 49 | + try (JsonWriter writer = new JsonWriter(new BufferedWriter(new FileWriter(result)))) { |
| 50 | + writer.setIndent(" "); |
| 51 | + var itemJson = new JsonObject(); |
| 52 | + itemJson.addProperty("type", Material.NETHERITE_SWORD.name()); |
| 53 | + itemJson.add("components", apply.serialize()); |
| 54 | + new Gson().toJson(itemJson, writer); |
| 55 | + } catch (Exception e) { |
| 56 | + |
| 57 | + } |
| 58 | + try { |
| 59 | + var yaml = new YamlConfiguration(); |
| 60 | + yaml.set("item" , get); |
| 61 | + yaml.save(compare); |
| 62 | + } catch (Exception e) { |
| 63 | + |
45 | 64 | } |
46 | | - var test = DataComponentAPI.api().adapter(new ItemStack(Material.DIAMOND)); |
47 | | - test.set(NMS.nms().customName(), Component.empty()); |
48 | | - System.out.println(test.serialize()); |
49 | 65 | } |
50 | 66 | } |
0 commit comments