Handle negative alcohol values

This commit is contained in:
alxl 2020-11-29 17:16:24 -06:00
parent cb86a9000a
commit a848ba4e8d
2 changed files with 16 additions and 11 deletions

View File

@ -180,21 +180,25 @@ public class BPlayer {
int quality = drinkEvent.getQuality(); int quality = drinkEvent.getQuality();
List<PotionEffect> effects = getBrewEffects(brew.getEffects(), quality); List<PotionEffect> effects = getBrewEffects(brew.getEffects(), quality);
if (brewAlc < 1) { if (brewAlc == 0) {
//no alcohol so we dont need to add a BPlayer //no alcohol so we dont need to add a BPlayer
applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK); applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK);
if (bPlayer.drunkeness <= 0) { if (bPlayer.drunkeness <= 0) {
bPlayer.remove(); bPlayer.remove();
} }
return true;
} }
bPlayer.drunkeness += brewAlc; if (brewAlc > 0) {
if (quality > 0) { bPlayer.drunkeness += brewAlc;
bPlayer.quality += quality * brewAlc; if (quality > 0) {
bPlayer.quality += quality * brewAlc;
} else {
bPlayer.quality += brewAlc;
}
} else { } else {
bPlayer.quality += brewAlc; bPlayer.drainAndRemove(player, -brewAlc);
} }
applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK); applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK);
applyEffects(getQualityEffects(quality, brewAlc), player, PlayerEffectEvent.EffectType.QUALITY); applyEffects(getQualityEffects(quality, brewAlc), player, PlayerEffectEvent.EffectType.QUALITY);
@ -202,6 +206,7 @@ public class BPlayer {
bPlayer.drinkCap(player); bPlayer.drinkCap(player);
} }
bPlayer.syncToSQL(false); bPlayer.syncToSQL(false);
if (BConfig.showStatusOnDrink) { if (BConfig.showStatusOnDrink) {
bPlayer.showDrunkeness(player); bPlayer.showDrunkeness(player);
} }
@ -336,7 +341,11 @@ public class BPlayer {
// Eat something to drain the drunkeness // Eat something to drain the drunkeness
public void drainByItem(Player player, Material mat) { public void drainByItem(Player player, Material mat) {
int strength = BConfig.drainItems.get(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); remove(player);
} }
} }

View File

@ -338,10 +338,6 @@ public class BRecipe {
P.p.errorLog("Invalid difficulty '" + difficulty + "' in Recipe: " + getRecipeName()); P.p.errorLog("Invalid difficulty '" + difficulty + "' in Recipe: " + getRecipeName());
return false; return false;
} }
if (alcohol < 0) {
P.p.errorLog("Invalid alcohol '" + alcohol + "' in Recipe: " + getRecipeName());
return false;
}
return true; return true;
} }