From a848ba4e8de645fca5f6cae8f99ed299d1448c38 Mon Sep 17 00:00:00 2001 From: alxl Date: Sun, 29 Nov 2020 17:16:24 -0600 Subject: [PATCH] Handle negative alcohol values --- src/com/dre/brewery/BPlayer.java | 23 ++++++++++++++++------- src/com/dre/brewery/recipe/BRecipe.java | 4 ---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index 1e03e20..015954e 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -180,21 +180,25 @@ public class BPlayer { int quality = drinkEvent.getQuality(); List effects = getBrewEffects(brew.getEffects(), quality); - if (brewAlc < 1) { + if (brewAlc == 0) { //no alcohol so we dont need to add a BPlayer applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK); if (bPlayer.drunkeness <= 0) { bPlayer.remove(); } - return true; } - bPlayer.drunkeness += brewAlc; - if (quality > 0) { - bPlayer.quality += quality * brewAlc; + if (brewAlc > 0) { + bPlayer.drunkeness += brewAlc; + if (quality > 0) { + bPlayer.quality += quality * brewAlc; + } else { + bPlayer.quality += brewAlc; + } } else { - bPlayer.quality += brewAlc; + bPlayer.drainAndRemove(player, -brewAlc); } + applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK); applyEffects(getQualityEffects(quality, brewAlc), player, PlayerEffectEvent.EffectType.QUALITY); @@ -202,6 +206,7 @@ public class BPlayer { bPlayer.drinkCap(player); } bPlayer.syncToSQL(false); + if (BConfig.showStatusOnDrink) { bPlayer.showDrunkeness(player); } @@ -336,7 +341,11 @@ public class BPlayer { // Eat something to drain the drunkeness public void drainByItem(Player player, Material mat) { int strength = BConfig.drainItems.get(mat); - if (drain(player, strength)) { + drainAndRemove(player, strength); + } + + public void drainAndRemove(Player player, int amount) { + if (drain(player, amount)) { remove(player); } } diff --git a/src/com/dre/brewery/recipe/BRecipe.java b/src/com/dre/brewery/recipe/BRecipe.java index 3d3d1e1..2fab5f8 100644 --- a/src/com/dre/brewery/recipe/BRecipe.java +++ b/src/com/dre/brewery/recipe/BRecipe.java @@ -338,10 +338,6 @@ public class BRecipe { P.p.errorLog("Invalid difficulty '" + difficulty + "' in Recipe: " + getRecipeName()); return false; } - if (alcohol < 0) { - P.p.errorLog("Invalid alcohol '" + alcohol + "' in Recipe: " + getRecipeName()); - return false; - } return true; }