mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Fire brew event after outputs have changed
and before experience is granted. Part 2 of fixing #2041
This commit is contained in:
parent
37aebc1716
commit
b107a8dc7c
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.skills.alchemy;
|
package com.gmail.nossr50.skills.alchemy;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
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.config.skills.alchemy.PotionConfig;
|
||||||
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
|
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
|
||||||
import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion;
|
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.datatypes.skills.alchemy.PotionStage;
|
||||||
|
import com.gmail.nossr50.events.fake.FakeBrewEvent;
|
||||||
import com.gmail.nossr50.runnables.player.PlayerUpdateInventoryTask;
|
import com.gmail.nossr50.runnables.player.PlayerUpdateInventoryTask;
|
||||||
import com.gmail.nossr50.runnables.skills.AlchemyBrewCheckTask;
|
import com.gmail.nossr50.runnables.skills.AlchemyBrewCheckTask;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
@ -102,12 +103,7 @@ public final class AlchemyPotionBrewer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeBrewEvent event = new FakeBrewEvent(brewingStand.getBlock(), inventory);
|
List<AlchemyPotion> inputList = new ArrayList<AlchemyPotion>();
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
ItemStack item = inventory.getItem(i);
|
ItemStack item = inventory.getItem(i);
|
||||||
@ -119,13 +115,26 @@ public final class AlchemyPotionBrewer {
|
|||||||
AlchemyPotion input = PotionConfig.getInstance().getPotion(item.getDurability());
|
AlchemyPotion input = PotionConfig.getInstance().getPotion(item.getDurability());
|
||||||
AlchemyPotion output = PotionConfig.getInstance().getPotion(input.getChildDataValue(ingredient));
|
AlchemyPotion output = PotionConfig.getInstance().getPotion(input.getChildDataValue(ingredient));
|
||||||
|
|
||||||
|
inputList.add(input);
|
||||||
|
|
||||||
if (output != null) {
|
if (output != null) {
|
||||||
inventory.setItem(i, output.toItemStack(item.getAmount()).clone());
|
inventory.setItem(i, output.toItemStack(item.getAmount()).clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (player != null) {
|
FakeBrewEvent event = new FakeBrewEvent(brewingStand.getBlock(), inventory);
|
||||||
PotionStage potionStage = PotionStage.getPotionStage(input, output);
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(potionStage, 1);
|
|
||||||
}
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user