如题
我看到很多插件都是直接将ItemStack塞进yml来储存物品
要如何才能做到那种效果?
我看到很多插件都是直接将ItemStack塞进yml来储存物品
要如何才能做到那种效果?
:L:dizzy::victory:
本帖最后由 疾风暗影 于 2020-8-18 14:49 编辑
直接set
复制代码
直接set
- getConfig().set("itemstack", new ItemStack(Material.STONE, 1));
- ItemStack i = getConfig().getItemStack("itemstack");
- // 序列化ItemStack
- public static String GetItemData(ItemStack item) {
- String a;
- try {
- a = new StreamSerializer().serializeItemStack(item);
- } catch (Exception e) {
- a = null;
- }
- return a;
- }
-
- // 反序列化ItemStack
- public static ItemStack GetItemStack(String data) {
- try {
- return new StreamSerializer().deserializeItemStack(data);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
我是通过protocollib来做的