Show the Alc content in the distiller/always

This commit is contained in:
Sn0wStorm 2019-10-22 10:32:48 +02:00
parent 7a6e361a8c
commit 92977d2c8e
13 changed files with 102 additions and 28 deletions

View File

@ -50,6 +50,12 @@ hangoverDays: 7
colorInBarrels: true
colorInBrewer: true
# Ob in den Iteminformationen immer 1-5 Sterne für die Qualität angezeigt werden sollen, oder nur beim brauen [true]
alwaysShowQuality: true
# Ob in den Iteminformationen immer der Alkoholgehalt angezeigt weden soll, oder nur im Braustand [false]
alwaysShowAlc: false
# Ob große Fässer an jedem Block geöffnet werden können, nicht nur an Zapfhahn und Schild. Bei kleinen Fässern geht dies immer. [true]
openLargeBarrelEverywhere: true
@ -160,6 +166,8 @@ recipes:
age: 3
color: ORANGE
difficulty: 1
lore:
- +++ &8Das perlt
alcohol: 6
3:
name: Ranziges Dunkelbier/Dunkelbier/Feines Dunkelbier
@ -172,8 +180,6 @@ recipes:
color: BLACK
difficulty: 2
alcohol: 7
lore:
- +++ &8Perlt wunderschön
4:
name: Scheußlicher Met/Met/&6Goldener Met
ingredients:

View File

@ -50,6 +50,12 @@ hangoverDays: 7
colorInBarrels: true
colorInBrewer: true
# Ob in den Iteminformationen immer 1-5 Sterne für die Qualität angezeigt werden sollen, oder nur beim brauen [true]
alwaysShowQuality: true
# Ob in den Iteminformationen immer der Alkoholgehalt angezeigt weden soll, oder nur im Braustand [false]
alwaysShowAlc: false
# Ob große Fässer an jedem Block geöffnet werden können, nicht nur an Zapfhahn und Schild. Bei kleinen Fässern geht dies immer. [true]
openLargeBarrelEverywhere: true
@ -152,7 +158,7 @@ recipes:
color: ORANGE
difficulty: 1
lore:
- +++ &8Perlt wunderschön
- +++ &8Das perlt
alcohol: 6
3:
name: Ranziges Dunkelbier/Dunkelbier/Feines Dunkelbier

View File

@ -50,6 +50,12 @@ hangoverDays: 7
colorInBarrels: true
colorInBrewer: true
# Always show the 1-5 stars on the item depending on the quality. If false, they will only appear when brewing [true]
alwaysShowQuality: true
# Always show the alcohol content on the item. If false, it will only show in the brewing stand [false]
alwaysShowAlc: false
# If a Large Barrel can be opened by clicking on any of its blocks, not just Spigot or Sign. This is always true for Small Barrels. [true]
openLargeBarrelEverywhere: true

View File

@ -14,6 +14,7 @@ Brew_Woodtype: Holzart
Brew_Years: Jahre
Brew_fermented: gegärt
Brew_minute: minute
Brew_Alc: Alc &v1ml
# CMD
CMD_Copy_Error: '&6&v1 &cTränke haben nicht mehr in das Inventar gepasst'

View File

@ -14,6 +14,7 @@ Brew_Woodtype: Woodtype
Brew_Years: Years
Brew_fermented: fermented
Brew_minute: minute
Brew_Alc: Alc &v1ml
# CMD
CMD_CopyNotPersistent: '&eThese copies of this Brew will not be persistent or static!'

View File

