mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-22 11:35:16 +01:00
Use Watch to display cooking time
This commit is contained in:
parent
a003d6ad23
commit
8e11062f56
@ -53,26 +53,36 @@ public class BCauldron {
|
||||
}
|
||||
}
|
||||
|
||||
// get cauldron by Block
|
||||
public static BCauldron get(Block block) {
|
||||
for (BCauldron bcauldron : bcauldrons) {
|
||||
if (bcauldron.block.equals(block)) {
|
||||
return bcauldron;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// get cauldron from block and add given ingredient
|
||||
public static boolean ingredientAdd(Block block, Material ingredient) {
|
||||
// if not empty
|
||||
if (block.getData() != 0) {
|
||||
for (BCauldron bcauldron : bcauldrons) {
|
||||
if (bcauldron.block.equals(block)) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
bcauldron.add(ingredient);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
new BCauldron(block, ingredient);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// fills players bottle with cooked brew
|
||||
public static boolean fill(Player player, Block block) {
|
||||
for (BCauldron bcauldron : bcauldrons) {
|
||||
if (bcauldron.block.equals(block)) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
ItemStack potion = bcauldron.ingredients.cook(bcauldron.state);
|
||||
if (potion != null) {
|
||||
// Bukkit Bug, inventory not updating while in event so this
|
||||
@ -92,18 +102,28 @@ public class BCauldron {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// prints the current cooking time to the player
|
||||
public static void printTime(Player player, Block block) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
if (bcauldron.state > 1) {
|
||||
P.p.msg(player, "Dieser Kessel siedet nun seit " + bcauldron.state + " Minuten");
|
||||
} else {
|
||||
P.p.msg(player, "Dieser Kessel siedet seit weniger als einer Minute");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reset to normal cauldron
|
||||
public static void remove(Block block) {
|
||||
for (BCauldron bcauldron : bcauldrons) {
|
||||
if (bcauldron.block.equals(block)) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//unloads cauldrons that are in a unloading world
|
||||
public static void onUnload(String name) {
|
||||
|
@ -36,16 +36,10 @@ public class PlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
// add ingredient to cauldron that meet the previous
|
||||
// contitions
|
||||
if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
||||
if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) {
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
} else {
|
||||
player.setItemInHand(new ItemStack(0));
|
||||
}
|
||||
}
|
||||
|
||||
if (materialInHand == Material.WATCH) {
|
||||
BCauldron.printTime(player, clickedBlock);
|
||||
|
||||
// fill a glass bottle with potion
|
||||
} else if (materialInHand == Material.GLASS_BOTTLE) {
|
||||
if (BCauldron.fill(player, clickedBlock)) {
|
||||
@ -56,6 +50,7 @@ public class PlayerListener implements Listener {
|
||||
player.setItemInHand(new ItemStack(0));
|
||||
}
|
||||
}
|
||||
|
||||
// reset cauldron when refilling to prevent
|
||||
// unlimited source of potions
|
||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||
@ -65,6 +60,17 @@ public class PlayerListener implements Listener {
|
||||
BCauldron.remove(clickedBlock);
|
||||
}
|
||||
}
|
||||
|
||||
// add ingredient to cauldron that meet the previous
|
||||
// contitions
|
||||
} else if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
||||
if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) {
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
} else {
|
||||
player.setItemInHand(new ItemStack(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// access a barrel
|
||||
|
Loading…
Reference in New Issue
Block a user