Fixed cauldron duplication bug

This commit is contained in:
Sn0wStorm
2015-03-14 21:57:56 +01:00
parent 1f16c6af04
commit 02b909a26a
4 changed files with 56 additions and 45 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<groupId>com.dre</groupId> <groupId>com.dre</groupId>
<artifactId>brewery</artifactId> <artifactId>brewery</artifactId>
<version>1.3.1</version> <version>1.3.2</version>
<name>Brewery</name> <name>Brewery</name>
<properties> <properties>
+1 -1
View File
@@ -1,5 +1,5 @@
name: Brewery name: Brewery
version: 1.3.1 version: 1.3.2
main: com.dre.brewery.P main: com.dre.brewery.P
authors: [Milan Albrecht, Frank Baumann] authors: [Milan Albrecht, Frank Baumann]
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention] softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention]
+16 -10
View File
@@ -97,22 +97,28 @@ public class BCauldron {
} }
ItemStack potion = bcauldron.ingredients.cook(bcauldron.state); ItemStack potion = bcauldron.ingredients.cook(bcauldron.state);
if (potion != null) { if (potion != null) {
byte data = block.getData();
if (data > 3) {
data = 3;
block.setData(data);
} else if (data <= 0) {
bcauldrons.remove(bcauldron);
return false;
}
data -= 1;
block.setData(data);
if (data == 0) {
bcauldrons.remove(bcauldron);
} else {
bcauldron.someRemoved = true;
}
// Bukkit Bug, inventory not updating while in event so this // Bukkit Bug, inventory not updating while in event so this
// will delay the give // will delay the give
// but could also just use deprecated updateInventory() // but could also just use deprecated updateInventory()
giveItem(player, potion); giveItem(player, potion);
// player.getInventory().addItem(potion); // player.getInventory().addItem(potion);
// player.getInventory().updateInventory(); // player.getInventory().updateInventory();
if (block.getData() > 3) {
block.setData((byte) 3);
}
block.setData((byte) (block.getData() - 1));
if (block.getData() == 0) {
bcauldrons.remove(bcauldron);
} else {
bcauldron.someRemoved = true;
}
return true; return true;
} }
} }
@@ -34,46 +34,51 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (!player.isSneaking()) { if (!player.isSneaking()) {
Material type = clickedBlock.getType(); Material type = clickedBlock.getType();
// Interacting with a Cauldron
if (type == Material.CAULDRON) { if (type == Material.CAULDRON) {
Block down = clickedBlock.getRelative(BlockFace.DOWN); Material materialInHand = event.getMaterial();
if (down.getType() == Material.FIRE || down.getType() == Material.STATIONARY_LAVA || down.getType() == Material.LAVA) { ItemStack item = event.getItem();
Material materialInHand = event.getMaterial();
ItemStack item = event.getItem();
if (materialInHand == Material.WATCH) {
if (materialInHand == Material.WATCH) { BCauldron.printTime(player, clickedBlock);
BCauldron.printTime(player, clickedBlock); return;
// fill a glass bottle with potion // fill a glass bottle with potion
} else if (materialInHand == Material.GLASS_BOTTLE) { } else if (materialInHand == Material.GLASS_BOTTLE) {
if (player.getInventory().firstEmpty() != -1 || item.getAmount() == 1) { if (player.getInventory().firstEmpty() != -1 || item.getAmount() == 1) {
if (BCauldron.fill(player, clickedBlock)) { if (BCauldron.fill(player, clickedBlock)) {
event.setCancelled(true); event.setCancelled(true);
if (player.hasPermission("brewery.cauldron.fill")) { if (player.hasPermission("brewery.cauldron.fill")) {
if (item.getAmount() > 1) { if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1); item.setAmount(item.getAmount() - 1);
} else { } else {
player.setItemInHand(new ItemStack(Material.AIR)); player.setItemInHand(new ItemStack(Material.AIR));
}
} }
} }
} else {
event.setCancelled(true);
} }
} else {
event.setCancelled(true);
}
return;
// reset cauldron when refilling to prevent // reset cauldron when refilling to prevent
// unlimited source of potions // unlimited source of potions
} else if (materialInHand == Material.WATER_BUCKET) { } else if (materialInHand == Material.WATER_BUCKET) {
if (BCauldron.getFillLevel(clickedBlock) != 0) { if (BCauldron.getFillLevel(clickedBlock) != 0 && BCauldron.getFillLevel(clickedBlock) < 2) {
if (BCauldron.getFillLevel(clickedBlock) < 2) { // will only remove when existing
// will only remove when existing BCauldron.remove(clickedBlock);
BCauldron.remove(clickedBlock); }
} return;
} }
// Check if fire alive below cauldron when adding ingredients
Block down = clickedBlock.getRelative(BlockFace.DOWN);
if (down.getType() == Material.FIRE || down.getType() == Material.STATIONARY_LAVA || down.getType() == Material.LAVA) {
// add ingredient to cauldron that meet the previous conditions
if (BIngredients.possibleIngredients.contains(materialInHand)) {
// add ingredient to cauldron that meet the previous
// contitions
} else if (BIngredients.possibleIngredients.contains(materialInHand)) {
if (player.hasPermission("brewery.cauldron.insert")) { if (player.hasPermission("brewery.cauldron.insert")) {
if (BCauldron.ingredientAdd(clickedBlock, item)) { if (BCauldron.ingredientAdd(clickedBlock, item)) {
boolean isBucket = item.getType().equals(Material.WATER_BUCKET) boolean isBucket = item.getType().equals(Material.WATER_BUCKET)
@@ -100,8 +105,8 @@ public class PlayerListener implements Listener {
} else { } else {
event.setCancelled(true); event.setCancelled(true);
} }
return;
} }
return;
} }
// Access a Barrel // Access a Barrel