mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user