mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
parent
b50ba9c02e
commit
6264bfa15f
@ -1,6 +1,7 @@
|
|||||||
package com.gmail.nossr50.events.skills.alchemy;
|
package com.gmail.nossr50.events.skills.alchemy;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.BrewingStand;
|
import org.bukkit.block.BrewingStand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
@ -9,11 +10,11 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
|
|||||||
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
|
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
|
||||||
|
|
||||||
public class McMMOPlayerBrewEvent extends McMMOPlayerSkillEvent implements Cancellable {
|
public class McMMOPlayerBrewEvent extends McMMOPlayerSkillEvent implements Cancellable {
|
||||||
private Block brewingStand;
|
private BlockState brewingStand;
|
||||||
|
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public McMMOPlayerBrewEvent(Player player, Block brewingStand) {
|
public McMMOPlayerBrewEvent(Player player, BlockState brewingStand) {
|
||||||
super(player, SkillType.ALCHEMY);
|
super(player, SkillType.ALCHEMY);
|
||||||
this.brewingStand = brewingStand;
|
this.brewingStand = brewingStand;
|
||||||
cancelled = false;
|
cancelled = false;
|
||||||
@ -28,10 +29,10 @@ public class McMMOPlayerBrewEvent extends McMMOPlayerSkillEvent implements Cance
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Block getBrewingStandBlock() {
|
public Block getBrewingStandBlock() {
|
||||||
return brewingStand;
|
return brewingStand.getBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BrewingStand getBrewingStand() {
|
public BrewingStand getBrewingStand() {
|
||||||
return brewingStand.getState() instanceof BrewingStand ? (BrewingStand) brewingStand.getState() : null;
|
return (BrewingStand) brewingStand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,18 +15,19 @@ public class AlchemyBrewCheckTask extends BukkitRunnable {
|
|||||||
private final static int INGREDIENT_SLOT = 3;
|
private final static int INGREDIENT_SLOT = 3;
|
||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
private Block brewingStand;
|
private BrewingStand brewingStand;
|
||||||
private ItemStack[] oldInventory;
|
private ItemStack[] oldInventory;
|
||||||
|
|
||||||
public AlchemyBrewCheckTask(Player player, BrewingStand brewingStand) {
|
public AlchemyBrewCheckTask(Player player, BrewingStand brewingStand) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.brewingStand = brewingStand.getBlock();
|
this.brewingStand = brewingStand;
|
||||||
this.oldInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4);
|
this.oldInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ItemStack[] newInventory = Arrays.copyOfRange(((BrewingStand) brewingStand.getState()).getInventory().getContents(), 0, 4);
|
Block block = brewingStand.getBlock();
|
||||||
|
ItemStack[] newInventory = Arrays.copyOfRange(((BrewingStand) block.getState()).getInventory().getContents(), 0, 4);
|
||||||
|
|
||||||
if (Alchemy.brewingStandMap.containsKey(brewingStand)) {
|
if (Alchemy.brewingStandMap.containsKey(brewingStand)) {
|
||||||
if (oldInventory[INGREDIENT_SLOT] == null || newInventory[INGREDIENT_SLOT] == null || !oldInventory[INGREDIENT_SLOT].isSimilar(newInventory[INGREDIENT_SLOT]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) {
|
if (oldInventory[INGREDIENT_SLOT] == null || newInventory[INGREDIENT_SLOT] == null || !oldInventory[INGREDIENT_SLOT].isSimilar(newInventory[INGREDIENT_SLOT]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.gmail.nossr50.runnables.skills;
|
package com.gmail.nossr50.runnables.skills;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.BrewingStand;
|
import org.bukkit.block.BrewingStand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@ -21,12 +21,12 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
private static double DEFAULT_BREW_SPEED = 1.0;
|
private static double DEFAULT_BREW_SPEED = 1.0;
|
||||||
private static int DEFAULT_BREW_TICKS = 400;
|
private static int DEFAULT_BREW_TICKS = 400;
|
||||||
|
|
||||||
private Block brewingStand;
|
private BlockState brewingStand;
|
||||||
private double brewSpeed;
|
private double brewSpeed;
|
||||||
private double brewTimer;
|
private double brewTimer;
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
public AlchemyBrewTask(Block brewingStand, Player player) {
|
public AlchemyBrewTask(BlockState brewingStand, Player player) {
|
||||||
this.brewingStand = brewingStand;
|
this.brewingStand = brewingStand;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
((BrewingStand) brewingStand.getState()).setBrewingTime((int) brewTimer);
|
((BrewingStand) brewingStand).setBrewingTime((int) brewTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public class AlchemyBrewTask extends BukkitRunnable {
|
|||||||
public void cancelBrew() {
|
public void cancelBrew() {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
||||||
((BrewingStand) brewingStand.getState()).setBrewingTime(-1);
|
((BrewingStand) brewingStand).setBrewingTime(-1);
|
||||||
Alchemy.brewingStandMap.remove(brewingStand);
|
Alchemy.brewingStandMap.remove(brewingStand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package com.gmail.nossr50.skills.alchemy;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.BlockState;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.AdvancedConfig;
|
import com.gmail.nossr50.config.AdvancedConfig;
|
||||||
@ -49,7 +49,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<Block, AlchemyBrewTask> brewingStandMap = new HashMap<Block, AlchemyBrewTask>();
|
public static Map<BlockState, AlchemyBrewTask> brewingStandMap = new HashMap<BlockState, AlchemyBrewTask>();
|
||||||
|
|
||||||
private Alchemy() {}
|
private Alchemy() {}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package com.gmail.nossr50.skills.alchemy;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.BrewingStand;
|
import org.bukkit.block.BrewingStand;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -119,12 +119,12 @@ public final class AlchemyPotionBrewer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void finishBrewing(Block brewingStand, Player player, boolean forced) {
|
public static void finishBrewing(BlockState brewingStand, Player player, boolean forced) {
|
||||||
if (!(brewingStand.getState() instanceof BrewingStand)) {
|
if (!(brewingStand instanceof BrewingStand)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BrewerInventory inventory = ((BrewingStand) brewingStand.getState()).getInventory();
|
BrewerInventory inventory = ((BrewingStand) brewingStand).getInventory();
|
||||||
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
|
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
|
||||||
|
|
||||||
if (!removeIngredient(inventory, player)) {
|
if (!removeIngredient(inventory, player)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user