From 113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 27 Aug 2021 05:26:06 +0800 Subject: Add hints for if REI does not initialize properly --- .../api/common/entry/type/EntryTypeRegistry.java | 2 +- .../rei/api/common/registry/ParentReloadable.java | 20 ++++++++++++--- .../rei/api/common/registry/ReloadStage.java | 29 ++++++++++++++++++++++ .../rei/api/common/registry/Reloadable.java | 22 ++++++++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/common/registry/ReloadStage.java (limited to 'api/src') diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryTypeRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryTypeRegistry.java index a5928679c..de413d6ab 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryTypeRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryTypeRegistry.java @@ -63,7 +63,7 @@ public interface EntryTypeRegistry extends Reloadable> { } /** - * Registers a entry type, with its entry definition. + * Registers an entry type, with its entry definition. * * @param id the identifier of the entry type * @param definition the definition of the entry diff --git a/api/src/main/java/me/shedaniel/rei/api/common/registry/ParentReloadable.java b/api/src/main/java/me/shedaniel/rei/api/common/registry/ParentReloadable.java index 48cce495e..0a3a8e185 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/registry/ParentReloadable.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/registry/ParentReloadable.java @@ -34,15 +34,29 @@ public interface ParentReloadable

> extends Reloadable

@Override default void startReload() { - for (Reloadable

reloadable : getReloadables()) { - reloadable.startReload(); + for (ReloadStage stage : ReloadStage.values()) { + startReload(stage); } } @Override default void endReload() { + for (ReloadStage stage : ReloadStage.values()) { + endReload(stage); + } + } + + @Override + default void startReload(ReloadStage stage) { + for (Reloadable

reloadable : getReloadables()) { + reloadable.startReload(stage); + } + } + + @Override + default void endReload(ReloadStage stage) { for (Reloadable

reloadable : getReloadables()) { - reloadable.endReload(); + reloadable.endReload(stage); } } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/registry/ReloadStage.java b/api/src/main/java/me/shedaniel/rei/api/common/registry/ReloadStage.java new file mode 100644 index 000000000..cb1deff3c --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/registry/ReloadStage.java @@ -0,0 +1,29 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.common.registry; + +public enum ReloadStage { + START, + END, +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/registry/Reloadable.java b/api/src/main/java/me/shedaniel/rei/api/common/registry/Reloadable.java index d472ad72d..67b7174a5 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/registry/Reloadable.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/registry/Reloadable.java @@ -27,10 +27,26 @@ import me.shedaniel.rei.api.common.plugins.REIPlugin; @FunctionalInterface public interface Reloadable

> { + default ReloadStage getStage() { + return ReloadStage.END; + } + void startReload(); + default void startReload(ReloadStage stage) { + if (stage == getStage()) { + startReload(); + } + } + default void endReload() {} + default void endReload(ReloadStage stage) { + if (stage == getStage()) { + endReload(); + } + } + /** * Accepts a {@link REIPlugin} * @@ -38,6 +54,12 @@ public interface Reloadable

> { */ default void acceptPlugin(P plugin) {} + default void acceptPlugin(P plugin, ReloadStage stage) { + if (stage == getStage()) { + acceptPlugin(plugin); + } + } + /** * Returns whether {@link Reloadable#acceptPlugin(REIPlugin)} should be done in parallel. * -- cgit