From 6c602e022e2316a553bdbcad09e84e93fa6273fc Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Fri, 4 Mar 2022 08:22:51 +0200 Subject: Cleaned up type activity checks --- .../fabric/citresewn/api/CITTypeContainer.java | 17 ++++++++++++++++- .../shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java index a9666d3..5aa727d 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java @@ -1,7 +1,9 @@ package shcm.shsupercm.fabric.citresewn.api; +import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; import shcm.shsupercm.fabric.citresewn.cit.CIT; import shcm.shsupercm.fabric.citresewn.cit.CITType; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import java.util.List; import java.util.function.Supplier; @@ -12,16 +14,29 @@ public abstract class CITTypeContainer implements CITDisposab public final Supplier createType; public final String id; + protected boolean empty = true; + public CITTypeContainer(Class type, Supplier createType, String id) { this.type = type; this.createType = createType; this.id = id; } - public abstract void load(List> parsedCITs); + protected abstract void load(List> parsedCITs); @SuppressWarnings("unchecked") public final void loadUntyped(List parsedCITs) { + if (!parsedCITs.isEmpty()) + empty = false; load((List>) parsedCITs); } + + public final void unload() { + dispose(); + empty = true; + } + + public boolean active() { + return !empty && CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive(); + } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java index f54cc54..c7ca38c 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java @@ -61,6 +61,6 @@ public class ActiveCITs implements CITDisposable { private ActiveCITs() {} disposable.dispose(); for (CITTypeContainer typeContainer : CITRegistry.TYPES.values()) - typeContainer.dispose(); + typeContainer.unload(); } } -- cgit