diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-03-04 08:22:51 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-03-04 08:22:51 +0200 |
commit | 6c602e022e2316a553bdbcad09e84e93fa6273fc (patch) | |
tree | 5e8265e43d8e57977532eb8fb6b01b50ee1a98c5 /src/main | |
parent | 5a08a70cf1d1c21992b21e484330fff54b744051 (diff) | |
download | CITResewn-6c602e022e2316a553bdbcad09e84e93fa6273fc.tar.gz CITResewn-6c602e022e2316a553bdbcad09e84e93fa6273fc.tar.bz2 CITResewn-6c602e022e2316a553bdbcad09e84e93fa6273fc.zip |
Cleaned up type activity checks
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java | 17 | ||||
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java | 2 |
2 files changed, 17 insertions, 2 deletions
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<T extends CITType> implements CITDisposab public final Supplier<T> createType; public final String id; + protected boolean empty = true; + public CITTypeContainer(Class<T> type, Supplier<T> createType, String id) { this.type = type; this.createType = createType; this.id = id; } - public abstract void load(List<CIT<T>> parsedCITs); + protected abstract void load(List<CIT<T>> parsedCITs); @SuppressWarnings("unchecked") public final void loadUntyped(List<?> parsedCITs) { + if (!parsedCITs.isEmpty()) + empty = false; load((List<CIT<T>>) 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<? extends CITType> typeContainer : CITRegistry.TYPES.values()) - typeContainer.dispose(); + typeContainer.unload(); } } |