mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 10:08:54 +00:00
Store the item loaders on the plugin instance
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user