Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void doStuff(ConfigurationLoader<CommentedConfigurationNode> loader, Player player) throws IOException {
- ItemStackSnapshot itemStackSnapshot = ItemStack.builder()
- .quantity(1)
- .itemType(ItemTypes.WRITTEN_BOOK)
- .add(Keys.DISPLAY_NAME, Text.of("Book Title One"))
- .add(Keys.BOOK_AUTHOR, Text.of("Author One"))
- .add(Keys.BOOK_PAGES, Collections.singletonList(Text.of("Page Text One")))
- .build().createSnapshot();
- // To node
- ConfigurationNode itemStackNode = DataTranslators.CONFIGURATION_NODE.translate(itemStackSnapshot.toContainer());
- loader.save(itemStackNode);
- // From node
- DataContainer dataContainer = DataTranslators.CONFIGURATION_NODE.translate(loader.load());
- ItemStackSnapshot deserializedItemStackSnapshot = Sponge.getDataManager()
- .deserialize(ItemStackSnapshot.class, dataContainer).orElse(null);
- player.getInventory().offer(deserializedItemStackSnapshot.createStack());
- }
Advertisement
Add Comment
Please, Sign In to add comment