mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
parent
f3fd48d0c0
commit
f79a4741cc
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<BlockState, AlchemyBrewTask> brewingStandMap = new HashMap<BlockState, AlchemyBrewTask>();
|
||||
public static Map<Location, AlchemyBrewTask> brewingStandMap = new HashMap<Location, AlchemyBrewTask>();
|
||||
|
||||
private Alchemy() {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user