Guest User

Untitled

a guest
Apr 13th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. public static void doStuff(ConfigurationLoader<CommentedConfigurationNode> loader, Player player) throws IOException {
  2.         ItemStackSnapshot itemStackSnapshot = ItemStack.builder()
  3.                 .quantity(1)
  4.                 .itemType(ItemTypes.WRITTEN_BOOK)
  5.                 .add(Keys.DISPLAY_NAME, Text.of("Book Title One"))
  6.                 .add(Keys.BOOK_AUTHOR, Text.of("Author One"))
  7.                 .add(Keys.BOOK_PAGES, Collections.singletonList(Text.of("Page Text One")))
  8.                 .build().createSnapshot();
  9.  
  10.         // To node
  11.         ConfigurationNode itemStackNode = DataTranslators.CONFIGURATION_NODE.translate(itemStackSnapshot.toContainer());
  12.         loader.save(itemStackNode);
  13.  
  14.         // From node
  15.         DataContainer dataContainer = DataTranslators.CONFIGURATION_NODE.translate(loader.load());
  16.         ItemStackSnapshot deserializedItemStackSnapshot = Sponge.getDataManager()
  17.                 .deserialize(ItemStackSnapshot.class, dataContainer).orElse(null);
  18.  
  19.         player.getInventory().offer(deserializedItemStackSnapshot.createStack());
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment