aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-07-31 23:17:19 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-07-31 23:17:19 +0800
commit59321c5c7c650dab63328d13180a4468cbdb5103 (patch)
tree0f35133fcac7f05b5171521570da98211d37dc13 /src/main/java/me
parent3e5df51929fe5204ce01e993560238e3d58a1faa (diff)
downloadRoughlyEnoughItems-59321c5c7c650dab63328d13180a4468cbdb5103.tar.gz
RoughlyEnoughItems-59321c5c7c650dab63328d13180a4468cbdb5103.tar.bz2
RoughlyEnoughItems-59321c5c7c650dab63328d13180a4468cbdb5103.zip
Better plugin loading
Diffstat (limited to 'src/main/java/me')
-rw-r--r--src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java14
-rw-r--r--src/main/java/me/shedaniel/rei/api/REIPluginEntry.java42
-rw-r--r--src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java53
-rw-r--r--src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java35
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java11
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java11
6 files changed, 106 insertions, 60 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
index f18f75963..36652cf4d 100644
--- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
+++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
@@ -10,6 +10,7 @@ import com.google.common.collect.Maps;
import me.shedaniel.cloth.api.ClientUtils;
import me.shedaniel.cloth.hooks.ClothClientHooks;
import me.shedaniel.rei.api.*;
+import me.shedaniel.rei.api.plugins.REIPluginV0;
import me.shedaniel.rei.client.*;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.gui.widget.ItemListOverlay;
@@ -87,10 +88,9 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
* @deprecated Check REI wiki
*/
@Deprecated
- public static REIPluginEntry registerPlugin(Identifier identifier, REIPluginEntry plugin) {
- plugins.put(identifier, plugin);
- RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered plugin %s from %s", identifier.toString(), plugin.getClass().getSimpleName());
- plugin.onFirstLoad(getPluginDisabler());
+ public static REIPluginEntry registerPlugin(REIPluginEntry plugin) {
+ plugins.put(plugin.getPluginIdentifier(), plugin);
+ RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered plugin %s from %s", plugin.getPluginIdentifier().toString(), plugin.getClass().getSimpleName());
return plugin;
}
@@ -147,7 +147,11 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
private void discoverPluginEntries() {
for(REIPluginEntry reiPlugin : FabricLoader.getInstance().getEntrypoints("rei_plugins", REIPluginEntry.class)) {
try {
- registerPlugin(reiPlugin.getPluginIdentifier(), reiPlugin);
+ if (!REIPluginV0.class.isAssignableFrom(reiPlugin.getClass()))
+ throw new IllegalArgumentException("REI plugin is too old!");
+ registerPlugin(reiPlugin);
+ if (reiPlugin instanceof REIPluginV0)
+ ((REIPluginV0) reiPlugin).onFirstLoad(getPluginDisabler());
} catch (Exception e) {
e.printStackTrace();
RoughlyEnoughItemsCore.LOGGER.error("[REI] Can't load REI plugins from %s: %s", reiPlugin.getClass(), e.getLocalizedMessage());
diff --git a/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java b/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java
index 2d0b2f236..8651c6751 100644
--- a/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java
+++ b/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java
@@ -13,48 +13,6 @@ import net.minecraft.util.Identifier;
public interface REIPluginEntry {
/**
- * On register of the plugin
- *
- * @param pluginDisabler the helper class to disable other plugins
- */
- default void onFirstLoad(PluginDisabler pluginDisabler) {}
-
- /**
- * Registers items on the item panel
- *
- * @param itemRegistry the helper class
- */
- default void registerItems(ItemRegistry itemRegistry) {}
-
- /**
- * Registers categories
- *
- * @param recipeHelper the helper class
- */
- default void registerPluginCategories(RecipeHelper recipeHelper) {}
-
- /**
- * Registers displays for categories
- *
- * @param recipeHelper the helper class
- */
- default void registerRecipeDisplays(RecipeHelper recipeHelper) {}
-
- /**
- * Registers bounds handlers
- *
- * @param displayHelper the helper class
- */
- default void registerBounds(DisplayHelper displayHelper) {}
-
- /**
- * Register other stuff
- *
- * @param recipeHelper the helper class
- */
- default void registerOthers(RecipeHelper recipeHelper) {}
-
- /**
* Gets the priority of the plugin.
*
* @return the priority
diff --git a/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java b/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java
new file mode 100644
index 000000000..414f6ea3e
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java
@@ -0,0 +1,53 @@
+package me.shedaniel.rei.api.plugins;
+
+import me.shedaniel.rei.api.*;
+import net.fabricmc.loader.api.SemanticVersion;
+import net.fabricmc.loader.util.version.VersionParsingException;
+
+public interface REIPluginV0 extends REIPluginEntry {
+
+ SemanticVersion getMinimumVersion() throws VersionParsingException;
+
+ /**
+ * On register of the plugin
+ *
+ * @param pluginDisabler the helper class to disable other plugins
+ */
+ default void onFirstLoad(PluginDisabler pluginDisabler) {}
+
+ /**
+ * Registers items on the item panel
+ *
+ * @param itemRegistry the helper class
+ */
+ default void registerItems(ItemRegistry itemRegistry) {}
+
+ /**
+ * Registers categories
+ *
+ * @param recipeHelper the helper class
+ */
+ default void registerPluginCategories(RecipeHelper recipeHelper) {}
+
+ /**
+ * Registers displays for categories
+ *
+ * @param recipeHelper the helper class
+ */
+ default void registerRecipeDisplays(RecipeHelper recipeHelper) {}
+
+ /**
+ * Registers bounds handlers
+ *
+ * @param displayHelper the helper class
+ */
+ default void registerBounds(DisplayHelper displayHelper) {}
+
+ /**
+ * Register other stuff
+ *
+ * @param recipeHelper the helper class
+ */
+ default void registerOthers(RecipeHelper recipeHelper) {}
+
+}
diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
index c6deab1ef..492aa8b7c 100644
--- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
+++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
@@ -9,6 +9,10 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.api.*;
+import me.shedaniel.rei.api.plugins.REIPluginV0;
+import net.fabricmc.loader.api.FabricLoader;
+import net.fabricmc.loader.api.SemanticVersion;
+import net.fabricmc.loader.api.Version;
import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Recipe;
@@ -239,19 +243,30 @@ public class RecipeHelperImpl implements RecipeHelper {
Collections.reverse(plugins);
RoughlyEnoughItemsCore.getItemRegisterer().getModifiableItemList().clear();
PluginDisabler pluginDisabler = RoughlyEnoughItemsCore.getPluginDisabler();
+ Version reiVersion = FabricLoader.getInstance().getModContainer("roughlyenoughitems").get().getMetadata().getVersion();
+ if (!(reiVersion instanceof SemanticVersion))
+ RoughlyEnoughItemsCore.LOGGER.warn("[REI] Roughly Enough Items is not using semantic versioning, will be ignoring plugins' minimum versions!");
plugins.forEach(plugin -> {
Identifier identifier = plugin.getPluginIdentifier();
try {
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_ITEMS))
- plugin.registerItems(RoughlyEnoughItemsCore.getItemRegisterer());
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_CATEGORIES))
- plugin.registerPluginCategories(this);
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_RECIPE_DISPLAYS))
- plugin.registerRecipeDisplays(this);
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_BOUNDS))
- plugin.registerBounds(RoughlyEnoughItemsCore.getDisplayHelper());
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_OTHERS))
- plugin.registerOthers(this);
+ if (plugin instanceof REIPluginV0) {
+ if (reiVersion instanceof SemanticVersion)
+ if (((REIPluginV0) plugin).getMinimumVersion().compareTo((SemanticVersion) reiVersion) > 0) {
+ throw new IllegalStateException("Requires " + ((REIPluginV0) plugin).getMinimumVersion().getFriendlyString() + " REI version!");
+ }
+ if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_CATEGORIES))
+ ((REIPluginV0) plugin).registerPluginCategories(this);
+ if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_RECIPE_DISPLAYS))
+ ((REIPluginV0) plugin).registerRecipeDisplays(this);
+ if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_BOUNDS))
+ ((REIPluginV0) plugin).registerBounds(RoughlyEnoughItemsCore.getDisplayHelper());
+ if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_OTHERS))
+ ((REIPluginV0) plugin).registerOthers(this);
+ if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_ITEMS))
+ ((REIPluginV0) plugin).registerItems(RoughlyEnoughItemsCore.getItemRegisterer());
+ } else {
+ throw new IllegalStateException("Invaild Plugin Class!");
+ }
} catch (Exception e) {
RoughlyEnoughItemsCore.LOGGER.error("[REI] " + identifier.toString() + " plugin failed to load!", e);
}
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java
index 3554b6fb9..956322a5f 100644
--- a/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java
+++ b/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java
@@ -8,12 +8,14 @@ package me.shedaniel.rei.plugin;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.api.PluginDisabler;
import me.shedaniel.rei.api.PluginFunction;
-import me.shedaniel.rei.api.REIPluginEntry;
import me.shedaniel.rei.api.RecipeHelper;
+import me.shedaniel.rei.api.plugins.REIPluginV0;
import me.shedaniel.rei.plugin.autocrafting.*;
+import net.fabricmc.loader.api.SemanticVersion;
+import net.fabricmc.loader.util.version.VersionParsingException;
import net.minecraft.util.Identifier;
-public class DefaultAutoCraftingPlugin implements REIPluginEntry {
+public class DefaultAutoCraftingPlugin implements REIPluginV0 {
public static final Identifier PLUGIN = new Identifier("roughlyenoughitems", "default_auto_crafting_plugin");
@@ -23,6 +25,11 @@ public class DefaultAutoCraftingPlugin implements REIPluginEntry {
}
@Override
+ public SemanticVersion getMinimumVersion() throws VersionParsingException {
+ return SemanticVersion.parse("2.10");
+ }
+
+ @Override
public void onFirstLoad(PluginDisabler pluginDisabler) {
if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_ITEMS);
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
index 80dde2db0..5cd22e0bb 100644
--- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
+++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
@@ -9,6 +9,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.api.*;
+import me.shedaniel.rei.api.plugins.REIPluginV0;
import me.shedaniel.rei.client.ScreenHelper;
import me.shedaniel.rei.gui.RecipeViewingScreen;
import me.shedaniel.rei.gui.VillagerRecipeViewingScreen;
@@ -30,6 +31,9 @@ import me.shedaniel.rei.plugin.smoking.DefaultSmokingCategory;
import me.shedaniel.rei.plugin.smoking.DefaultSmokingDisplay;
import me.shedaniel.rei.plugin.stonecutting.DefaultStoneCuttingCategory;
import me.shedaniel.rei.plugin.stonecutting.DefaultStoneCuttingDisplay;
+import net.fabricmc.loader.api.SemanticVersion;
+import net.fabricmc.loader.util.version.SemanticVersionImpl;
+import net.fabricmc.loader.util.version.VersionParsingException;
import net.minecraft.block.ComposterBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.*;
@@ -49,7 +53,7 @@ import java.awt.*;
import java.util.List;
import java.util.*;
-public class DefaultPlugin implements REIPluginEntry {
+public class DefaultPlugin implements REIPluginV0 {
public static final Identifier CRAFTING = new Identifier("minecraft", "plugins/crafting");
public static final Identifier SMELTING = new Identifier("minecraft", "plugins/smelting");
@@ -78,6 +82,11 @@ public class DefaultPlugin implements REIPluginEntry {
}
@Override
+ public SemanticVersion getMinimumVersion() throws VersionParsingException {
+ return SemanticVersion.parse("2.10");
+ }
+
+ @Override
public void onFirstLoad(PluginDisabler pluginDisabler) {
if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_ITEMS);