Skip to content

Commit

Permalink
reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 15, 2019
1 parent ac8282d commit 2d2b386
Showing 1 changed file with 72 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,112 +50,93 @@ public static void removeDenizenRecipes() {
}
}

@EventHandler
public void scriptReload(ScriptReloadEvent event) {

for (ItemScriptContainer container : item_scripts.values()) {
if (!container.contains("RECIPE")) {
continue;
}
List<String> recipeList = container.getStringList("RECIPE");

// Process all tags in list
for (int n = 0; n < recipeList.size(); n++) {
recipeList.set(n, TagManager.tag(recipeList.get(n), new BukkitTagContext(container.player, container.npc, new ScriptTag(container))));
}

// Store every ingredient in a List
List<ItemTag> ingredients = new ArrayList<>();

boolean shouldRegister = true;
recipeLoop:
for (String recipeRow : recipeList) {
String[] elements = recipeRow.split("\\|", 3);

for (String element : elements) {
ItemTag ingredient = ItemTag.valueOf(element.replaceAll("[iImM]@", ""), container);
if (ingredient == null) {
Debug.echoError("Invalid ItemTag ingredient, recipe will not be registered for item script '"
+ container.getName() + "': " + element);
shouldRegister = false;
break recipeLoop;
}
ingredients.add(ingredient);
}
}

if (shouldRegister) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
NamespacedKey key = new NamespacedKey("denizen", "item_" + CoreUtilities.toLowerCase(container.getName()) + "_shaped_recipe");
ShapedRecipe recipe = new ShapedRecipe(key, container.getCleanReference().getItemStack()).shape("ABC", "DEF", "GHI");
for (int i = 0; i < ingredients.size(); i++) {
recipe.setIngredient("ABCDEFGHI".charAt(i), new RecipeChoice.ExactChoice(ingredients.get(i).getItemStack().clone()));
}
Bukkit.addRecipe(recipe);
}
else {
specialrecipesMap.put(container, ingredients);
}
}
public void registerShapedRecipe(ItemScriptContainer container, List<String> recipeList) {
for (int n = 0; n < recipeList.size(); n++) {
recipeList.set(n, TagManager.tag(recipeList.get(n), new BukkitTagContext(container.player, container.npc, new ScriptTag(container))));
}
List<ItemTag> ingredients = new ArrayList<>();
for (String recipeRow : recipeList) {
String[] elements = recipeRow.split("\\|", 3);

for (ItemScriptContainer container : item_scripts.values()) {
if (!container.contains("SHAPELESS_RECIPE")) {
continue;
}
String string = container.getString("SHAPELESS_RECIPE");

String list = TagManager.tag(string, new BukkitTagContext(container.player, container.npc, new ScriptTag(container)));

List<ItemTag> ingredients = new ArrayList<>();

boolean shouldRegister = true;
for (String element : ListTag.valueOf(list)) {
for (String element : elements) {
ItemTag ingredient = ItemTag.valueOf(element.replaceAll("[iImM]@", ""), container);
if (ingredient == null) {
Debug.echoError("Invalid ItemTag ingredient, shapeless recipe will not be registered for item script '"
Debug.echoError("Invalid ItemTag ingredient, recipe will not be registered for item script '"
+ container.getName() + "': " + element);
shouldRegister = false;
break;
return;
}
ingredients.add(ingredient);
}
if (shouldRegister) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack[] input = new ItemStack[ingredients.size()];
for (int i = 0; i < input.length; i++) {
input[i] = ingredients.get(i).getItemStack().clone();
}
NMSHandler.getItemHelper().registerShapelessRecipe(CoreUtilities.toLowerCase(container.getName()), result, input);
}
else {
shapelessRecipesMap.put(container, ingredients);
}
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
NamespacedKey key = new NamespacedKey("denizen", "item_" + CoreUtilities.toLowerCase(container.getName()) + "_shaped_recipe");
ShapedRecipe recipe = new ShapedRecipe(key, container.getCleanReference().getItemStack()).shape("ABC", "DEF", "GHI");
for (int i = 0; i < ingredients.size(); i++) {
recipe.setIngredient("ABCDEFGHI".charAt(i), new RecipeChoice.ExactChoice(ingredients.get(i).getItemStack().clone()));
}
Bukkit.addRecipe(recipe);
}
else {
specialrecipesMap.put(container, ingredients);
}
}

currentFurnaceRecipes.clear();
for (ItemScriptContainer container : item_scripts.values()) {
if (!container.contains("FURNACE_RECIPE")) {
continue;
public void registerShapelessRecipe(ItemScriptContainer container, String shapelessString) {
String list = TagManager.tag(shapelessString, new BukkitTagContext(container.player, container.npc, new ScriptTag(container)));
List<ItemTag> ingredients = new ArrayList<>();
for (String element : ListTag.valueOf(list)) {
ItemTag ingredient = ItemTag.valueOf(element.replaceAll("[iImM]@", ""), container);
if (ingredient == null) {
Debug.echoError("Invalid ItemTag ingredient, shapeless recipe will not be registered for item script '"
+ container.getName() + "': " + element);
return;
}
String string = container.getString("FURNACE_RECIPE");
ingredients.add(ingredient);
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack[] input = new ItemStack[ingredients.size()];
for (int i = 0; i < input.length; i++) {
input[i] = ingredients.get(i).getItemStack().clone();
}
NMSHandler.getItemHelper().registerShapelessRecipe(CoreUtilities.toLowerCase(container.getName()), result, input);
}
else {
shapelessRecipesMap.put(container, ingredients);
}
}

ItemTag furnace_item = ItemTag.valueOf(string, container);
if (furnace_item == null) {
Debug.echoError("Invalid item '" + string + "', furnace recipe will not be registered for item script '" + container.getName() + "'.");
continue;
public void registerFurnaceRecipe(ItemScriptContainer container, String furnaceItemString, float exp, int time) {
ItemTag furnace_item = ItemTag.valueOf(furnaceItemString, container);
if (furnace_item == null) {
Debug.echoError("Invalid item '" + furnaceItemString + "', furnace recipe will not be registered for item script '" + container.getName() + "'.");
return;
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack input = furnace_item.getItemStack().clone();
NMSHandler.getItemHelper().registerFurnaceRecipe(CoreUtilities.toLowerCase(container.getName()), result, input, exp, time);
}
else {
FurnaceRecipe recipe = new FurnaceRecipe(container.getCleanReference().getItemStack(), furnace_item.getMaterial().getMaterial(), furnace_item.getItemStack().getDurability());
Bukkit.addRecipe(recipe);
currentFurnaceRecipes.put(container, furnace_item);
}
}

@EventHandler
public void scriptReload(ScriptReloadEvent event) {

currentFurnaceRecipes.clear();
for (ItemScriptContainer container : item_scripts.values()) {
if (container.contains("RECIPE")) {
registerShapedRecipe(container, container.getStringList("RECIPE"));
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack input = furnace_item.getItemStack().clone();
NMSHandler.getItemHelper().registerFurnaceRecipe(CoreUtilities.toLowerCase(container.getName()), result, input, 0, 20);
if (container.contains("SHAPELESS_RECIPE")) {
registerShapelessRecipe(container, container.getString("SHAPELESS_RECIPE"));
}
else {
FurnaceRecipe recipe = new FurnaceRecipe(container.getCleanReference().getItemStack(), furnace_item.getMaterial().getMaterial(), furnace_item.getItemStack().getDurability());
Bukkit.addRecipe(recipe);
currentFurnaceRecipes.put(container, furnace_item);
if (container.contains("FURNACE_RECIPE")) {
registerFurnaceRecipe(container, container.getString("FURNACE_RECIPE"), 0, 40);
}
}
}
Expand Down

0 comments on commit 2d2b386

Please sign in to comment.