浏览代码

minor refactoring

nossr50 11 月之前
父节点
当前提交
4fce053804

+ 2 - 2
src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java

@@ -156,7 +156,7 @@ public class AlchemyBrewTask extends CancellableRunnable {
         mcMMO.p.getServer().getPluginManager().callEvent(event);
 
         if (!event.isCancelled()) {
-            AlchemyPotionBrewer.finishBrewing(brewingStand, mmoPlayer.getPlayer(), false);
+            AlchemyPotionBrewer.finishBrewing(brewingStand, mmoPlayer, false);
         }
 
         Alchemy.brewingStandMap.remove(brewingStand.getLocation());
@@ -165,7 +165,7 @@ public class AlchemyBrewTask extends CancellableRunnable {
     public void finishImmediately() {
         this.cancel();
 
-        AlchemyPotionBrewer.finishBrewing(brewingStand, mmoPlayer.getPlayer(), true);
+        AlchemyPotionBrewer.finishBrewing(brewingStand, mmoPlayer, true);
         Alchemy.brewingStandMap.remove(brewingStand.getLocation());
     }
 

+ 8 - 2
src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java

@@ -144,7 +144,7 @@ public final class AlchemyPotionBrewer {
                 ? 1 : mmoPlayer.getAlchemyManager().getTier());
     }
 
-    public static void finishBrewing(BlockState brewingStand, Player player, boolean forced) {
+    public static void finishBrewing(BlockState brewingStand, @Nullable McMMOPlayer mmoPlayer, boolean forced) {
         // Check if the brewing stand block state is an actual brewing stand
         if (!(brewingStand instanceof BrewingStand)) {
             return;
@@ -153,9 +153,15 @@ public final class AlchemyPotionBrewer {
         // 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();
+        Player player = mmoPlayer != null ? mmoPlayer.getPlayer() : null;
+
+        if (ingredient == null) {
+            return;
+        }
 
         // Check if the brewing stand has a valid ingredient; if not, exit the method
-        if (!hasIngredient(inventory, player)) {
+        if (player == null
+                || !hasIngredient(inventory, player)) {
             // debug
             return;
         }