From b107a8dc7c32ed4f1c2863aa5e6bdf4a9b142c89 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Mon, 9 Jun 2014 02:04:59 +0200 Subject: [PATCH] Fire brew event after outputs have changed and before experience is granted. Part 2 of fixing #2041 --- .../skills/alchemy/AlchemyPotionBrewer.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java b/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java index 46fc14141..500919e77 100644 --- a/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java +++ b/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.skills.alchemy; +import java.util.ArrayList; import java.util.List; import org.bukkit.Material; @@ -17,8 +18,8 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.skills.alchemy.PotionConfig; import com.gmail.nossr50.datatypes.skills.SecondaryAbility; import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion; -import com.gmail.nossr50.events.fake.FakeBrewEvent; import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage; +import com.gmail.nossr50.events.fake.FakeBrewEvent; import com.gmail.nossr50.runnables.player.PlayerUpdateInventoryTask; import com.gmail.nossr50.runnables.skills.AlchemyBrewCheckTask; import com.gmail.nossr50.util.Permissions; @@ -102,12 +103,7 @@ public final class AlchemyPotionBrewer { return; } - FakeBrewEvent event = new FakeBrewEvent(brewingStand.getBlock(), inventory); - mcMMO.p.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return; - } + List inputList = new ArrayList(); for (int i = 0; i < 3; i++) { ItemStack item = inventory.getItem(i); @@ -119,13 +115,26 @@ public final class AlchemyPotionBrewer { AlchemyPotion input = PotionConfig.getInstance().getPotion(item.getDurability()); AlchemyPotion output = PotionConfig.getInstance().getPotion(input.getChildDataValue(ingredient)); + inputList.add(input); + if (output != null) { inventory.setItem(i, output.toItemStack(item.getAmount()).clone()); + } + } - if (player != null) { - PotionStage potionStage = PotionStage.getPotionStage(input, output); - UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(potionStage, 1); - } + FakeBrewEvent event = new FakeBrewEvent(brewingStand.getBlock(), inventory); + mcMMO.p.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled() || inputList.isEmpty()) { + return; + } + + for (AlchemyPotion input : inputList) { + AlchemyPotion output = PotionConfig.getInstance().getPotion(input.getChildDataValue(ingredient)); + + if (output != null && player != null) { + PotionStage potionStage = PotionStage.getPotionStage(input, output); + UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(potionStage, 1); } }