From a6223915426c0dcf5a47853deb7278cea0be2ee8 Mon Sep 17 00:00:00 2001 From: YufiriaMazenta Date: Tue, 5 Dec 2023 21:50:24 +0800 Subject: [PATCH] =?UTF-8?q?[1.6.0-dev2]=E9=87=8D=E5=86=99=E4=B8=80?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../craftorithm/recipe/DefRecipeManager.java | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/github/yufiriamazenta/craftorithm/recipe/DefRecipeManager.java diff --git a/build.gradle.kts b/build.gradle.kts index aae90671..8311f65a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -44,7 +44,7 @@ dependencies { } group = "com.github.yufiriamazenta" -version = "1.6.0-dev1" +version = "1.6.0-dev2" var pluginVersion: String = version.toString() + "-" + SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis()) java.sourceCompatibility = JavaVersion.VERSION_1_8 java.targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/src/main/java/com/github/yufiriamazenta/craftorithm/recipe/DefRecipeManager.java b/src/main/java/com/github/yufiriamazenta/craftorithm/recipe/DefRecipeManager.java new file mode 100644 index 00000000..86cd9334 --- /dev/null +++ b/src/main/java/com/github/yufiriamazenta/craftorithm/recipe/DefRecipeManager.java @@ -0,0 +1,85 @@ +package com.github.yufiriamazenta.craftorithm.recipe; + +import com.github.yufiriamazenta.craftorithm.recipe.custom.CustomRecipe; +import org.bukkit.Bukkit; +import org.bukkit.Keyed; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.CookingRecipe; +import org.bukkit.inventory.Recipe; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public enum DefRecipeManager { + + INSTANCE; + private final Map>> craftorithmRecipeMap; + + DefRecipeManager() { + craftorithmRecipeMap = new ConcurrentHashMap<>(); + } + + public void regRecipe(String recipeName, Recipe recipe) { + + } + + public void regShapedRecipe(String recipeName, ShapedRecipe recipe) { + RecipeType recipeType = RecipeType.SHAPED; + if (!craftorithmRecipeMap.containsKey(recipeType)) + craftorithmRecipeMap.put(recipeType, new ConcurrentHashMap<>()); + Map> recipeMap = craftorithmRecipeMap.get(recipeType); + if (!recipeMap.containsKey(recipeName)) + recipeMap.put(recipeName, new ArrayList<>()); + List recipeGroup = recipeMap.get(recipeName); + recipeGroup.add(recipe.getKey()); + Bukkit.addRecipe(recipe); + } + + public void regShapelessRecipe(String recipeName, ShapelessRecipe recipe) { + RecipeType recipeType = RecipeType.SHAPELESS; + if (!craftorithmRecipeMap.containsKey(recipeType)) + craftorithmRecipeMap.put(recipeType, new ConcurrentHashMap<>()); + Map> recipeMap = craftorithmRecipeMap.get(recipeType); + if (!recipeMap.containsKey(recipeName)) + recipeMap.put(recipeName, new ArrayList<>()); + List recipeGroup = recipeMap.get(recipeName); + recipeGroup.add(recipe.getKey()); + Bukkit.addRecipe(recipe); + } + + public void regCookingRecipe(String recipeName, CookingRecipe recipe) { + RecipeType recipeType = RecipeType.COOKING; + if (!craftorithmRecipeMap.containsKey(recipeType)) + craftorithmRecipeMap.put(recipeType, new ConcurrentHashMap<>()); + Map> recipeMap = craftorithmRecipeMap.get(recipeType); + if (!recipeMap.containsKey(recipeName)) + recipeMap.put(recipeName, new ArrayList<>()); + List recipeGroup = recipeMap.get(recipeName); + recipeGroup.add(recipe.getKey()); + Bukkit.addRecipe(recipe); + } + + public Map>> recipeMap() { + return craftorithmRecipeMap; + } + + public Recipe getRecipe(NamespacedKey namespacedKey) { + //TODO + return null; + } + + public NamespacedKey getRecipeKey(Recipe recipe) { + if (recipe == null) + return null; + if (recipe instanceof CustomRecipe) { + return ((CustomRecipe) recipe).key(); + } + return ((Keyed) recipe).getKey(); + } + + +}