package net.glowstone.io.entity;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import net.glowstone.entity.objects.GlowMinecart;
import net.glowstone.io.nbt.NbtSerialization;
import net.glowstone.util.nbt.CompoundTag;
import org.bukkit.Location;
import org.bukkit.inventory.InventoryHolder;

public class MinecartStore extends EntityStore<GlowMinecart> {

    private GlowMinecart.MinecartType type;

    public MinecartStore(GlowMinecart.MinecartType type) {
        super((Class<GlowMinecart>) type.getMinecartClass(), type.getEntityType());
        this.type = type;
    }

    @Override
    public GlowMinecart createEntity(Location location, CompoundTag compound) {
        try {
            Constructor<? extends GlowMinecart> constructor = type.getMinecartClass()
                .getConstructor(Location.class);
            return constructor.newInstance(location);
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void load(GlowMinecart entity, CompoundTag tag) {
        super.load(entity, tag);
        if (entity instanceof InventoryHolder) {
            InventoryHolder inv = (InventoryHolder) entity;
            if (inv.getInventory() != null) {
                inv.getInventory().setContents(NbtSerialization
                    .readInventory(tag.getCompoundList("Items"), 0, inv.getInventory().getSize()));
            }
        }
        // todo
    }

    @Override
    public void save(GlowMinecart entity, CompoundTag tag) {
        super.save(entity, tag);
        if (entity instanceof InventoryHolder) {
            InventoryHolder inv = (InventoryHolder) entity;
            if (inv.getInventory() != null) {
                tag.putCompoundList("Items",
                    NbtSerialization.writeInventory(inv.getInventory().getContents(), 0));
            }
        }
        // todo
    }
}

package net.glowstone.io.entity;

import java.util.function.Function;
import net.glowstone.entity.objects.GlowMinecart;
import net.glowstone.io.nbt.NbtSerialization;
import net.glowstone.util.nbt.CompoundTag;
import org.bukkit.Location;
import org.bukkit.inventory.InventoryHolder;

public class MinecartStore extends EntityStore<GlowMinecart> {

    private GlowMinecart.MinecartType type;

    public MinecartStore(GlowMinecart.MinecartType type) {
        super((Class<GlowMinecart>) type.getMinecartClass(), type.getEntityType());
        this.type = type;
    }

    @Override
    public GlowMinecart createEntity(Location location, CompoundTag compound) {
        Function<? super Location, ? extends GlowMinecart> creator = type.getCreator();
        return creator == null ? null : creator.apply(location);
    }

    @Override
    public void load(GlowMinecart entity, CompoundTag tag) {
        super.load(entity, tag);
        if (entity instanceof InventoryHolder) {
            InventoryHolder inv = (InventoryHolder) entity;
            if (inv.getInventory() != null) {
                inv.getInventory().setContents(NbtSerialization
                    .readInventory(tag.getCompoundList("Items"), 0, inv.getInventory().getSize()));
            }
        }
        // todo
    }

    @Override
    public void save(GlowMinecart entity, CompoundTag tag) {
        super.save(entity, tag);
        if (entity instanceof InventoryHolder) {
            InventoryHolder inv = (InventoryHolder) entity;
            if (inv.getInventory() != null) {
                tag.putCompoundList("Items",
                    NbtSerialization.writeInventory(inv.getInventory().getContents(), 0));
            }
        }
        // todo
    }
}

Fix CheckStyle issues in io/entity/MinecartStore.java (#728)