Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ItemStackSerializer implements Serializable {
- private static final long serialVersionUID = 4423820056736136143L;
- private Map<String, Object> map;
- public ItemStackSerializer(ItemStack i) {
- map = i.serialize();
- }
- public ItemStackSerializer(ItemMeta i) {
- map = i.serialize();
- }
- public byte[] serialize() {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ObjectOutputStream os;
- try {
- os = new ObjectOutputStream(out);
- os.writeObject(this);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return out.toByteArray();
- }
- public Map<String, Object> getMap() {
- return map;
- }
- public static ItemStackSerializer deserialize(byte[] data) {
- try {
- ByteArrayInputStream in = new ByteArrayInputStream(data);
- ObjectInputStream is;
- is = new ObjectInputStream(in);
- return (ItemStackSerializer) is.readObject();
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement