Store the item loaders on the plugin instance

This commit is contained in:
Sn0wStorm
2020-11-08 01:50:17 +01:00
parent 74171f78c9
commit 3fa16414d0
7 changed files with 44 additions and 42 deletions
+3 -2
View File
@@ -1,5 +1,6 @@
package com.dre.brewery.recipe;
import com.dre.brewery.P;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@@ -285,7 +286,7 @@ public class CustomItem extends RecipeItem implements Ingredient {
}
// Needs to be called at Server start
public static void registerItemLoader() {
Ingredient.registerForItemLoader("CI", CustomItem::loadFrom);
public static void registerItemLoader(P p) {
p.registerForItemLoader("CI", CustomItem::loadFrom);
}
}
@@ -4,9 +4,6 @@ import org.bukkit.inventory.ItemStack;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
/**
* Item used in a BIngredients, inside BCauldron or Brew,
@@ -17,30 +14,6 @@ import java.util.function.Function;
*/
public interface Ingredient {
Map<String, Function<ItemLoader, Ingredient>> LOADERS = new HashMap<>();
/**
* Register a Static function as function that takes an ItemLoader, containing a DataInputStream.
* <p>Using the Stream it constructs a corresponding Ingredient for the chosen SaveID
*
* @param saveID The SaveID should be a small identifier like "AB"
* @param loadFct The Static Function that loads the Item, i.e.
* public static AItem loadFrom(ItemLoader loader)
*/
static void registerForItemLoader(String saveID, Function<ItemLoader, Ingredient> loadFct) {
LOADERS.put(saveID, loadFct);
}
/**
* Unregister the ItemLoader
*
* @param saveID the chosen SaveID
*/
static void unRegisterItemLoader(String saveID) {
LOADERS.remove(saveID);
}
/**
* Saves this Ingredient to the DataOutputStream.
* <p>The first data HAS to be storing the SaveID like:
+3 -2
View File
@@ -1,5 +1,6 @@
package com.dre.brewery.recipe;
import com.dre.brewery.P;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -164,8 +165,8 @@ public abstract class PluginItem extends RecipeItem implements Ingredient {
* Registers the chosen SaveID and the loading Method for loading from Brew or BCauldron.
* <p>Needs to be called at Server start.
*/
public static void registerItemLoader() {
Ingredient.registerForItemLoader("PI", PluginItem::loadFrom);
public static void registerItemLoader(P p) {
p.registerForItemLoader("PI", PluginItem::loadFrom);
}
+2 -2
View File
@@ -144,8 +144,8 @@ public class SimpleItem extends RecipeItem implements Ingredient {
}
// Needs to be called at Server start
public static void registerItemLoader() {
Ingredient.registerForItemLoader("SI", SimpleItem::loadFrom);
public static void registerItemLoader(P p) {
p.registerForItemLoader("SI", SimpleItem::loadFrom);
}
}