From 6264bfa15faaeda7141aba6048310532249e01c1 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Thu, 30 Jan 2014 20:45:21 +0100 Subject: [PATCH] Don't store Block objects, use BlockState Fixes #1811, Closes #1822 --- .../events/skills/alchemy/McMMOPlayerBrewEvent.java | 9 +++++---- .../nossr50/runnables/skills/AlchemyBrewCheckTask.java | 7 ++++--- .../nossr50/runnables/skills/AlchemyBrewTask.java | 10 +++++----- .../java/com/gmail/nossr50/skills/alchemy/Alchemy.java | 4 ++-- .../nossr50/skills/alchemy/AlchemyPotionBrewer.java | 8 ++++---- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/events/skills/alchemy/McMMOPlayerBrewEvent.java b/src/main/java/com/gmail/nossr50/events/skills/alchemy/McMMOPlayerBrewEvent.java index 983a11a82..0152b30e9 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/alchemy/McMMOPlayerBrewEvent.java +++ b/src/main/java/com/gmail/nossr50/events/skills/alchemy/McMMOPlayerBrewEvent.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.events.skills.alchemy; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.BrewingStand; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; @@ -9,11 +10,11 @@ import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent; public class McMMOPlayerBrewEvent extends McMMOPlayerSkillEvent implements Cancellable { - private Block brewingStand; + private BlockState brewingStand; private boolean cancelled; - public McMMOPlayerBrewEvent(Player player, Block brewingStand) { + public McMMOPlayerBrewEvent(Player player, BlockState brewingStand) { super(player, SkillType.ALCHEMY); this.brewingStand = brewingStand; cancelled = false; @@ -28,10 +29,10 @@ public class McMMOPlayerBrewEvent extends McMMOPlayerSkillEvent implements Cance } public Block getBrewingStandBlock() { - return brewingStand; + return brewingStand.getBlock(); } public BrewingStand getBrewingStand() { - return brewingStand.getState() instanceof BrewingStand ? (BrewingStand) brewingStand.getState() : null; + return (BrewingStand) brewingStand; } } 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 c098af995..62e414223 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewCheckTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewCheckTask.java @@ -15,18 +15,19 @@ public class AlchemyBrewCheckTask extends BukkitRunnable { private final static int INGREDIENT_SLOT = 3; private Player player; - private Block brewingStand; + private BrewingStand brewingStand; private ItemStack[] oldInventory; public AlchemyBrewCheckTask(Player player, BrewingStand brewingStand) { this.player = player; - this.brewingStand = brewingStand.getBlock(); + this.brewingStand = brewingStand; this.oldInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4); } @Override public void run() { - ItemStack[] newInventory = Arrays.copyOfRange(((BrewingStand) brewingStand.getState()).getInventory().getContents(), 0, 4); + Block block = brewingStand.getBlock(); + ItemStack[] newInventory = Arrays.copyOfRange(((BrewingStand) block.getState()).getInventory().getContents(), 0, 4); 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)) { 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 8bf8fa938..b100d5a06 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java @@ -1,7 +1,7 @@ package com.gmail.nossr50.runnables.skills; import org.bukkit.Material; -import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.BrewingStand; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -21,12 +21,12 @@ public class AlchemyBrewTask extends BukkitRunnable { private static double DEFAULT_BREW_SPEED = 1.0; private static int DEFAULT_BREW_TICKS = 400; - private Block brewingStand; + private BlockState brewingStand; private double brewSpeed; private double brewTimer; private Player player; - public AlchemyBrewTask(Block brewingStand, Player player) { + public AlchemyBrewTask(BlockState brewingStand, Player player) { this.brewingStand = brewingStand; this.player = player; @@ -75,7 +75,7 @@ public class AlchemyBrewTask extends BukkitRunnable { finish(); } else { - ((BrewingStand) brewingStand.getState()).setBrewingTime((int) brewTimer); + ((BrewingStand) brewingStand).setBrewingTime((int) brewTimer); } } @@ -100,7 +100,7 @@ public class AlchemyBrewTask extends BukkitRunnable { public void cancelBrew() { this.cancel(); - ((BrewingStand) brewingStand.getState()).setBrewingTime(-1); + ((BrewingStand) brewingStand).setBrewingTime(-1); Alchemy.brewingStandMap.remove(brewingStand); } } 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 4f4aec379..be7b0628b 100644 --- a/src/main/java/com/gmail/nossr50/skills/alchemy/Alchemy.java +++ b/src/main/java/com/gmail/nossr50/skills/alchemy/Alchemy.java @@ -3,7 +3,7 @@ package com.gmail.nossr50.skills.alchemy; import java.util.HashMap; import java.util.Map; -import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.AdvancedConfig; @@ -49,7 +49,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() {} diff --git a/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java b/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java index 0f4cde55e..40209ecb5 100644 --- a/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java +++ b/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java @@ -3,7 +3,7 @@ package com.gmail.nossr50.skills.alchemy; import java.util.List; import org.bukkit.Material; -import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.BrewingStand; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; @@ -119,12 +119,12 @@ public final class AlchemyPotionBrewer { } } - public static void finishBrewing(Block brewingStand, Player player, boolean forced) { - if (!(brewingStand.getState() instanceof BrewingStand)) { + public static void finishBrewing(BlockState brewingStand, Player player, boolean forced) { + if (!(brewingStand instanceof BrewingStand)) { return; } - BrewerInventory inventory = ((BrewingStand) brewingStand.getState()).getInventory(); + BrewerInventory inventory = ((BrewingStand) brewingStand).getInventory(); ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone(); if (!removeIngredient(inventory, player)) {