Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. public class ItemStackSerializer implements Serializable {
  2.  
  3. private static final long serialVersionUID = 4423820056736136143L;
  4.  
  5. private Map<String, Object> map;
  6.  
  7. public ItemStackSerializer(ItemStack i) {
  8. map = i.serialize();
  9.  
  10. }
  11.  
  12. public ItemStackSerializer(ItemMeta i) {
  13. map = i.serialize();
  14.  
  15. }
  16.  
  17.  
  18.  
  19. public byte[] serialize() {
  20.  
  21. ByteArrayOutputStream out = new ByteArrayOutputStream();
  22. ObjectOutputStream os;
  23. try {
  24. os = new ObjectOutputStream(out);
  25. os.writeObject(this);
  26. } catch (IOException e) {
  27. e.printStackTrace();
  28. }
  29. return out.toByteArray();
  30. }
  31.  
  32. public Map<String, Object> getMap() {
  33. return map;
  34. }
  35.  
  36. public static ItemStackSerializer deserialize(byte[] data) {
  37. try {
  38. ByteArrayInputStream in = new ByteArrayInputStream(data);
  39. ObjectInputStream is;
  40. is = new ObjectInputStream(in);
  41. return (ItemStackSerializer) is.readObject();
  42. } catch (IOException | ClassNotFoundException e) {
  43. e.printStackTrace();
  44. return null;
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement