|
@@ -9,6 +9,7 @@ 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;
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
|
|
+import org.bukkit.Bukkit;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.block.BlockState;
|
|
import org.bukkit.block.BlockState;
|
|
import org.bukkit.block.BrewingStand;
|
|
import org.bukkit.block.BrewingStand;
|
|
@@ -31,7 +32,9 @@ public final class AlchemyPotionBrewer {
|
|
}
|
|
}
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
for (int i = 0; i < 3; i++) {
|
|
- if (contents[i] == null || contents[i].getType() != Material.POTION && contents[i].getType() != Material.SPLASH_POTION && contents[i].getType() != Material.LINGERING_POTION) {
|
|
|
|
|
|
+ if (contents[i] == null || contents[i].getType() != Material.POTION
|
|
|
|
+ && contents[i].getType() != Material.SPLASH_POTION
|
|
|
|
+ && contents[i].getType() != Material.LINGERING_POTION) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -101,52 +104,71 @@ public final class AlchemyPotionBrewer {
|
|
}
|
|
}
|
|
|
|
|
|
public static void finishBrewing(BlockState brewingStand, Player player, boolean forced) {
|
|
public static void finishBrewing(BlockState brewingStand, Player player, boolean forced) {
|
|
|
|
+ // Check if the brewing stand block state is an actual brewing stand
|
|
if (!(brewingStand instanceof BrewingStand)) {
|
|
if (!(brewingStand instanceof BrewingStand)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- BrewerInventory inventory = ((BrewingStand) brewingStand).getInventory();
|
|
|
|
- ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
|
|
|
|
|
|
+ // Retrieve the inventory of the brewing stand and clone the current ingredient for safe manipulation
|
|
|
|
+ final BrewerInventory inventory = ((BrewingStand) brewingStand).getInventory();
|
|
|
|
+ final ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
|
|
|
|
|
|
|
|
+ // Check if the brewing stand has a valid ingredient; if not, exit the method
|
|
if (!hasIngredient(inventory, player)) {
|
|
if (!hasIngredient(inventory, player)) {
|
|
|
|
+ // debug
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Initialize lists to hold the potions before and after brewing, initially setting them to null
|
|
List<AlchemyPotion> inputList = new ArrayList<>(Collections.nCopies(3, null));
|
|
List<AlchemyPotion> inputList = new ArrayList<>(Collections.nCopies(3, null));
|
|
List<ItemStack> outputList = new ArrayList<>(Collections.nCopies(3, null));
|
|
List<ItemStack> outputList = new ArrayList<>(Collections.nCopies(3, null));
|
|
|
|
|
|
|
|
+ // Process each of the three slots in the brewing stand
|
|
for (int i = 0; i < 3; i++) {
|
|
for (int i = 0; i < 3; i++) {
|
|
ItemStack item = inventory.getItem(i);
|
|
ItemStack item = inventory.getItem(i);
|
|
|
|
|
|
- if (isEmpty(item) || item.getType() == Material.GLASS_BOTTLE || !mcMMO.p.getPotionConfig().isValidPotion(item)) {
|
|
|
|
|
|
+ // Skip the slot if it's empty, contains a glass bottle, or holds an invalid potion
|
|
|
|
+ if (isEmpty(item)
|
|
|
|
+ || item.getType() == Material.GLASS_BOTTLE
|
|
|
|
+ || !mcMMO.p.getPotionConfig().isValidPotion(item)) {
|
|
|
|
+ // debug
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Retrieve the potion configurations for the input and resulting output potion
|
|
AlchemyPotion input = mcMMO.p.getPotionConfig().getPotion(item);
|
|
AlchemyPotion input = mcMMO.p.getPotionConfig().getPotion(item);
|
|
AlchemyPotion output = input.getChild(ingredient);
|
|
AlchemyPotion output = input.getChild(ingredient);
|
|
|
|
|
|
|
|
+ // Update the input list with the current potion
|
|
inputList.set(i, input);
|
|
inputList.set(i, input);
|
|
|
|
|
|
|
|
+ // If there is a valid output potion, add it to the output list
|
|
if (output != null) {
|
|
if (output != null) {
|
|
outputList.set(i, output.toItemStack(item.getAmount()).clone());
|
|
outputList.set(i, output.toItemStack(item.getAmount()).clone());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Create a fake brewing event and pass it to the plugin's event system
|
|
FakeBrewEvent event = new FakeBrewEvent(brewingStand.getBlock(), inventory, outputList, ((BrewingStand) brewingStand).getFuelLevel());
|
|
FakeBrewEvent event = new FakeBrewEvent(brewingStand.getBlock(), inventory, outputList, ((BrewingStand) brewingStand).getFuelLevel());
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
+ // If the event is cancelled or there are no potions processed, exit the method
|
|
if (event.isCancelled() || inputList.isEmpty()) {
|
|
if (event.isCancelled() || inputList.isEmpty()) {
|
|
|
|
+ // debug
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Update the brewing inventory with the new potions
|
|
for (int i = 0; i < 3; i++) {
|
|
for (int i = 0; i < 3; i++) {
|
|
if(outputList.get(i) != null) {
|
|
if(outputList.get(i) != null) {
|
|
inventory.setItem(i, outputList.get(i));
|
|
inventory.setItem(i, outputList.get(i));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Remove the used ingredient from the brewing inventory
|
|
removeIngredient(inventory, player);
|
|
removeIngredient(inventory, player);
|
|
|
|
|
|
|
|
+ // Handle potion brewing success and related effects for each potion processed
|
|
for (AlchemyPotion input : inputList) {
|
|
for (AlchemyPotion input : inputList) {
|
|
if (input == null) continue;
|
|
if (input == null) continue;
|
|
|
|
|
|
@@ -155,13 +177,14 @@ public final class AlchemyPotionBrewer {
|
|
if (output != null && player != null) {
|
|
if (output != null && player != null) {
|
|
PotionStage potionStage = PotionStage.getPotionStage(input, output);
|
|
PotionStage potionStage = PotionStage.getPotionStage(input, output);
|
|
|
|
|
|
- //TODO: hmm
|
|
|
|
|
|
+ // Update player alchemy skills or effects based on brewing success
|
|
if (UserManager.hasPlayerDataKey(player)) {
|
|
if (UserManager.hasPlayerDataKey(player)) {
|
|
UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(potionStage, 1);
|
|
UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(potionStage, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // If the brewing was not forced by external conditions, schedule a new update
|
|
if (!forced) {
|
|
if (!forced) {
|
|
scheduleUpdate(inventory);
|
|
scheduleUpdate(inventory);
|
|
}
|
|
}
|