Advertisement
Guest User

Untitled

a guest
Apr 13th, 2017
30
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None
  1. public static void doStuff2(Player player) throws IOException {
  2.         // serialize
  3.         StringWriter sink = new StringWriter();
  4.         GsonConfigurationLoader loader = GsonConfigurationLoader.builder().setSink(() -> new BufferedWriter(sink)).build();
  5.  
  6.         DataView container = player.getItemInHand(HandTypes.MAIN_HAND).get().toContainer();
  7.         loader.save(DataTranslators.CONFIGURATION_NODE.translate(container));
  8.  
  9.         // debug
  10.         String data = sink.toString();
  11.         System.out.println(data);
  12.  
  13.         // deserialize
  14.         StringReader source = new StringReader(data);
  15.         GsonConfigurationLoader loader2 = GsonConfigurationLoader.builder().setSource(() -> new BufferedReader(source)).build();
  16.         ConfigurationNode node = loader2.load();
  17.  
  18.         DataView container2 = DataTranslators.CONFIGURATION_NODE.translate(node);
  19.         ItemStack itemStack = Sponge.getDataManager().deserialize(ItemStack.class, container2).get();
  20.  
  21.         player.getInventory().offer(itemStack);
  22.     }
Advertisement
RAW Paste Data Copied
Advertisement