@ -1,5 +1,6 @@
package com.dre.brewery;
import com.dre.brewery.lore.BrewLore;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -8,6 +9,7 @@ import org.bukkit.block.BrewingStand;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
@ -137,6 +139,21 @@ public class BDistiller {
return 800;
}
public static void showAlc(BrewerInventory inv) {
Brew[] contents = getDistillContents(inv);
for (int slot = 0; slot < 3; slot++) {
if (contents[slot] != null) {
// Show Alc in lore
ItemStack item = inv.getItem(slot);
PotionMeta meta = (PotionMeta) item.getItemMeta();
BrewLore brewLore = new BrewLore(contents[slot], meta);
brewLore.updateAlc(true);
brewLore.write();
item.setItemMeta(meta);
}
}
}
public class DistillRunnable extends BukkitRunnable {
@Override
@ -166,6 +183,7 @@ public class BDistiller {
// No custom potion, cancel and ignore
this.cancel();
trackedDistillers.remove(standBlock);
showAlc(stand.getInventory());
P.p.debugLog("nothing to distill");
return;
default:

View File

@ -93,7 +93,10 @@ public class BIngredients {
P.p.debugLog("cooked potion has Quality: " + quality);
brew = new Brew(quality, cookRecipe, this);
BrewLore lore = new BrewLore(brew, potionMeta);
lore.updateQualityStars(false);
lore.updateCustomLore();
lore.updateAlc(false);
lore.addOrReplaceEffects(brew.getEffects(), brew.getQuality());
cookedName = cookRecipe.getName(quality);

View File

@ -287,6 +287,7 @@ public class Brew {
}*/
// calculate alcohol from recipe
@Contract(pure = true)
public int calcAlcohol() {
if (quality == 0) {
// Give bad potions some alc
@ -329,6 +330,7 @@ public class Brew {
}
// calculating quality
@Contract(pure = true)
public int calcQuality() {
// calculate quality from all of the factors
float quality = ingredients.getIngredientQuality(currentRecipe) + ingredients.getCookingQuality(currentRecipe, distillRuns > 0);
@ -375,6 +377,7 @@ public class Brew {
lore.updateAgeLore(false);
}
lore.updateQualityStars(false);
lore.updateAlc(false);
lore.write();
item.setItemMeta(meta);
}
@ -491,7 +494,6 @@ public class Brew {
currentRecipe = recipe;
quality = calcQuality();
lore.updateCustomLore();
lore.addOrReplaceEffects(getEffects(), quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
PotionColor.fromString(recipe.getColor()).colorBrew(potionMeta, slotItem, canDistill());
@ -509,8 +511,10 @@ public class Brew {
lore.convertLore(BConfig.colorInBrewer);
}
lore.updateQualityStars(BConfig.colorInBrewer);
lore.updateCustomLore();
}
lore.updateDistillLore(BConfig.colorInBrewer);
lore.updateAlc(true);
lore.write();
touch();
BrewModifyEvent modifyEvent = new BrewModifyEvent(this, potionMeta, BrewModifyEvent.Type.DISTILL);
@ -562,7 +566,6 @@ public class Brew {
currentRecipe = recipe;
quality = calcQuality();
lore.updateCustomLore();
lore.addOrReplaceEffects(getEffects(), quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
PotionColor.fromString(recipe.getColor()).colorBrew(potionMeta, item, canDistill());
@ -588,6 +591,8 @@ public class Brew {
lore.updateWoodLore(true);
}
lore.updateQualityStars(BConfig.colorInBarrels);
lore.updateCustomLore();
lore.updateAlc(false);
}
lore.write();
touch();

View File

@ -81,7 +81,7 @@ public class MCBarrel {
for (ItemStack item : inv.getContents()) {
if (item != null) {
Brew brew = Brew.get(item);
if (brew != null) {
if (brew != null) { // TODO replace this and others with isBrew
// We found a brew, so set time on this Barrel
if (inv.getHolder() instanceof org.bukkit.block.Barrel) {
Barrel barrel = (Barrel) inv.getHolder();

View File

@ -55,6 +55,8 @@ public class BConfig {
public static boolean colorInBarrels; // color the Lore while in Barrels
public static boolean colorInBrewer; // color the Lore while in Brewer
public static boolean enableEncode;
public static boolean alwaysShowQuality; // Always show quality stars
public static boolean alwaysShowAlc; // Always show alc%
public static P p = P.p;
@ -174,6 +176,8 @@ public class BConfig {
homeType = config.getString("homeType", null);
colorInBarrels = config.getBoolean("colorInBarrels", false);
colorInBrewer = config.getBoolean("colorInBrewer", false);
alwaysShowQuality = config.getBoolean("alwaysShowQuality", false);
alwaysShowAlc = config.getBoolean("alwaysShowAlc", false);
enableEncode = config.getBoolean("enableEncode", false);
openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
MCBarrel.maxBrews = config.getInt("maxBrewsInMCBarrels", 6);

View File

@ -75,6 +75,7 @@ public class LanguageReader {
defaults.put("Brew_HundredsOfYears", "Hundreds of Years");
defaults.put("Brew_Woodtype", "Woodtype");
defaults.put("Brew_ThickBrew", "Muddy Brew");
defaults.put("Brew_Alc", "Alc &v1ml");
/* Commands */
defaults.put("CMD_Reload", "&aConfig was successfully reloaded");

View File

@ -5,6 +5,7 @@ import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.lore.BrewLore;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -204,18 +205,32 @@ public class InventoryListener implements Listener {
PotionMeta meta = (PotionMeta) item.getItemMeta();
Brew brew = Brew.get(meta);
if (brew != null) {
BrewLore lore = null;
if (BrewLore.hasColorLore(meta)) {
BrewLore lore = new BrewLore(brew, meta);
lore = new BrewLore(brew, meta);
lore.convertLore(false);
} else if (!BConfig.alwaysShowAlc && event.getInventory().getType() == InventoryType.BREWING) {
lore = new BrewLore(brew, meta);
lore.updateAlc(false);
}
if (lore != null) {
lore.write();
item.setItemMeta(meta);
if (event.getWhoClicked() instanceof Player) {
switch (event.getAction()) {
case MOVE_TO_OTHER_INVENTORY:
case HOTBAR_SWAP:
// Fix a Graphical glitch of item still showing colors until clicking it
P.p.getServer().getScheduler().runTask(P.p, () -> ((Player) event.getWhoClicked()).updateInventory());
}
}
}
}
}
}
// Check if the player tries to add more than the allowed amount of brews into an mc-barrel
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInventoryClickMCBarrel(InventoryClickEvent event) {
if (!P.use1_14) return;
if (event.getInventory().getType() != InventoryType.BARREL) return;

View File

@ -1,6 +1,7 @@
package com.dre.brewery.lore;
import com.dre.brewery.*;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.utility.BUtil;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
@ -209,7 +210,7 @@ public class BrewLore {
if (brew.hasRecipe() && brew.getCurrentRecipe().needsToAge() && brew.getAgeTime() < 0.5) {
return;
}
if (!brew.isUnlabeled()) {
if (!brew.isUnlabeled() && brew.getQuality() > 0 && (qualityColor || BConfig.alwaysShowQuality)) {
int stars = (brew.getQuality() + 1) / 2;
StringBuilder b = new StringBuilder(stars);
for (; stars > 0; stars--) {
@ -227,6 +228,15 @@ public class BrewLore {
}
}
public void updateAlc(boolean inDistiller) {
if (!brew.isUnlabeled() && (inDistiller || BConfig.alwaysShowAlc)) {
int alc = brew.calcAlcohol();
addOrReplaceLore(Type.ALC, "§8", P.p.languageReader.get("Brew_Alc", alc + ""));
} else {
removeLore(Type.ALC);
}
}
/**
* Converts to/from qualitycolored Lore
*/
@ -260,6 +270,8 @@ public class BrewLore {
updateWoodLore(toQuality);
}
}
updateAlc(false);
}
/**
@ -332,10 +344,9 @@ public class BrewLore {
* Removes all Brew Lore lines
*/
public void removeAll() {
for (Type t : Type.values()) {
int index = t.findInLore(lore);
if (index > -1) {
lore.remove(index);
for (int i = lore.size() - 1; i >= 0; i--) {
if (Type.get(lore.get(i)) != null) {
lore.remove(i);
}
}
}
@ -442,26 +453,24 @@ public class BrewLore {
}
public enum Type {
STARS("§s", 0),
CUSTOM("§t", 1),
SPACE("§u", 2),
STARS("§s"),
CUSTOM("§t"),
SPACE("§u"),
INGR("§v", 3),
COOK("§w", 4),
DISTILL("§x", 5),
AGE("§y", 6),
WOOD("§z", 7);
INGR("§v"),
COOK("§w"),
DISTILL("§x"),
AGE("§y"),
WOOD("§z"),
ALC("§k");
public final String id;
public final int ordering;
/**
* @param id Identifier as Prefix of the Loreline
* @param ordering Ordering of the Brew Lore
*/
Type(String id, int ordering) {
Type(String id) {
this.id = id;
this.ordering = ordering;
}
/**
@ -481,7 +490,7 @@ public class BrewLore {
* @return true if this type should be after the other type in lore
*/
public boolean isAfter(Type other) {
return other.ordering <= ordering;
return other.ordinal() <= ordinal();
}
/**
@ -490,8 +499,7 @@ public class BrewLore {
@Nullable
public static Type get(String loreLine) {
if (loreLine.length() >= 2) {
loreLine = loreLine.substring(0, 2);
return getById(loreLine);
return getById(loreLine.substring(0, 2));
} else {
return null;
}