2013-11-16 00:21:00 +01:00
|
|
|
package com.gmail.nossr50.runnables.skills;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BrewingStand;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.skills.alchemy.Alchemy;
|
|
|
|
import com.gmail.nossr50.skills.alchemy.AlchemyPotionBrewer;
|
|
|
|
|
|
|
|
public class AlchemyBrewCheckTask extends BukkitRunnable {
|
|
|
|
private Player player;
|
2014-01-30 20:45:21 +01:00
|
|
|
private BrewingStand brewingStand;
|
2013-11-16 00:21:00 +01:00
|
|
|
private ItemStack[] oldInventory;
|
2014-01-18 19:11:15 +01:00
|
|
|
|
2013-11-16 00:21:00 +01:00
|
|
|
public AlchemyBrewCheckTask(Player player, BrewingStand brewingStand) {
|
|
|
|
this.player = player;
|
2014-01-30 20:45:21 +01:00
|
|
|
this.brewingStand = brewingStand;
|
2013-11-16 00:21:00 +01:00
|
|
|
this.oldInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4);
|
|
|
|
}
|
2014-01-18 19:11:15 +01:00
|
|
|
|
2013-11-16 00:21:00 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-01-30 20:45:21 +01:00
|
|
|
Block block = brewingStand.getBlock();
|
|
|
|
ItemStack[] newInventory = Arrays.copyOfRange(((BrewingStand) block.getState()).getInventory().getContents(), 0, 4);
|
2014-01-18 19:11:15 +01:00
|
|
|
|
2013-11-16 00:21:00 +01:00
|
|
|
if (Alchemy.brewingStandMap.containsKey(brewingStand)) {
|
2014-02-11 22:22:57 +01:00
|
|
|
if (oldInventory[Alchemy.INGREDIENT_SLOT] == null || newInventory[Alchemy.INGREDIENT_SLOT] == null || !oldInventory[Alchemy.INGREDIENT_SLOT].isSimilar(newInventory[Alchemy.INGREDIENT_SLOT]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) {
|
2013-11-16 00:21:00 +01:00
|
|
|
Alchemy.brewingStandMap.get(brewingStand).cancelBrew();
|
|
|
|
}
|
|
|
|
}
|
2014-01-20 22:38:04 +01:00
|
|
|
|
2013-11-16 00:21:00 +01:00
|
|
|
if (!Alchemy.brewingStandMap.containsKey(brewingStand) && AlchemyPotionBrewer.isValidBrew(player, newInventory)) {
|
|
|
|
Alchemy.brewingStandMap.put(brewingStand, new AlchemyBrewTask(brewingStand, player));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|