mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-23 04:47:34 +01:00
1.12 hotfix
This commit is contained in:
parent
76af2814ce
commit
b30d2ea70e
@ -58,8 +58,6 @@ import net.Indyuce.mmoitems.manager.DropTableManager;
|
|||||||
import net.Indyuce.mmoitems.manager.EntityManager;
|
import net.Indyuce.mmoitems.manager.EntityManager;
|
||||||
import net.Indyuce.mmoitems.manager.ItemManager;
|
import net.Indyuce.mmoitems.manager.ItemManager;
|
||||||
import net.Indyuce.mmoitems.manager.PluginUpdateManager;
|
import net.Indyuce.mmoitems.manager.PluginUpdateManager;
|
||||||
import net.Indyuce.mmoitems.manager.RecipeManager;
|
|
||||||
import net.Indyuce.mmoitems.manager.RecipeManagerLegacy;
|
|
||||||
import net.Indyuce.mmoitems.manager.SetManager;
|
import net.Indyuce.mmoitems.manager.SetManager;
|
||||||
import net.Indyuce.mmoitems.manager.StatManager;
|
import net.Indyuce.mmoitems.manager.StatManager;
|
||||||
import net.Indyuce.mmoitems.manager.TierManager;
|
import net.Indyuce.mmoitems.manager.TierManager;
|
||||||
@ -67,6 +65,9 @@ import net.Indyuce.mmoitems.manager.TypeManager;
|
|||||||
import net.Indyuce.mmoitems.manager.UpdaterManager;
|
import net.Indyuce.mmoitems.manager.UpdaterManager;
|
||||||
import net.Indyuce.mmoitems.manager.UpgradeManager;
|
import net.Indyuce.mmoitems.manager.UpgradeManager;
|
||||||
import net.Indyuce.mmoitems.manager.WorldGenManager;
|
import net.Indyuce.mmoitems.manager.WorldGenManager;
|
||||||
|
import net.Indyuce.mmoitems.manager.recipe.RecipeManager;
|
||||||
|
import net.Indyuce.mmoitems.manager.recipe.RecipeManagerDefault;
|
||||||
|
import net.Indyuce.mmoitems.manager.recipe.RecipeManagerLegacy;
|
||||||
import net.mmogroup.mmolib.MMOLib;
|
import net.mmogroup.mmolib.MMOLib;
|
||||||
import net.mmogroup.mmolib.version.SpigotPlugin;
|
import net.mmogroup.mmolib.version.SpigotPlugin;
|
||||||
|
|
||||||
@ -235,7 +236,7 @@ public class MMOItems extends JavaPlugin {
|
|||||||
// advanced recipes
|
// advanced recipes
|
||||||
getLogger().log(Level.INFO, "Loading recipes, please wait...");
|
getLogger().log(Level.INFO, "Loading recipes, please wait...");
|
||||||
recipeManager = MMOLib.plugin.getVersion().isStrictlyHigher(1, 12) ?
|
recipeManager = MMOLib.plugin.getVersion().isStrictlyHigher(1, 12) ?
|
||||||
new RecipeManager() : new RecipeManagerLegacy();
|
new RecipeManagerDefault() : new RecipeManagerLegacy();
|
||||||
|
|
||||||
// commands
|
// commands
|
||||||
getCommand("mmoitems").setExecutor(new MMOItemsCommand());
|
getCommand("mmoitems").setExecutor(new MMOItemsCommand());
|
||||||
|
@ -0,0 +1,116 @@
|
|||||||
|
package net.Indyuce.mmoitems.manager.recipe;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.inventory.Recipe;
|
||||||
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
|
|
||||||
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
|
import net.Indyuce.mmoitems.api.MMORecipeChoice;
|
||||||
|
import net.Indyuce.mmoitems.api.Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
* When Bukkit changes their 'RecipeChoice.ExactChoice' API
|
||||||
|
* we can remove the suppressed warnings, but right now it works
|
||||||
|
* despite being marked as deprecated. It is just a
|
||||||
|
*/
|
||||||
|
public abstract class RecipeManager {
|
||||||
|
protected List<Recipe> loadedRecipes = new ArrayList<>();
|
||||||
|
protected Collection<NamespacedKey> keys = new ArrayList<>();
|
||||||
|
|
||||||
|
public RecipeManager() { load(); }
|
||||||
|
|
||||||
|
protected abstract void load();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Some day I want to get proper rid of the AWB
|
||||||
|
* but right now we don't want to force players to update
|
||||||
|
* their recipes right off the bat.
|
||||||
|
*/
|
||||||
|
protected void registerAdvancedWorkbenchRecipe(Type type, String id, FileConfiguration config) {
|
||||||
|
MMOItems.plugin.getLogger().warning("Found deprecated adv. recipe for " + id + ". Converting it to the new system...");
|
||||||
|
MMOItems.plugin.getLogger().warning("It is recommended to update your recipes!");
|
||||||
|
|
||||||
|
NamespacedKey key = getRecipeKey(type, id, "advanced", "deprecated");
|
||||||
|
ShapedRecipe recipe = new ShapedRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
||||||
|
recipe.shape("012", "345", "678");
|
||||||
|
|
||||||
|
setIngredientOrAir(recipe, '0', config.getConfigurationSection(id + ".advanced-craft." + 0));
|
||||||
|
setIngredientOrAir(recipe, '1', config.getConfigurationSection(id + ".advanced-craft." + 1));
|
||||||
|
setIngredientOrAir(recipe, '2', config.getConfigurationSection(id + ".advanced-craft." + 2));
|
||||||
|
setIngredientOrAir(recipe, '3', config.getConfigurationSection(id + ".advanced-craft." + 3));
|
||||||
|
setIngredientOrAir(recipe, '4', config.getConfigurationSection(id + ".advanced-craft." + 4));
|
||||||
|
setIngredientOrAir(recipe, '5', config.getConfigurationSection(id + ".advanced-craft." + 5));
|
||||||
|
setIngredientOrAir(recipe, '6', config.getConfigurationSection(id + ".advanced-craft." + 6));
|
||||||
|
setIngredientOrAir(recipe, '7', config.getConfigurationSection(id + ".advanced-craft." + 7));
|
||||||
|
setIngredientOrAir(recipe, '8', config.getConfigurationSection(id + ".advanced-craft." + 8));
|
||||||
|
|
||||||
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just for convenience
|
||||||
|
protected NamespacedKey getRecipeKey(Type t, String i, String type, String number) {
|
||||||
|
return new NamespacedKey(MMOItems.plugin, "mmorecipe_" + type + "_" + t.getId() + "_" + i + "_" + number);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void registerFurnaceRecipe(Type type, String id, RecipeInformation info, String number);
|
||||||
|
protected abstract void registerBlastRecipe(Type type, String id, RecipeInformation info, String number);
|
||||||
|
protected abstract void registerShapelessRecipe(Type type, String id, ConfigurationSection config, String number);
|
||||||
|
protected abstract void shapedIngredient(ShapedRecipe recipe, char c, MMORecipeChoice rc);
|
||||||
|
protected abstract void registerShapedRecipe(Type type, String id, List<String> list, String number);
|
||||||
|
protected abstract void registerCampfireRecipe(Type type, String id, RecipeInformation info, String number);
|
||||||
|
protected abstract void registerSmokerRecipe(Type type, String id, RecipeInformation info, String number);
|
||||||
|
protected abstract void shapelessIngredient(ShapelessRecipe recipe, MMORecipeChoice rc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is purely for easily converting the AWB recipes.
|
||||||
|
*
|
||||||
|
* @deprecated Some day I want to get proper rid of the AWB
|
||||||
|
* but right now we don't want to force players to update
|
||||||
|
* their recipes right off the bat.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
protected abstract void setIngredientOrAir(ShapedRecipe recipe, char character, ConfigurationSection c);
|
||||||
|
|
||||||
|
// For adding the recipes to the book
|
||||||
|
public Collection<NamespacedKey> getNamespacedKeys() {
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadRecipes() {
|
||||||
|
Bukkit.getScheduler().runTask(MMOItems.plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Bukkit.resetRecipes();
|
||||||
|
loadedRecipes.clear();
|
||||||
|
keys.clear();
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// For the reload command
|
||||||
|
public int size() {
|
||||||
|
return loadedRecipes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecipeInformation {
|
||||||
|
protected final MMORecipeChoice choice;
|
||||||
|
protected final float exp;
|
||||||
|
protected final int burnTime;
|
||||||
|
|
||||||
|
protected RecipeInformation(ConfigurationSection config) {
|
||||||
|
choice = MMORecipeChoice.getFromString(config.getString("item"));
|
||||||
|
exp = (float) config.getDouble("exp", 0.35);
|
||||||
|
burnTime = config.getInt("time", 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package net.Indyuce.mmoitems.manager;
|
package net.Indyuce.mmoitems.manager.recipe;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -24,19 +22,10 @@ import net.Indyuce.mmoitems.MMOItems;
|
|||||||
import net.Indyuce.mmoitems.api.MMORecipeChoice;
|
import net.Indyuce.mmoitems.api.MMORecipeChoice;
|
||||||
import net.Indyuce.mmoitems.api.Type;
|
import net.Indyuce.mmoitems.api.Type;
|
||||||
|
|
||||||
/**
|
@SuppressWarnings("deprecation")
|
||||||
* TODO
|
public class RecipeManagerDefault extends RecipeManager {
|
||||||
* When Bukkit changes their 'RecipeChoice.ExactChoice' API
|
@Override
|
||||||
* we can remove the suppressed warnings, but right now it works
|
protected void load() {
|
||||||
* despite being marked as deprecated. It is just a
|
|
||||||
*/
|
|
||||||
public class RecipeManager {
|
|
||||||
private List<Recipe> loadedRecipes = new ArrayList<>();
|
|
||||||
private Collection<NamespacedKey> keys = new ArrayList<>();
|
|
||||||
|
|
||||||
public RecipeManager() { load(); }
|
|
||||||
|
|
||||||
private void load() {
|
|
||||||
for (Type type : MMOItems.plugin.getTypes().getAll()) {
|
for (Type type : MMOItems.plugin.getTypes().getAll()) {
|
||||||
FileConfiguration config = type.getConfigFile().getConfig();
|
FileConfiguration config = type.getConfigFile().getConfig();
|
||||||
|
|
||||||
@ -76,7 +65,40 @@ public class RecipeManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerShapedRecipe(Type type, String id, List<String> list, String number) {
|
@Override
|
||||||
|
protected void registerFurnaceRecipe(Type type, String id, RecipeInformation info, String number) {
|
||||||
|
NamespacedKey key = getRecipeKey(type, id, "furnace", number);
|
||||||
|
FurnaceRecipe recipe = new FurnaceRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice.generateChoice(), info.exp, info.burnTime);
|
||||||
|
|
||||||
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerBlastRecipe(Type type, String id, RecipeInformation info, String number) {
|
||||||
|
NamespacedKey key = getRecipeKey(type, id, "blast", number);
|
||||||
|
BlastingRecipe recipe = new BlastingRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice.generateChoice(), info.exp, info.burnTime);
|
||||||
|
|
||||||
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerSmokerRecipe(Type type, String id, RecipeInformation info, String number) {
|
||||||
|
NamespacedKey key = getRecipeKey(type, id, "smoker", number);
|
||||||
|
SmokingRecipe recipe = new SmokingRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice.generateChoice(), info.exp, info.burnTime);
|
||||||
|
|
||||||
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerCampfireRecipe(Type type, String id, RecipeInformation info, String number) {
|
||||||
|
NamespacedKey key = getRecipeKey(type, id, "campfire", number);
|
||||||
|
CampfireRecipe recipe = new CampfireRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice.generateChoice(), info.exp, info.burnTime);
|
||||||
|
|
||||||
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerShapedRecipe(Type type, String id, List<String> list, String number) {
|
||||||
NamespacedKey key = getRecipeKey(type, id, "shaped", number);
|
NamespacedKey key = getRecipeKey(type, id, "shaped", number);
|
||||||
ShapedRecipe recipe = new ShapedRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
ShapedRecipe recipe = new ShapedRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
||||||
|
|
||||||
@ -98,12 +120,14 @@ public class RecipeManager {
|
|||||||
loadedRecipes.add(recipe); keys.add(key);
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shapedIngredient(ShapedRecipe recipe, char c, MMORecipeChoice rc) {
|
@Override
|
||||||
|
protected void shapedIngredient(ShapedRecipe recipe, char c, MMORecipeChoice rc) {
|
||||||
if(rc.isAir()) recipe.setIngredient(c, Material.AIR);
|
if(rc.isAir()) recipe.setIngredient(c, Material.AIR);
|
||||||
else recipe.setIngredient(c, rc.generateChoice());
|
else recipe.setIngredient(c, rc.generateChoice());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerShapelessRecipe(Type type, String id, ConfigurationSection config, String number) {
|
@Override
|
||||||
|
protected void registerShapelessRecipe(Type type, String id, ConfigurationSection config, String number) {
|
||||||
NamespacedKey key = getRecipeKey(type, id, "shapeless", number);
|
NamespacedKey key = getRecipeKey(type, id, "shapeless", number);
|
||||||
ShapelessRecipe recipe = new ShapelessRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
ShapelessRecipe recipe = new ShapelessRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
||||||
|
|
||||||
@ -115,78 +139,13 @@ public class RecipeManager {
|
|||||||
loadedRecipes.add(recipe); keys.add(key);
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shapelessIngredient(ShapelessRecipe recipe, MMORecipeChoice rc) {
|
@Override
|
||||||
|
protected void shapelessIngredient(ShapelessRecipe recipe, MMORecipeChoice rc) {
|
||||||
if(!rc.isAir()) recipe.addIngredient(rc.generateChoice());
|
if(!rc.isAir()) recipe.addIngredient(rc.generateChoice());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerFurnaceRecipe(Type type, String id, RecipeInformation info, String number) {
|
@Override
|
||||||
NamespacedKey key = getRecipeKey(type, id, "furnace", number);
|
protected void setIngredientOrAir(ShapedRecipe recipe, char character, ConfigurationSection c) {
|
||||||
FurnaceRecipe recipe = new FurnaceRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice, info.exp, info.burnTime);
|
|
||||||
|
|
||||||
loadedRecipes.add(recipe); keys.add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerBlastRecipe(Type type, String id, RecipeInformation info, String number) {
|
|
||||||
NamespacedKey key = getRecipeKey(type, id, "blast", number);
|
|
||||||
BlastingRecipe recipe = new BlastingRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice, info.exp, info.burnTime);
|
|
||||||
|
|
||||||
loadedRecipes.add(recipe); keys.add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerSmokerRecipe(Type type, String id, RecipeInformation info, String number) {
|
|
||||||
NamespacedKey key = getRecipeKey(type, id, "smoker", number);
|
|
||||||
SmokingRecipe recipe = new SmokingRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice, info.exp, info.burnTime);
|
|
||||||
|
|
||||||
loadedRecipes.add(recipe); keys.add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerCampfireRecipe(Type type, String id, RecipeInformation info, String number) {
|
|
||||||
NamespacedKey key = getRecipeKey(type, id, "campfire", number);
|
|
||||||
CampfireRecipe recipe = new CampfireRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice, info.exp, info.burnTime);
|
|
||||||
|
|
||||||
loadedRecipes.add(recipe); keys.add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Some day I want to get proper rid of the AWB
|
|
||||||
* but right now we don't want to force players to update
|
|
||||||
* their recipes right off the bat.
|
|
||||||
*/
|
|
||||||
private void registerAdvancedWorkbenchRecipe(Type type, String id, FileConfiguration config) {
|
|
||||||
MMOItems.plugin.getLogger().warning("Found deprecated adv. recipe for " + id + ". Converting it to the new system...");
|
|
||||||
MMOItems.plugin.getLogger().warning("It is recommended to update your recipes!");
|
|
||||||
|
|
||||||
NamespacedKey key = getRecipeKey(type, id, "advanced", "deprecated");
|
|
||||||
ShapedRecipe recipe = new ShapedRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
|
||||||
recipe.shape("012", "345", "678");
|
|
||||||
|
|
||||||
setIngredientOrAir(recipe, '0', config.getConfigurationSection(id + ".advanced-craft." + 0));
|
|
||||||
setIngredientOrAir(recipe, '1', config.getConfigurationSection(id + ".advanced-craft." + 1));
|
|
||||||
setIngredientOrAir(recipe, '2', config.getConfigurationSection(id + ".advanced-craft." + 2));
|
|
||||||
setIngredientOrAir(recipe, '3', config.getConfigurationSection(id + ".advanced-craft." + 3));
|
|
||||||
setIngredientOrAir(recipe, '4', config.getConfigurationSection(id + ".advanced-craft." + 4));
|
|
||||||
setIngredientOrAir(recipe, '5', config.getConfigurationSection(id + ".advanced-craft." + 5));
|
|
||||||
setIngredientOrAir(recipe, '6', config.getConfigurationSection(id + ".advanced-craft." + 6));
|
|
||||||
setIngredientOrAir(recipe, '7', config.getConfigurationSection(id + ".advanced-craft." + 7));
|
|
||||||
setIngredientOrAir(recipe, '8', config.getConfigurationSection(id + ".advanced-craft." + 8));
|
|
||||||
|
|
||||||
loadedRecipes.add(recipe); keys.add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just for convenience
|
|
||||||
private NamespacedKey getRecipeKey(Type t, String i, String type, String number) {
|
|
||||||
return new NamespacedKey(MMOItems.plugin, "mmorecipe_" + type + "_" + t.getId() + "_" + i + "_" + number);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is purely for easily converting the AWB recipes.
|
|
||||||
*
|
|
||||||
* @deprecated Some day I want to get proper rid of the AWB
|
|
||||||
* but right now we don't want to force players to update
|
|
||||||
* their recipes right off the bat.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private void setIngredientOrAir(ShapedRecipe recipe, char character, ConfigurationSection c) {
|
|
||||||
if(c.contains("type")) {
|
if(c.contains("type")) {
|
||||||
ItemStack item = MMOItems.plugin.getItems().getItem(Type.get(c.getString("type")), c.getString("id"));
|
ItemStack item = MMOItems.plugin.getItems().getItem(Type.get(c.getString("type")), c.getString("id"));
|
||||||
if(item == null) {
|
if(item == null) {
|
||||||
@ -214,38 +173,4 @@ public class RecipeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For adding the recipes to the book
|
|
||||||
public Collection<NamespacedKey> getNamespacedKeys() {
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadRecipes() {
|
|
||||||
Bukkit.getScheduler().runTask(MMOItems.plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Bukkit.resetRecipes();
|
|
||||||
loadedRecipes.clear();
|
|
||||||
keys.clear();
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// For the reload command
|
|
||||||
public int size() {
|
|
||||||
return loadedRecipes.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
class RecipeInformation {
|
|
||||||
private final RecipeChoice choice;
|
|
||||||
private final float exp;
|
|
||||||
private final int burnTime;
|
|
||||||
|
|
||||||
private RecipeInformation(ConfigurationSection config) {
|
|
||||||
choice = MMORecipeChoice.getFromString(config.getString("item")).generateChoice();
|
|
||||||
exp = (float) config.getDouble("exp", 0.35);
|
|
||||||
burnTime = config.getInt("time", 200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,9 +1,6 @@
|
|||||||
package net.Indyuce.mmoitems.manager;
|
package net.Indyuce.mmoitems.manager.recipe;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -21,22 +18,10 @@ import net.Indyuce.mmoitems.MMOItems;
|
|||||||
import net.Indyuce.mmoitems.api.MMORecipeChoice;
|
import net.Indyuce.mmoitems.api.MMORecipeChoice;
|
||||||
import net.Indyuce.mmoitems.api.Type;
|
import net.Indyuce.mmoitems.api.Type;
|
||||||
|
|
||||||
/**
|
@SuppressWarnings("deprecation")
|
||||||
* TODO
|
|
||||||
* When Bukkit changes their 'RecipeChoice.ExactChoice' API
|
|
||||||
* we can remove the suppressed warnings, but right now it works
|
|
||||||
* despite being marked as deprecated. It is just a
|
|
||||||
*/
|
|
||||||
public class RecipeManagerLegacy extends RecipeManager {
|
public class RecipeManagerLegacy extends RecipeManager {
|
||||||
private List<Recipe> loadedRecipes = new ArrayList<>();
|
@Override
|
||||||
private Collection<NamespacedKey> keys = new ArrayList<>();
|
protected void load() {
|
||||||
|
|
||||||
public RecipeManagerLegacy() {
|
|
||||||
MMOItems.plugin.getLogger().log(Level.INFO, "1.12 detected! Loading the Legacy recipe manager...");
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void load() {
|
|
||||||
for (Type type : MMOItems.plugin.getTypes().getAll()) {
|
for (Type type : MMOItems.plugin.getTypes().getAll()) {
|
||||||
FileConfiguration config = type.getConfigFile().getConfig();
|
FileConfiguration config = type.getConfigFile().getConfig();
|
||||||
|
|
||||||
@ -70,7 +55,23 @@ public class RecipeManagerLegacy extends RecipeManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerShapedRecipe(Type type, String id, List<String> list, String number) {
|
@Override
|
||||||
|
protected void registerFurnaceRecipe(Type type, String id, RecipeInformation info, String number) {
|
||||||
|
NamespacedKey key = getRecipeKey(type, id, "furnace", number);
|
||||||
|
FurnaceRecipe recipe = new FurnaceRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.choice.generateLegacy(), info.exp, info.burnTime);
|
||||||
|
|
||||||
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerBlastRecipe(Type type, String id, RecipeInformation info, String number) {}
|
||||||
|
@Override
|
||||||
|
protected void registerSmokerRecipe(Type type, String id, RecipeInformation info, String number) {}
|
||||||
|
@Override
|
||||||
|
protected void registerCampfireRecipe(Type type, String id, RecipeInformation info, String number) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerShapedRecipe(Type type, String id, List<String> list, String number) {
|
||||||
NamespacedKey key = getRecipeKey(type, id, "shaped", number);
|
NamespacedKey key = getRecipeKey(type, id, "shaped", number);
|
||||||
ShapedRecipe recipe = new ShapedRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
ShapedRecipe recipe = new ShapedRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
||||||
|
|
||||||
@ -92,12 +93,14 @@ public class RecipeManagerLegacy extends RecipeManager {
|
|||||||
loadedRecipes.add(recipe); keys.add(key);
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shapedIngredient(ShapedRecipe recipe, char c, MMORecipeChoice rc) {
|
@Override
|
||||||
|
protected void shapedIngredient(ShapedRecipe recipe, char c, MMORecipeChoice rc) {
|
||||||
if(rc.isAir()) recipe.setIngredient(c, Material.AIR);
|
if(rc.isAir()) recipe.setIngredient(c, Material.AIR);
|
||||||
else recipe.setIngredient(c, rc.generateChoice());
|
else recipe.setIngredient(c, rc.generateLegacy());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerShapelessRecipe(Type type, String id, ConfigurationSection config, String number) {
|
@Override
|
||||||
|
protected void registerShapelessRecipe(Type type, String id, ConfigurationSection config, String number) {
|
||||||
NamespacedKey key = getRecipeKey(type, id, "shapeless", number);
|
NamespacedKey key = getRecipeKey(type, id, "shapeless", number);
|
||||||
ShapelessRecipe recipe = new ShapelessRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
ShapelessRecipe recipe = new ShapelessRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
||||||
|
|
||||||
@ -109,57 +112,13 @@ public class RecipeManagerLegacy extends RecipeManager {
|
|||||||
loadedRecipes.add(recipe); keys.add(key);
|
loadedRecipes.add(recipe); keys.add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shapelessIngredient(ShapelessRecipe recipe, MMORecipeChoice rc) {
|
@Override
|
||||||
if(!rc.isAir()) recipe.addIngredient(rc.generateChoice());
|
protected void shapelessIngredient(ShapelessRecipe recipe, MMORecipeChoice rc) {
|
||||||
|
if(!rc.isAir()) recipe.addIngredient(rc.generateLegacy());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerFurnaceRecipe(Type type, String id, RecipeInformation info, String number) {
|
@Override
|
||||||
NamespacedKey key = getRecipeKey(type, id, "furnace", number);
|
protected void setIngredientOrAir(ShapedRecipe recipe, char character, ConfigurationSection c) {
|
||||||
FurnaceRecipe recipe = new FurnaceRecipe(key, MMOItems.plugin.getItems().getItem(type, id), info.input, info.exp, info.burnTime);
|
|
||||||
|
|
||||||
loadedRecipes.add(recipe); keys.add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Some day I want to get proper rid of the AWB
|
|
||||||
* but right now we don't want to force players to update
|
|
||||||
* their recipes right off the bat.
|
|
||||||
*/
|
|
||||||
private void registerAdvancedWorkbenchRecipe(Type type, String id, FileConfiguration config) {
|
|
||||||
MMOItems.plugin.getLogger().warning("Found deprecated adv. recipe for " + id + ". Converting it to the new system...");
|
|
||||||
MMOItems.plugin.getLogger().warning("It is recommended to update your recipes!");
|
|
||||||
|
|
||||||
NamespacedKey key = getRecipeKey(type, id, "advanced", "deprecated");
|
|
||||||
ShapedRecipe recipe = new ShapedRecipe(key, MMOItems.plugin.getItems().getItem(type, id));
|
|
||||||
recipe.shape("012", "345", "678");
|
|
||||||
|
|
||||||
setIngredientOrAir(recipe, '0', config.getConfigurationSection(id + ".advanced-craft." + 0));
|
|
||||||
setIngredientOrAir(recipe, '1', config.getConfigurationSection(id + ".advanced-craft." + 1));
|
|
||||||
setIngredientOrAir(recipe, '2', config.getConfigurationSection(id + ".advanced-craft." + 2));
|
|
||||||
setIngredientOrAir(recipe, '3', config.getConfigurationSection(id + ".advanced-craft." + 3));
|
|
||||||
setIngredientOrAir(recipe, '4', config.getConfigurationSection(id + ".advanced-craft." + 4));
|
|
||||||
setIngredientOrAir(recipe, '5', config.getConfigurationSection(id + ".advanced-craft." + 5));
|
|
||||||
setIngredientOrAir(recipe, '6', config.getConfigurationSection(id + ".advanced-craft." + 6));
|
|
||||||
setIngredientOrAir(recipe, '7', config.getConfigurationSection(id + ".advanced-craft." + 7));
|
|
||||||
setIngredientOrAir(recipe, '8', config.getConfigurationSection(id + ".advanced-craft." + 8));
|
|
||||||
|
|
||||||
loadedRecipes.add(recipe); keys.add(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just for convenience
|
|
||||||
private NamespacedKey getRecipeKey(Type t, String i, String type, String number) {
|
|
||||||
return new NamespacedKey(MMOItems.plugin, "mmorecipe_" + type + "_" + t.getId() + "_" + i + "_" + number);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is purely for easily converting the AWB recipes.
|
|
||||||
*
|
|
||||||
* @deprecated Some day I want to get proper rid of the AWB
|
|
||||||
* but right now we don't want to force players to update
|
|
||||||
* their recipes right off the bat.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private void setIngredientOrAir(ShapedRecipe recipe, char character, ConfigurationSection c) {
|
|
||||||
if(c.contains("type")) {
|
if(c.contains("type")) {
|
||||||
ItemStack item = MMOItems.plugin.getItems().getItem(Type.get(c.getString("type")), c.getString("id"));
|
ItemStack item = MMOItems.plugin.getItems().getItem(Type.get(c.getString("type")), c.getString("id"));
|
||||||
if(item == null) {
|
if(item == null) {
|
||||||
@ -183,42 +142,8 @@ public class RecipeManagerLegacy extends RecipeManager {
|
|||||||
ItemStack item = new ItemStack(material);
|
ItemStack item = new ItemStack(material);
|
||||||
item.setAmount(amount); ItemMeta meta = item.getItemMeta();
|
item.setAmount(amount); ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName(name); item.setItemMeta(meta);
|
meta.setDisplayName(name); item.setItemMeta(meta);
|
||||||
recipe.setIngredient(character, material);
|
recipe.setIngredient(character, item.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For adding the recipes to the book
|
|
||||||
public Collection<NamespacedKey> getNamespacedKeys() {
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadRecipes() {
|
|
||||||
Bukkit.getScheduler().runTask(MMOItems.plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Bukkit.resetRecipes();
|
|
||||||
loadedRecipes.clear();
|
|
||||||
keys.clear();
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// For the reload command
|
|
||||||
public int size() {
|
|
||||||
return loadedRecipes.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
class RecipeInformation {
|
|
||||||
private final Material input;
|
|
||||||
private final float exp;
|
|
||||||
private final int burnTime;
|
|
||||||
|
|
||||||
private RecipeInformation(ConfigurationSection config) {
|
|
||||||
input = MMORecipeChoice.getFromString(config.getString("item")).generateLegacy();
|
|
||||||
exp = (float) config.getDouble("exp", 0.35);
|
|
||||||
burnTime = config.getInt("time", 200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user