diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-03-06 17:42:04 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-03-06 17:42:04 +0200 |
commit | 2356c6bb055079ef03cfd26e9d505ab9cea3960d (patch) | |
tree | 4649c1ee2779b4997d1d386222e523d82786f45f /src/main | |
parent | 526a5f1da2354d328be10c4d6d2f58b3b73e0d20 (diff) | |
download | CITResewn-2356c6bb055079ef03cfd26e9d505ab9cea3960d.tar.gz CITResewn-2356c6bb055079ef03cfd26e9d505ab9cea3960d.tar.bz2 CITResewn-2356c6bb055079ef03cfd26e9d505ab9cea3960d.zip |
Modified global properties api a bit
Diffstat (limited to 'src/main')
3 files changed, 21 insertions, 26 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java index a3d78ae..05495af 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java @@ -2,6 +2,8 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +import javax.annotation.Nullable; + /** * @see #globalProperty(String, PropertyValue) */ @@ -16,10 +18,9 @@ public interface CITGlobalProperties { /** * Invoked before CIT parsing for any global property name associated with the handler's modid.<br> * May be called multiple times for a key to overwrite its global property with higher-priority resourcepacks.<br> - * Handlers should take care to reset back any changes global properties make by listening to CIT disposal. - * @see CITDisposable#dispose() + * When unloading resourcepacks(usually before reloading), all keys that were invoked in the previous load will get called again with a null value to allow for disposal. * @param key name of the property key stripped of its modid - * @param value the value it's been set to + * @param value the value it's been set to or null if resetting */ - void globalProperty(String key, PropertyValue value) throws Exception; + void globalProperty(String key, @Nullable PropertyValue value) throws Exception; } 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 5270d20..82f341f 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java @@ -62,9 +62,16 @@ public class ActiveCITs { private ActiveCITs() {} */ public static void load(ResourceManager resourceManager, Profiler profiler) { profiler.push("citresewn:disposing"); - disposeAll(); + for (CITDisposable disposable : FabricLoader.getInstance().getEntrypoints(CITDisposable.ENTRYPOINT, CITDisposable.class)) + disposable.dispose(); + + for (CITTypeContainer<? extends CITType> typeContainer : CITRegistry.TYPES.values()) + typeContainer.unload(); + if (active != null) { - //todo send reset calls to global properties with null value + active.globalProperties.properties.replaceAll((key, value) -> Set.of()); + active.globalProperties.callHandlers(); + active = null; } @@ -96,17 +103,4 @@ public class ActiveCITs { private ActiveCITs() {} if (!cits.isEmpty()) ActiveCITs.active = active; } - - /** - * Cleans up any registered disposable element. - * @see CITDisposable - * @see CITTypeContainer - */ - public static void disposeAll() { - for (CITDisposable disposable : FabricLoader.getInstance().getEntrypoints(CITDisposable.ENTRYPOINT, CITDisposable.class)) - disposable.dispose(); - - for (CITTypeContainer<? extends CITType> typeContainer : CITRegistry.TYPES.values()) - typeContainer.unload(); - } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java index c16242f..3e93b07 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java @@ -19,6 +19,7 @@ import java.util.Set; /** * Property group representation of the global cit.properties file. + * @see CITGlobalProperties * @see PackParser#loadGlobalProperties(ResourceManager, GlobalProperties) */ public class GlobalProperties extends PropertyGroup { @@ -59,13 +60,12 @@ public class GlobalProperties extends PropertyGroup { for (PropertyValue value : entry.getValue()) lastValue = value; - if (lastValue != null) - try { - container.getEntrypoint().globalProperty(entry.getKey().path(), lastValue); - } catch (Exception e) { - CITResewn.logErrorLoading("Errored while parsing global properties: Line " + lastValue.position() + " of " + lastValue.propertiesIdentifier() + " in " + lastValue.packName()); - e.printStackTrace(); - } + try { + container.getEntrypoint().globalProperty(entry.getKey().path(), lastValue); + } catch (Exception e) { + CITResewn.logErrorLoading(lastValue == null ? "Errored while disposing global properties" : "Errored while parsing global properties: Line " + lastValue.position() + " of " + lastValue.propertiesIdentifier() + " in " + lastValue.packName()); + e.printStackTrace(); + } } } } |