mcMMO/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewCheckTask.java

41 lines
1.5 KiB
Java
Raw Normal View History

2013-11-16 00:21:00 +01:00
package com.gmail.nossr50.runnables.skills;
import java.util.Arrays;
import org.bukkit.Location;
2013-11-16 00:21:00 +01:00
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;
private BrewingStand brewingStand;
2013-11-16 00:21:00 +01:00
private ItemStack[] oldInventory;
2013-11-16 00:21:00 +01:00
public AlchemyBrewCheckTask(Player player, BrewingStand brewingStand) {
this.player = player;
this.brewingStand = brewingStand;
2013-11-16 00:21:00 +01:00
this.oldInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4);
}
2013-11-16 00:21:00 +01:00
@Override
public void run() {
Location location = brewingStand.getLocation();
ItemStack[] newInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4);
boolean validBrew = AlchemyPotionBrewer.isValidBrew(player, newInventory);
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();
2013-11-16 00:21:00 +01:00
}
}
else if (validBrew) {
Alchemy.brewingStandMap.put(location, new AlchemyBrewTask(brewingStand, player));
2013-11-16 00:21:00 +01:00
}
}
}