public abstract class AbstractHolidayItem { protected final ConfigurationSection section; protected final ItemsPlugin plugin; private final EventBus eventBus; // Cached values private final ItemStack item; protected AbstractHolidayItem(ItemsPlugin plugin, FileConfiguration configuration) { this.plugin = plugin; this.eventBus = plugin.getEventBus(); this.section = configuration.getConfigurationSection(getName()); this.item = createItem(); } public abstract String getName(); public ItemStack getItem() { return item.clone(); } public boolean isEnabled() { return section != null; } protected boolean matches(ItemStack item) { return plugin.getItemRegistry().get(item) == this; } protected void subscribe(Class eventClass, Consumer action) { if (!isEnabled()) { return; } eventBus.subscribe(eventClass, action); } private ItemStack createItem() { if (!isEnabled()) { return null; } ItemStack item = ItemBuilder.fromSection(section); ItemPDCWrapper wrapper = new ItemPDCWrapper(plugin, item); wrapper.setString("holiday-item", getName()); addTags(wrapper); return wrapper.getModifiedItem(); } protected void addTags(ItemPDCWrapper wrapper) { } }