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
+8 -2
View File
@@ -50,6 +50,12 @@ hangoverDays: 7
colorInBarrels: true colorInBarrels: true
colorInBrewer: 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] # 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 openLargeBarrelEverywhere: true
@@ -160,6 +166,8 @@ recipes:
age: 3 age: 3
color: ORANGE color: ORANGE
difficulty: 1 difficulty: 1
lore:
- +++ &8Das perlt
alcohol: 6 alcohol: 6
3: 3:
name: Ranziges Dunkelbier/Dunkelbier/Feines Dunkelbier name: Ranziges Dunkelbier/Dunkelbier/Feines Dunkelbier
@@ -172,8 +180,6 @@ recipes:
color: BLACK color: BLACK
difficulty: 2 difficulty: 2
alcohol: 7 alcohol: 7
lore:
- +++ &8Perlt wunderschön
4: 4:
name: Scheußlicher Met/Met/&6Goldener Met name: Scheußlicher Met/Met/&6Goldener Met
ingredients: ingredients:
+7 -1
View File
@@ -50,6 +50,12 @@ hangoverDays: 7
colorInBarrels: true colorInBarrels: true
colorInBrewer: 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] # 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 openLargeBarrelEverywhere: true
@@ -152,7 +158,7 @@ recipes:
color: ORANGE color: ORANGE
difficulty: 1 difficulty: 1
lore: lore:
- +++ &8Perlt wunderschön - +++ &8Das perlt
alcohol: 6 alcohol: 6
3: 3:
name: Ranziges Dunkelbier/Dunkelbier/Feines Dunkelbier name: Ranziges Dunkelbier/Dunkelbier/Feines Dunkelbier
+6
View File
@@ -50,6 +50,12 @@ hangoverDays: 7
colorInBarrels: true colorInBarrels: true
colorInBrewer: 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] # 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 openLargeBarrelEverywhere: true
+1
View File
@@ -14,6 +14,7 @@ Brew_Woodtype: Holzart
Brew_Years: Jahre Brew_Years: Jahre
Brew_fermented: gegärt Brew_fermented: gegärt
Brew_minute: minute Brew_minute: minute
Brew_Alc: Alc &v1ml
# CMD # CMD
CMD_Copy_Error: '&6&v1 &cTränke haben nicht mehr in das Inventar gepasst' CMD_Copy_Error: '&6&v1 &cTränke haben nicht mehr in das Inventar gepasst'
+1
View File
@@ -14,6 +14,7 @@ Brew_Woodtype: Woodtype
Brew_Years: Years Brew_Years: Years
Brew_fermented: fermented Brew_fermented: fermented
Brew_minute: minute Brew_minute: minute
Brew_Alc: Alc &v1ml
# CMD # CMD
CMD_CopyNotPersistent: '&eThese copies of this Brew will not be persistent or static!' CMD_CopyNotPersistent: '&eThese copies of this Brew will not be persistent or static!'
+18
View File
@@ -1,5 +1,6 @@
package com.dre.brewery; package com.dre.brewery;
import com.dre.brewery.lore.BrewLore;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@@ -8,6 +9,7 @@ import org.bukkit.block.BrewingStand;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.BrewerInventory; import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap; import java.util.HashMap;
@@ -137,6 +139,21 @@ public class BDistiller {
return 800; 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 { public class DistillRunnable extends BukkitRunnable {
@Override @Override
@@ -166,6 +183,7 @@ public class BDistiller {
// No custom potion, cancel and ignore // No custom potion, cancel and ignore
this.cancel(); this.cancel();
trackedDistillers.remove(standBlock); trackedDistillers.remove(standBlock);
showAlc(stand.getInventory());
P.p.debugLog("nothing to distill"); P.p.debugLog("nothing to distill");
return; return;
default: default:
+3
View File
@@ -93,7 +93,10 @@ public class BIngredients {
P.p.debugLog("cooked potion has Quality: " + quality); P.p.debugLog("cooked potion has Quality: " + quality);
brew = new Brew(quality, cookRecipe, this); brew = new Brew(quality, cookRecipe, this);
BrewLore lore = new BrewLore(brew, potionMeta); BrewLore lore = new BrewLore(brew, potionMeta);
lore.updateQualityStars(false);
lore.updateCustomLore(); lore.updateCustomLore();
lore.updateAlc(false);
lore.addOrReplaceEffects(brew.getEffects(), brew.getQuality()); lore.addOrReplaceEffects(brew.getEffects(), brew.getQuality());
cookedName = cookRecipe.getName(quality); cookedName = cookRecipe.getName(quality);
+7 -2
View File
@@ -287,6 +287,7 @@ public class Brew {
}*/ }*/
// calculate alcohol from recipe // calculate alcohol from recipe
@Contract(pure = true)
public int calcAlcohol() { public int calcAlcohol() {
if (quality == 0) { if (quality == 0) {
// Give bad potions some alc // Give bad potions some alc
@@ -329,6 +330,7 @@ public class Brew {
} }
// calculating quality // calculating quality
@Contract(pure = true)
public int calcQuality() { public int calcQuality() {
// calculate quality from all of the factors // calculate quality from all of the factors
float quality = ingredients.getIngredientQuality(currentRecipe) + ingredients.getCookingQuality(currentRecipe, distillRuns > 0); float quality = ingredients.getIngredientQuality(currentRecipe) + ingredients.getCookingQuality(currentRecipe, distillRuns > 0);
@@ -375,6 +377,7 @@ public class Brew {
lore.updateAgeLore(false); lore.updateAgeLore(false);
} }
lore.updateQualityStars(false); lore.updateQualityStars(false);
lore.updateAlc(false);
lore.write(); lore.write();
item.setItemMeta(meta); item.setItemMeta(meta);
} }
@@ -491,7 +494,6 @@ public class Brew {
currentRecipe = recipe; currentRecipe = recipe;
quality = calcQuality(); quality = calcQuality();
lore.updateCustomLore();
lore.addOrReplaceEffects(getEffects(), quality); lore.addOrReplaceEffects(getEffects(), quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
PotionColor.fromString(recipe.getColor()).colorBrew(potionMeta, slotItem, canDistill()); PotionColor.fromString(recipe.getColor()).colorBrew(potionMeta, slotItem, canDistill());
@@ -509,8 +511,10 @@ public class Brew {
lore.convertLore(BConfig.colorInBrewer); lore.convertLore(BConfig.colorInBrewer);
} }
lore.updateQualityStars(BConfig.colorInBrewer); lore.updateQualityStars(BConfig.colorInBrewer);
lore.updateCustomLore();
} }
lore.updateDistillLore(BConfig.colorInBrewer); lore.updateDistillLore(BConfig.colorInBrewer);
lore.updateAlc(true);
lore.write(); lore.write();
touch(); touch();
BrewModifyEvent modifyEvent = new BrewModifyEvent(this, potionMeta, BrewModifyEvent.Type.DISTILL); BrewModifyEvent modifyEvent = new BrewModifyEvent(this, potionMeta, BrewModifyEvent.Type.DISTILL);
@@ -562,7 +566,6 @@ public class Brew {
currentRecipe = recipe; currentRecipe = recipe;
quality = calcQuality(); quality = calcQuality();
lore.updateCustomLore();
lore.addOrReplaceEffects(getEffects(), quality); lore.addOrReplaceEffects(getEffects(), quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
PotionColor.fromString(recipe.getColor()).colorBrew(potionMeta, item, canDistill()); PotionColor.fromString(recipe.getColor()).colorBrew(potionMeta, item, canDistill());
@@ -588,6 +591,8 @@ public class Brew {
lore.updateWoodLore(true); lore.updateWoodLore(true);
} }
lore.updateQualityStars(BConfig.colorInBarrels); lore.updateQualityStars(BConfig.colorInBarrels);
lore.updateCustomLore();
lore.updateAlc(false);
} }
lore.write(); lore.write();
touch(); touch();
+1 -1
View File
@@ -81,7 +81,7 @@ public class MCBarrel {
for (ItemStack item : inv.getContents()) { for (ItemStack item : inv.getContents()) {
if (item != null) { if (item != null) {
Brew brew = Brew.get(item); 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 // We found a brew, so set time on this Barrel
if (inv.getHolder() instanceof org.bukkit.block.Barrel) { if (inv.getHolder() instanceof org.bukkit.block.Barrel) {
Barrel barrel = (Barrel) inv.getHolder(); Barrel barrel = (Barrel) inv.getHolder();
@@ -55,6 +55,8 @@ public class BConfig {
public static boolean colorInBarrels; // color the Lore while in Barrels public static boolean colorInBarrels; // color the Lore while in Barrels
public static boolean colorInBrewer; // color the Lore while in Brewer public static boolean colorInBrewer; // color the Lore while in Brewer
public static boolean enableEncode; 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; public static P p = P.p;
@@ -174,6 +176,8 @@ public class BConfig {
homeType = config.getString("homeType", null); homeType = config.getString("homeType", null);
colorInBarrels = config.getBoolean("colorInBarrels", false); colorInBarrels = config.getBoolean("colorInBarrels", false);
colorInBrewer = config.getBoolean("colorInBrewer", false); colorInBrewer = config.getBoolean("colorInBrewer", false);
alwaysShowQuality = config.getBoolean("alwaysShowQuality", false);
alwaysShowAlc = config.getBoolean("alwaysShowAlc", false);
enableEncode = config.getBoolean("enableEncode", false); enableEncode = config.getBoolean("enableEncode", false);
openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false); openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
MCBarrel.maxBrews = config.getInt("maxBrewsInMCBarrels", 6); MCBarrel.maxBrews = config.getInt("maxBrewsInMCBarrels", 6);
@@ -75,6 +75,7 @@ public class LanguageReader {
defaults.put("Brew_HundredsOfYears", "Hundreds of Years"); defaults.put("Brew_HundredsOfYears", "Hundreds of Years");
defaults.put("Brew_Woodtype", "Woodtype"); defaults.put("Brew_Woodtype", "Woodtype");
defaults.put("Brew_ThickBrew", "Muddy Brew"); defaults.put("Brew_ThickBrew", "Muddy Brew");
defaults.put("Brew_Alc", "Alc &v1ml");
/* Commands */ /* Commands */
defaults.put("CMD_Reload", "&aConfig was successfully reloaded"); defaults.put("CMD_Reload", "&aConfig was successfully reloaded");
@@ -5,6 +5,7 @@ import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.lore.BrewLore; import com.dre.brewery.lore.BrewLore;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -204,18 +205,32 @@ public class InventoryListener implements Listener {
PotionMeta meta = (PotionMeta) item.getItemMeta(); PotionMeta meta = (PotionMeta) item.getItemMeta();
Brew brew = Brew.get(meta); Brew brew = Brew.get(meta);
if (brew != null) { if (brew != null) {
BrewLore lore = null;
if (BrewLore.hasColorLore(meta)) { if (BrewLore.hasColorLore(meta)) {
BrewLore lore = new BrewLore(brew, meta); lore = new BrewLore(brew, meta);
lore.convertLore(false); 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(); lore.write();
item.setItemMeta(meta); 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 // 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) { public void onInventoryClickMCBarrel(InventoryClickEvent event) {
if (!P.use1_14) return; if (!P.use1_14) return;
if (event.getInventory().getType() != InventoryType.BARREL) return; if (event.getInventory().getType() != InventoryType.BARREL) return;
+28 -20
View File
@@ -1,6 +1,7 @@
package com.dre.brewery.lore; package com.dre.brewery.lore;
import com.dre.brewery.*; import com.dre.brewery.*;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.BUtil;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@@ -209,7 +210,7 @@ public class BrewLore {
if (brew.hasRecipe() && brew.getCurrentRecipe().needsToAge() && brew.getAgeTime() < 0.5) { if (brew.hasRecipe() && brew.getCurrentRecipe().needsToAge() && brew.getAgeTime() < 0.5) {
return; return;
} }
if (!brew.isUnlabeled()) { if (!brew.isUnlabeled() && brew.getQuality() > 0 && (qualityColor || BConfig.alwaysShowQuality)) {
int stars = (brew.getQuality() + 1) / 2; int stars = (brew.getQuality() + 1) / 2;
StringBuilder b = new StringBuilder(stars); StringBuilder b = new StringBuilder(stars);
for (; stars > 0; 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 * Converts to/from qualitycolored Lore
*/ */
@@ -260,6 +270,8 @@ public class BrewLore {
updateWoodLore(toQuality); updateWoodLore(toQuality);
} }
} }
updateAlc(false);
} }
/** /**
@@ -332,10 +344,9 @@ public class BrewLore {
* Removes all Brew Lore lines * Removes all Brew Lore lines
*/ */
public void removeAll() { public void removeAll() {
for (Type t : Type.values()) { for (int i = lore.size() - 1; i >= 0; i--) {
int index = t.findInLore(lore); if (Type.get(lore.get(i)) != null) {
if (index > -1) { lore.remove(i);
lore.remove(index);
} }
} }
} }
@@ -442,26 +453,24 @@ public class BrewLore {
} }
public enum Type { public enum Type {
STARS("§s", 0), STARS("§s"),
CUSTOM("§t", 1), CUSTOM("§t"),
SPACE("§u", 2), SPACE("§u"),
INGR("§v", 3), INGR("§v"),
COOK("§w", 4), COOK("§w"),
DISTILL("§x", 5), DISTILL("§x"),
AGE("§y", 6), AGE("§y"),
WOOD("§z", 7); WOOD("§z"),
ALC("§k");
public final String id; public final String id;
public final int ordering;
/** /**
* @param id Identifier as Prefix of the Loreline * @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.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 * @return true if this type should be after the other type in lore
*/ */
public boolean isAfter(Type other) { public boolean isAfter(Type other) {
return other.ordering <= ordering; return other.ordinal() <= ordinal();
} }
/** /**
@@ -490,8 +499,7 @@ public class BrewLore {
@Nullable @Nullable
public static Type get(String loreLine) { public static Type get(String loreLine) {
if (loreLine.length() >= 2) { if (loreLine.length() >= 2) {
loreLine = loreLine.substring(0, 2); return getById(loreLine.substring(0, 2));
return getById(loreLine);
} else { } else {
return null; return null;
} }