001package com.ericlam.mc.eldgui.component;
002
003import com.ericlam.mc.eld.services.ItemStackService;
004import org.bukkit.inventory.ItemStack;
005
006/**
007 * 用於繼承組件,預設了很多事先的邏輯,方便創建
008 */
009public abstract class AbstractComponent implements Component {
010
011    protected final AttributeController attributeController;
012    protected final ItemStackService.ItemFactory itemFactory;
013
014    private Runnable updateHandler = () -> {};
015
016    public AbstractComponent(AttributeController attributeController, ItemStackService.ItemFactory itemFactory) {
017        this.attributeController = attributeController;
018        this.itemFactory = itemFactory;
019    }
020
021    @Override
022    public void setUpdateHandler(Runnable updateHandler) {
023        this.updateHandler = updateHandler;
024    }
025
026    protected void updateInventory(){
027        this.updateHandler.run();
028    }
029
030    @Override
031    public ItemStack getItem() {
032        return itemFactory.getItem();
033    }
034}