mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
parent
f3fd48d0c0
commit
f79a4741cc
@ -197,11 +197,9 @@ public class InventoryListener implements Listener {
|
|||||||
boolean emptyClicked = AlchemyPotionBrewer.isEmpty(clicked);
|
boolean emptyClicked = AlchemyPotionBrewer.isEmpty(clicked);
|
||||||
|
|
||||||
if (AlchemyPotionBrewer.isEmpty(cursor)) {
|
if (AlchemyPotionBrewer.isEmpty(cursor)) {
|
||||||
if (emptyClicked) {
|
if (emptyClicked && click == ClickType.NUMBER_KEY) {
|
||||||
if (click == ClickType.NUMBER_KEY) {
|
AlchemyPotionBrewer.scheduleCheck(player, stand);
|
||||||
AlchemyPotionBrewer.scheduleCheck(player, stand);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AlchemyPotionBrewer.scheduleCheck(player, stand);
|
AlchemyPotionBrewer.scheduleCheck(player, stand);
|
||||||
|
@ -2,7 +2,7 @@ package com.gmail.nossr50.runnables.skills;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.BrewingStand;
|
import org.bukkit.block.BrewingStand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -24,17 +24,17 @@ public class AlchemyBrewCheckTask extends BukkitRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Block block = brewingStand.getBlock();
|
Location location = brewingStand.getLocation();
|
||||||
ItemStack[] newInventory = Arrays.copyOfRange(((BrewingStand) block.getState()).getInventory().getContents(), 0, 4);
|
ItemStack[] newInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4);
|
||||||
|
boolean validBrew = AlchemyPotionBrewer.isValidBrew(player, newInventory);
|
||||||
|
|
||||||
if (Alchemy.brewingStandMap.containsKey(brewingStand)) {
|
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]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) {
|
if (oldInventory[Alchemy.INGREDIENT_SLOT] == null || newInventory[Alchemy.INGREDIENT_SLOT] == null || !oldInventory[Alchemy.INGREDIENT_SLOT].isSimilar(newInventory[Alchemy.INGREDIENT_SLOT]) || !validBrew) {
|
||||||
Alchemy.brewingStandMap.get(brewingStand).cancelBrew();
|
Alchemy.brewingStandMap.get(location).cancelBrew();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (validBrew) {
|
||||||
if (!Alchemy.brewingStandMap.containsKey(brewingStand) && AlchemyPotionBrewer.isValidBrew(player, newInventory)) {
|
Alchemy.brewingStandMap.put(location, new AlchemyBrewTask(brewingStand, player));
|
||||||
Alchemy.brewingStandMap.put(brewingStand, new AlchemyBrewTask(brewingStand, player));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.runnables.skills;
|
package com.gmail.nossr50.runnables.skills;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.BrewingStand;
|
import org.bukkit.block.BrewingStand;
|
||||||
@ -22,12 +23,14 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
private static int DEFAULT_BREW_TICKS = 400;
|
private static int DEFAULT_BREW_TICKS = 400;
|
||||||
|
|
||||||
private BlockState brewingStand;
|
private BlockState brewingStand;
|
||||||
|
private Location location;
|
||||||
private double brewSpeed;
|
private double brewSpeed;
|
||||||
private double brewTimer;
|
private double brewTimer;
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
public AlchemyBrewTask(BlockState brewingStand, Player player) {
|
public AlchemyBrewTask(BlockState brewingStand, Player player) {
|
||||||
this.brewingStand = brewingStand;
|
this.brewingStand = brewingStand;
|
||||||
|
this.location = brewingStand.getLocation();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
brewSpeed = DEFAULT_BREW_SPEED;
|
brewSpeed = DEFAULT_BREW_SPEED;
|
||||||
@ -44,19 +47,19 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Alchemy.brewingStandMap.containsKey(brewingStand)) {
|
if (Alchemy.brewingStandMap.containsKey(location)) {
|
||||||
Alchemy.brewingStandMap.get(brewingStand).cancel();
|
Alchemy.brewingStandMap.get(location).cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
Alchemy.brewingStandMap.put(brewingStand, this);
|
Alchemy.brewingStandMap.put(location, this);
|
||||||
this.runTaskTimer(mcMMO.p, 1, 1);
|
this.runTaskTimer(mcMMO.p, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (player == null || !player.isValid() || brewingStand == null || brewingStand.getType() != Material.BREWING_STAND) {
|
if (player == null || !player.isValid() || brewingStand == null || brewingStand.getType() != Material.BREWING_STAND) {
|
||||||
if (Alchemy.brewingStandMap.containsKey(brewingStand)) {
|
if (Alchemy.brewingStandMap.containsKey(location)) {
|
||||||
Alchemy.brewingStandMap.remove(brewingStand);
|
Alchemy.brewingStandMap.remove(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cancel();
|
this.cancel();
|
||||||
@ -84,20 +87,20 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
AlchemyPotionBrewer.finishBrewing(brewingStand, player, false);
|
AlchemyPotionBrewer.finishBrewing(brewingStand, player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Alchemy.brewingStandMap.remove(brewingStand);
|
Alchemy.brewingStandMap.remove(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finishImmediately() {
|
public void finishImmediately() {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
||||||
AlchemyPotionBrewer.finishBrewing(brewingStand, player, true);
|
AlchemyPotionBrewer.finishBrewing(brewingStand, player, true);
|
||||||
Alchemy.brewingStandMap.remove(brewingStand);
|
Alchemy.brewingStandMap.remove(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelBrew() {
|
public void cancelBrew() {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
||||||
((BrewingStand) brewingStand).setBrewingTime(-1);
|
((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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.AdvancedConfig;
|
import com.gmail.nossr50.config.AdvancedConfig;
|
||||||
@ -53,7 +53,7 @@ public final class Alchemy {
|
|||||||
public static double catalysisMinSpeed = AdvancedConfig.getInstance().getCatalysisMinSpeed();
|
public static double catalysisMinSpeed = AdvancedConfig.getInstance().getCatalysisMinSpeed();
|
||||||
public static double catalysisMaxSpeed = AdvancedConfig.getInstance().getCatalysisMaxSpeed();
|
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() {}
|
private Alchemy() {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user