mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-10-31 01:03:44 +01:00 
			
		
		
		
	Check if brewing stand still exists before processing AlchemyBrewTask
This commit is contained in:
		| @@ -18,17 +18,17 @@ public class AlchemyBrewCheckTask extends BukkitRunnable { | |||||||
|     private Block brewingStand; |     private Block brewingStand; | ||||||
|     private ItemStack[] oldInventory; |     private ItemStack[] oldInventory; | ||||||
|     private ItemStack[] newInventory; |     private ItemStack[] newInventory; | ||||||
|      |  | ||||||
|     public AlchemyBrewCheckTask(Player player, BrewingStand brewingStand) { |     public AlchemyBrewCheckTask(Player player, BrewingStand brewingStand) { | ||||||
|         this.player = player; |         this.player = player; | ||||||
|         this.brewingStand = brewingStand.getBlock(); |         this.brewingStand = brewingStand.getBlock(); | ||||||
|         this.oldInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4); |         this.oldInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4); | ||||||
|     } |     } | ||||||
|      |  | ||||||
|     @Override |     @Override | ||||||
|     public void run() { |     public void run() { | ||||||
|         this.newInventory = Arrays.copyOfRange(((BrewingStand) brewingStand.getState()).getInventory().getContents(), 0, 4); |         this.newInventory = Arrays.copyOfRange(((BrewingStand) brewingStand.getState()).getInventory().getContents(), 0, 4); | ||||||
|           |  | ||||||
|         if (Alchemy.brewingStandMap.containsKey(brewingStand)) { |         if (Alchemy.brewingStandMap.containsKey(brewingStand)) { | ||||||
|             if (oldInventory[INGREDIENT_SLOT] == null || newInventory[INGREDIENT_SLOT] == null || !oldInventory[INGREDIENT_SLOT].isSimilar(newInventory[INGREDIENT_SLOT]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) { |             if (oldInventory[INGREDIENT_SLOT] == null || newInventory[INGREDIENT_SLOT] == null || !oldInventory[INGREDIENT_SLOT].isSimilar(newInventory[INGREDIENT_SLOT]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) { | ||||||
|                 Alchemy.brewingStandMap.get(brewingStand).cancelBrew(); |                 Alchemy.brewingStandMap.get(brewingStand).cancelBrew(); | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package com.gmail.nossr50.runnables.skills; | package com.gmail.nossr50.runnables.skills; | ||||||
|  |  | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
|  | import org.bukkit.Material; | ||||||
| import org.bukkit.block.Block; | import org.bukkit.block.Block; | ||||||
| import org.bukkit.block.BrewingStand; | import org.bukkit.block.BrewingStand; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| @@ -20,7 +21,7 @@ import com.gmail.nossr50.util.player.UserManager; | |||||||
| public class AlchemyBrewTask extends BukkitRunnable { | public class AlchemyBrewTask extends BukkitRunnable { | ||||||
|     private final double DEFAULT_BREW_SPEED = 1.0; |     private final double DEFAULT_BREW_SPEED = 1.0; | ||||||
|     private final int    DEFAULT_BREW_TICKS = 400; |     private final int    DEFAULT_BREW_TICKS = 400; | ||||||
|      |  | ||||||
|     private Block brewingStand; |     private Block brewingStand; | ||||||
|     private double brewSpeed; |     private double brewSpeed; | ||||||
|     private double brewTimer; |     private double brewTimer; | ||||||
| @@ -32,31 +33,41 @@ public class AlchemyBrewTask extends BukkitRunnable { | |||||||
|  |  | ||||||
|         brewSpeed = DEFAULT_BREW_SPEED; |         brewSpeed = DEFAULT_BREW_SPEED; | ||||||
|         brewTimer = DEFAULT_BREW_TICKS; |         brewTimer = DEFAULT_BREW_TICKS; | ||||||
|          |  | ||||||
|         if (player != null && !Misc.isNPCEntity(player) && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.CATALYSIS)) { |         if (player != null && !Misc.isNPCEntity(player) && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.CATALYSIS)) { | ||||||
|             double catalysis = UserManager.getPlayer(player).getAlchemyManager().getBrewSpeed(); |             double catalysis = UserManager.getPlayer(player).getAlchemyManager().getBrewSpeed(); | ||||||
|              |  | ||||||
|             if (Permissions.lucky(player, SkillType.ALCHEMY)) { |             if (Permissions.lucky(player, SkillType.ALCHEMY)) { | ||||||
|                 catalysis = UserManager.getPlayer(player).getAlchemyManager().getBrewSpeedLucky(); |                 catalysis = UserManager.getPlayer(player).getAlchemyManager().getBrewSpeedLucky(); | ||||||
|             } |             } | ||||||
|              |  | ||||||
|             McMMOPlayerCatalysisEvent event = new McMMOPlayerCatalysisEvent(player, catalysis); |             McMMOPlayerCatalysisEvent event = new McMMOPlayerCatalysisEvent(player, catalysis); | ||||||
|             Bukkit.getPluginManager().callEvent(event); |             Bukkit.getPluginManager().callEvent(event); | ||||||
|             if (!event.isCancelled()) { |             if (!event.isCancelled()) { | ||||||
|                 brewSpeed = catalysis; |                 brewSpeed = catalysis; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|          |  | ||||||
|         if (Alchemy.brewingStandMap.containsKey(brewingStand)) { |         if (Alchemy.brewingStandMap.containsKey(brewingStand)) { | ||||||
|             Alchemy.brewingStandMap.get(brewingStand).cancel(); |             Alchemy.brewingStandMap.get(brewingStand).cancel(); | ||||||
|         } |         } | ||||||
|          |  | ||||||
|         Alchemy.brewingStandMap.put(brewingStand, this); |         Alchemy.brewingStandMap.put(brewingStand, this); | ||||||
|         this.runTaskTimer(mcMMO.p, 1, 1); |         this.runTaskTimer(mcMMO.p, 1, 1); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void run() { |     public void run() { | ||||||
|  |         if (brewingStand.getType() != Material.BREWING_STAND) { | ||||||
|  |             if (Alchemy.brewingStandMap.containsKey(brewingStand)) { | ||||||
|  |                 Alchemy.brewingStandMap.remove(brewingStand); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             this.cancel(); | ||||||
|  |  | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         brewTimer -= brewSpeed; |         brewTimer -= brewSpeed; | ||||||
|  |  | ||||||
|         // Vanilla potion brewing completes when BrewingTime == 1 |         // Vanilla potion brewing completes when BrewingTime == 1 | ||||||
| @@ -72,24 +83,24 @@ public class AlchemyBrewTask extends BukkitRunnable { | |||||||
|     private void finish() { |     private void finish() { | ||||||
|         McMMOPlayerBrewEvent event = new McMMOPlayerBrewEvent(player, brewingStand); |         McMMOPlayerBrewEvent event = new McMMOPlayerBrewEvent(player, brewingStand); | ||||||
|         Bukkit.getPluginManager().callEvent(event); |         Bukkit.getPluginManager().callEvent(event); | ||||||
|          |  | ||||||
|         if (!event.isCancelled()) { |         if (!event.isCancelled()) { | ||||||
|             AlchemyPotionBrewer.finishBrewing(brewingStand, player, false); |             AlchemyPotionBrewer.finishBrewing(brewingStand, player, false); | ||||||
|         } |         } | ||||||
|          |  | ||||||
|         Alchemy.brewingStandMap.remove(brewingStand); |         Alchemy.brewingStandMap.remove(brewingStand); | ||||||
|     } |     } | ||||||
|      |  | ||||||
|     public void finishImmediately() { |     public void finishImmediately() { | ||||||
|         this.cancel(); |         this.cancel(); | ||||||
|          |  | ||||||
|         AlchemyPotionBrewer.finishBrewing(brewingStand, player, true); |         AlchemyPotionBrewer.finishBrewing(brewingStand, player, true); | ||||||
|         Alchemy.brewingStandMap.remove(brewingStand); |         Alchemy.brewingStandMap.remove(brewingStand); | ||||||
|     } |     } | ||||||
|      |  | ||||||
|     public void cancelBrew() { |     public void cancelBrew() { | ||||||
|         this.cancel(); |         this.cancel(); | ||||||
|          |  | ||||||
|         ((BrewingStand) brewingStand.getState()).setBrewingTime(-1); |         ((BrewingStand) brewingStand.getState()).setBrewingTime(-1); | ||||||
|         Alchemy.brewingStandMap.remove(brewingStand); |         Alchemy.brewingStandMap.remove(brewingStand); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 TfT_02
					TfT_02