From 4e24411029bb5e21cbc91696503bab600cc7cd51 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 16 May 2021 16:21:36 +0800 Subject: Refactor PluginManager --- .../rei/api/common/display/DisplaySerializerRegistry.java | 4 ++-- .../me/shedaniel/rei/api/common/plugins/PluginManager.java | 6 +++--- .../rei/impl/client/config/entries/ReloadPluginsEntry.java | 2 +- .../rei/impl/client/gui/screen/ConfigReloadingScreen.java | 2 +- .../rei/impl/common/plugins/PluginManagerImpl.java | 13 +++++-------- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/me/shedaniel/rei/api/common/display/DisplaySerializerRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/display/DisplaySerializerRegistry.java index e2e063023..8b2c8c0e1 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/display/DisplaySerializerRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/display/DisplaySerializerRegistry.java @@ -38,7 +38,7 @@ public interface DisplaySerializerRegistry extends Reloadable> { * Registers a {@link DisplaySerializer} for serializing a {@link Display} for syncing across server-client, and * for serializing displays to disk for favorites. *

- * Since REI 6, all {@link me.shedaniel.rei.api.client.registry.display.DisplayCategory}s are required to register their serializers, + * Since REI 6, all {@link me.shedaniel.rei.api.client.registry.display.DisplayCategory} are required to register their serializers, * or mark themselves as unavailable for serialization. * * @param categoryId the category identifier of the display @@ -51,7 +51,7 @@ public interface DisplaySerializerRegistry extends Reloadable> { * Marks a {@link Display} as unavailable to sync across server-client, and * for serializing displays to disk for favorites. *

- * Since REI 6, all {@link me.shedaniel.rei.api.client.registry.display.DisplayCategory}s are required to register their serializers, + * Since REI 6, all {@link me.shedaniel.rei.api.client.registry.display.DisplayCategory} are required to register their serializers, * or mark themselves as unavailable for serialization. * * @param categoryId the category identifier of the display diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java index 2a74d0493..7a525c045 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java @@ -59,11 +59,11 @@ public interface PluginManager

> extends ParentReloadable< () -> () -> Arrays.asList(getInstance(), getServerInstance())); } - static boolean areAnyPluginsReloading() { - return CollectionUtils.anyMatch(getActiveInstances(), PluginManager::arePluginsReloading); + static boolean areAnyReloading() { + return CollectionUtils.anyMatch(getActiveInstances(), PluginManager::isReloading); } - boolean arePluginsReloading(); + boolean isReloading(); > T get(Class reloadableClass); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java index 94196c19e..cadbe569c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java @@ -49,7 +49,7 @@ public class ReloadPluginsEntry extends AbstractConfigListEntry { private AbstractWidget buttonWidget = new Button(0, 0, 0, 20, NarratorChatListener.NO_TITLE, button -> RoughlyEnoughItemsCore.reloadPlugins(null)) { @Override public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (PluginManager.areAnyPluginsReloading()) { + if (PluginManager.areAnyReloading()) { Screen screen = Minecraft.getInstance().screen; Minecraft.getInstance().setScreen(new ConfigReloadingScreen(() -> Minecraft.getInstance().setScreen(screen))); } else { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java index 17fede258..52a531acf 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java @@ -48,7 +48,7 @@ public class ConfigReloadingScreen extends Screen { @Override public void render(PoseStack matrices, int int_1, int int_2, float float_1) { this.renderDirtBackground(0); - if (!PluginManager.areAnyPluginsReloading()) { + if (!PluginManager.areAnyReloading()) { parent.run(); } drawCenteredString(matrices, this.font, I18n.get("text.rei.config.is.reloading"), this.width / 2, this.height / 2 - 50, 16777215); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index 249abc0c6..684be988e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -28,15 +28,12 @@ import com.google.common.base.Stopwatch; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.PluginView; import me.shedaniel.rei.api.common.plugins.REIPlugin; import me.shedaniel.rei.api.common.plugins.REIPluginProvider; import me.shedaniel.rei.api.common.registry.Reloadable; import me.shedaniel.rei.api.common.util.CollectionUtils; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.minecraft.Util; import org.apache.commons.lang3.tuple.MutablePair; import org.jetbrains.annotations.ApiStatus; @@ -54,7 +51,7 @@ public class PluginManagerImpl

> implements PluginManager< private final Map>, Reloadable> cache = new ConcurrentHashMap<>(); private final Class

pluginClass; private final UnaryOperator> view; - private boolean arePluginsLoading = false; + private boolean reloading = false; private final List> plugins = new ArrayList<>(); private final LongConsumer reloadDoneListener; @@ -74,8 +71,8 @@ public class PluginManagerImpl

> implements PluginManager< } @Override - public boolean arePluginsReloading() { - return arePluginsLoading; + public boolean isReloading() { + return reloading; } @Override @@ -154,7 +151,7 @@ public class PluginManagerImpl

> implements PluginManager< @Override public void startReload() { try { - arePluginsLoading = true; + reloading = true; long startTime = Util.getMillis(); MutablePair sectionData = new MutablePair<>(Stopwatch.createUnstarted(), ""); @@ -193,7 +190,7 @@ public class PluginManagerImpl

> implements PluginManager< } catch (Throwable throwable) { throwable.printStackTrace(); } finally { - arePluginsLoading = false; + reloading = false; } } } -- cgit