From f79a4741cc0cf1e1b7e232cfc4700a9df49c6da9 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Sat, 15 Feb 2014 01:31:13 +0100 Subject: [PATCH] Store Locations, not BlockStates Fixes #1862 --- .../nossr50/listeners/InventoryListener.java | 8 +++----- .../skills/AlchemyBrewCheckTask.java | 18 +++++++++--------- .../runnables/skills/AlchemyBrewTask.java | 19 +++++++++++-------- .../gmail/nossr50/skills/alchemy/Alchemy.java | 4 ++-- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java index c120698e4..d5b4d1e3a 100644 --- a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java @@ -197,11 +197,9 @@ public class InventoryListener implements Listener { boolean emptyClicked = AlchemyPotionBrewer.isEmpty(clicked); if (AlchemyPotionBrewer.isEmpty(cursor)) { - if (emptyClicked) { - if (click == ClickType.NUMBER_KEY) { - AlchemyPotionBrewer.scheduleCheck(player, stand); - return; - } + if (emptyClicked && click == ClickType.NUMBER_KEY) { + AlchemyPotionBrewer.scheduleCheck(player, stand); + return; } AlchemyPotionBrewer.scheduleCheck(player, stand); diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewCheckTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewCheckTask.java index d0a12bc76..c1517ec64 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewCheckTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewCheckTask.java @@ -2,7 +2,7 @@ package com.gmail.nossr50.runnables.skills; import java.util.Arrays; -import org.bukkit.block.Block; +import org.bukkit.Location; import org.bukkit.block.BrewingStand; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -24,17 +24,17 @@ public class AlchemyBrewCheckTask extends BukkitRunnable { @Override public void run() { - Block block = brewingStand.getBlock(); - ItemStack[] newInventory = Arrays.copyOfRange(((BrewingStand) block.getState()).getInventory().getContents(), 0, 4); + Location location = brewingStand.getLocation(); + ItemStack[] newInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4); + boolean validBrew = AlchemyPotionBrewer.isValidBrew(player, newInventory); - if (Alchemy.brewingStandMap.containsKey(brewingStand)) { - if (oldInventory[Alchemy.INGREDIENT_SLOT] == null || newInventory[Alchemy.INGREDIENT_SLOT] == null || !oldInventory[Alchemy.INGREDIENT_SLOT].isSimilar(newInventory[Alchemy.INGREDIENT_SLOT]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) { - Alchemy.brewingStandMap.get(brewingStand).cancelBrew(); + if (Alchemy.brewingStandMap.containsKey(location)) { + if (oldInventory[Alchemy.INGREDIENT_SLOT] == null || newInventory[Alchemy.INGREDIENT_SLOT] == null || !oldInventory[Alchemy.INGREDIENT_SLOT].isSimilar(newInventory[Alchemy.INGREDIENT_SLOT]) || !validBrew) { + Alchemy.brewingStandMap.get(location).cancelBrew(); } } - - if (!Alchemy.brewingStandMap.containsKey(brewingStand) && AlchemyPotionBrewer.isValidBrew(player, newInventory)) { - Alchemy.brewingStandMap.put(brewingStand, new AlchemyBrewTask(brewingStand, player)); + else if (validBrew) { + Alchemy.brewingStandMap.put(location, new AlchemyBrewTask(brewingStand, player)); } } } diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java index 0cde3181f..cfcac3ca5 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.runnables.skills; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.BlockState; import org.bukkit.block.BrewingStand; @@ -22,12 +23,14 @@ public class AlchemyBrewTask extends BukkitRunnable { private static int DEFAULT_BREW_TICKS = 400; private BlockState brewingStand; + private Location location; private double brewSpeed; private double brewTimer; private Player player; public AlchemyBrewTask(BlockState brewingStand, Player player) { this.brewingStand = brewingStand; + this.location = brewingStand.getLocation(); this.player = player; brewSpeed = DEFAULT_BREW_SPEED; @@ -44,19 +47,19 @@ public class AlchemyBrewTask extends BukkitRunnable { } } - if (Alchemy.brewingStandMap.containsKey(brewingStand)) { - Alchemy.brewingStandMap.get(brewingStand).cancel(); + if (Alchemy.brewingStandMap.containsKey(location)) { + Alchemy.brewingStandMap.get(location).cancel(); } - Alchemy.brewingStandMap.put(brewingStand, this); + Alchemy.brewingStandMap.put(location, this); this.runTaskTimer(mcMMO.p, 1, 1); } @Override public void run() { if (player == null || !player.isValid() || brewingStand == null || brewingStand.getType() != Material.BREWING_STAND) { - if (Alchemy.brewingStandMap.containsKey(brewingStand)) { - Alchemy.brewingStandMap.remove(brewingStand); + if (Alchemy.brewingStandMap.containsKey(location)) { + Alchemy.brewingStandMap.remove(location); } this.cancel(); @@ -84,20 +87,20 @@ public class AlchemyBrewTask extends BukkitRunnable { AlchemyPotionBrewer.finishBrewing(brewingStand, player, false); } - Alchemy.brewingStandMap.remove(brewingStand); + Alchemy.brewingStandMap.remove(location); } public void finishImmediately() { this.cancel(); AlchemyPotionBrewer.finishBrewing(brewingStand, player, true); - Alchemy.brewingStandMap.remove(brewingStand); + Alchemy.brewingStandMap.remove(location); } public void cancelBrew() { this.cancel(); ((BrewingStand) brewingStand).setBrewingTime(-1); - Alchemy.brewingStandMap.remove(brewingStand); + Alchemy.brewingStandMap.remove(location); } } diff --git a/src/main/java/com/gmail/nossr50/skills/alchemy/Alchemy.java b/src/main/java/com/gmail/nossr50/skills/alchemy/Alchemy.java index 1873dae70..e992c490f 100644 --- a/src/main/java/com/gmail/nossr50/skills/alchemy/Alchemy.java +++ b/src/main/java/com/gmail/nossr50/skills/alchemy/Alchemy.java @@ -5,7 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.bukkit.block.BlockState; +import org.bukkit.Location; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.AdvancedConfig; @@ -53,7 +53,7 @@ public final class Alchemy { public static double catalysisMinSpeed = AdvancedConfig.getInstance().getCatalysisMinSpeed(); public static double catalysisMaxSpeed = AdvancedConfig.getInstance().getCatalysisMaxSpeed(); - public static Map brewingStandMap = new HashMap(); + public static Map brewingStandMap = new HashMap(); private Alchemy() {}