mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 05:28:59 +00:00
Make Lore quality-colored while in Barrel/Brewer
This commit is contained in:
@@ -39,6 +39,10 @@ drainItems:
|
|||||||
- BREAD/4
|
- BREAD/4
|
||||||
- MILK_BUCKET/2
|
- MILK_BUCKET/2
|
||||||
|
|
||||||
|
# Färben der Iteminformationen je nach Qualität während sie sich 1. im Fass und/oder 2. im Braustand befinden
|
||||||
|
colorInBarrels: true
|
||||||
|
colorInBrewer: true
|
||||||
|
|
||||||
# Autosave Intervall in Minuten
|
# Autosave Intervall in Minuten
|
||||||
autosave: 3
|
autosave: 3
|
||||||
|
|
||||||
|
|||||||
@@ -117,19 +117,8 @@ public class BIngredients {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void qualityLore(PotionMeta meta, BRecipe recipe, boolean distilled) {
|
public int getCookedTime() {
|
||||||
// Ingredients
|
return cookedTime;
|
||||||
String prefix = Brew.getQualityColor(getIngredientQuality(recipe));
|
|
||||||
String lore = "Zutaten";
|
|
||||||
Brew.addOrReplaceLore(meta, prefix, lore);
|
|
||||||
|
|
||||||
// Cookingtime
|
|
||||||
prefix = Brew.getQualityColor(getCookingQuality(recipe, distilled)) + cookedTime + " minute";
|
|
||||||
if (cookedTime > 1) {
|
|
||||||
prefix = prefix + "n";
|
|
||||||
}
|
|
||||||
lore = " gegärt";
|
|
||||||
Brew.addOrReplaceLore(meta, prefix, lore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// best recipe for current state of potion, STILL not always returns the
|
// best recipe for current state of potion, STILL not always returns the
|
||||||
|
|||||||
@@ -21,8 +21,16 @@ public class BPlayer {
|
|||||||
public static Map<String, BPlayer> players = new HashMap<String, BPlayer>();// Players name and BPlayer
|
public static Map<String, BPlayer> players = new HashMap<String, BPlayer>();// Players name and BPlayer
|
||||||
public static Map<Material, Integer> drainItems = new HashMap<Material, Integer>();// DrainItem Material and Strength
|
public static Map<Material, Integer> drainItems = new HashMap<Material, Integer>();// DrainItem Material and Strength
|
||||||
private static Map<Player, Integer> pTasks = new HashMap<Player, Integer>();// Player and count
|
private static Map<Player, Integer> pTasks = new HashMap<Player, Integer>();// Player and count
|
||||||
|
|
||||||
|
// Settings
|
||||||
private static int taskId;
|
private static int taskId;
|
||||||
public static int pukeItemId;
|
public static int pukeItemId;
|
||||||
|
public static boolean overdrinkKick;
|
||||||
|
public static boolean enableHome;
|
||||||
|
public static boolean enableLoginDisallow;
|
||||||
|
public static boolean enablePuke;
|
||||||
|
public static String wakeString;
|
||||||
|
public static String homeType;
|
||||||
|
|
||||||
private int quality = 0;// = quality of drunkeness * drunkeness
|
private int quality = 0;// = quality of drunkeness * drunkeness
|
||||||
private int drunkeness = 0;// = amount of drunkeness
|
private int drunkeness = 0;// = amount of drunkeness
|
||||||
@@ -105,7 +113,7 @@ public class BPlayer {
|
|||||||
|
|
||||||
// Player has drunken too much
|
// Player has drunken too much
|
||||||
public void drinkCap(Player player) {
|
public void drinkCap(Player player) {
|
||||||
if (P.p.getConfig().getBoolean("enableKickOnOverdrink", false)) {
|
if (overdrinkKick) {
|
||||||
passOut(player);
|
passOut(player);
|
||||||
} else {
|
} else {
|
||||||
quality = getQuality() * 100;
|
quality = getQuality() * 100;
|
||||||
@@ -193,7 +201,7 @@ public class BPlayer {
|
|||||||
if (drunkeness <= 70) {
|
if (drunkeness <= 70) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (P.p.getConfig().getBoolean("enableLoginDisallow", false) == false) {
|
if (!enableLoginDisallow) {
|
||||||
if (drunkeness <= 100) {
|
if (drunkeness <= 100) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -240,7 +248,7 @@ public class BPlayer {
|
|||||||
public void login(final Player player) {
|
public void login(final Player player) {
|
||||||
if (drunkeness < 10) {
|
if (drunkeness < 10) {
|
||||||
if (offlineDrunk > 60) {
|
if (offlineDrunk > 60) {
|
||||||
if (P.p.getConfig().getBoolean("enableHome", false)) {
|
if (enableHome) {
|
||||||
goHome(player);
|
goHome(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,7 +260,7 @@ public class BPlayer {
|
|||||||
Location randomLoc = Wakeup.getRandom(player.getLocation());
|
Location randomLoc = Wakeup.getRandom(player.getLocation());
|
||||||
if (randomLoc != null) {
|
if (randomLoc != null) {
|
||||||
player.teleport(randomLoc);
|
player.teleport(randomLoc);
|
||||||
P.p.msg(player, P.p.getConfig().getString("wakeString", "Ohh nein! Ich kann mich nicht erinnern, wie ich hier hergekommen bin..."));
|
P.p.msg(player, wakeString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +269,6 @@ public class BPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void goHome(final Player player) {
|
public void goHome(final Player player) {
|
||||||
String homeType = P.p.getConfig().getString("homeType", null);
|
|
||||||
if (homeType != null) {
|
if (homeType != null) {
|
||||||
Location home = null;
|
Location home = null;
|
||||||
if (homeType.equalsIgnoreCase("bed")) {
|
if (homeType.equalsIgnoreCase("bed")) {
|
||||||
@@ -310,7 +317,7 @@ public class BPlayer {
|
|||||||
|
|
||||||
// make a Player puke "count" items
|
// make a Player puke "count" items
|
||||||
public static void addPuke(Player player, int count) {
|
public static void addPuke(Player player, int count) {
|
||||||
if (!P.p.getConfig().getBoolean("enablePuke", false)) {
|
if (!enablePuke) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +411,7 @@ public class BPlayer {
|
|||||||
|
|
||||||
bplayer.drunkEffects(player);
|
bplayer.drunkEffects(player);
|
||||||
|
|
||||||
if (P.p.getConfig().getBoolean("enablePuke", false)) {
|
if (enablePuke) {
|
||||||
bplayer.drunkPuke(player);
|
bplayer.drunkPuke(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+125
-27
@@ -16,10 +16,14 @@ import com.dre.brewery.BIngredients;
|
|||||||
|
|
||||||
public class Brew {
|
public class Brew {
|
||||||
|
|
||||||
public static Map<Integer, Brew> potions = new HashMap<Integer, Brew>();
|
|
||||||
|
|
||||||
// represents the liquid in the brewed Potions
|
// represents the liquid in the brewed Potions
|
||||||
|
|
||||||
|
public static Map<Integer, Brew> potions = new HashMap<Integer, Brew>();
|
||||||
|
public static Boolean colorInBarrels; // color the Lore while in Barrels
|
||||||
|
public static Boolean colorInBrewer; // color the Lore while in Brewer
|
||||||
|
|
||||||
|
//public static Map<ItemStack, List<String>> oldLore = new HashMap<ItemStack, List<String>>();
|
||||||
|
|
||||||
private BIngredients ingredients;
|
private BIngredients ingredients;
|
||||||
private int quality;
|
private int quality;
|
||||||
private int distillRuns;
|
private int distillRuns;
|
||||||
@@ -68,11 +72,16 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns a Brew by ItemStack
|
// returns a Brew by ItemStack
|
||||||
/*
|
/* public static Brew get(ItemStack item) {
|
||||||
* public static Brew get(ItemStack item){ if(item.getTypeId() == 373){
|
* if (item.getTypeId() == 373) {
|
||||||
* PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); return
|
* if (item.hasItemMeta()) {
|
||||||
* get(potionMeta); } return null; }
|
* PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||||
*/
|
* return get(potionMeta);
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* return null;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
// returns UID of custom Potion item
|
// returns UID of custom Potion item
|
||||||
public static int getUID(ItemStack item) {
|
public static int getUID(ItemStack item) {
|
||||||
@@ -187,12 +196,15 @@ public class Brew {
|
|||||||
brew.currentRecipe = recipe;
|
brew.currentRecipe = recipe;
|
||||||
|
|
||||||
// Distill Lore
|
// Distill Lore
|
||||||
String lore = "destilliert";
|
if (colorInBrewer != hasColorLore(potionMeta)) {
|
||||||
String prefix = P.p.color("&7");
|
brew.convertLore(potionMeta, colorInBrewer);
|
||||||
if (brew.distillRuns > 1) {
|
} else {
|
||||||
prefix = prefix + brew.distillRuns + "-fach ";
|
String prefix = P.p.color("&7");
|
||||||
|
if (colorInBrewer) {
|
||||||
|
prefix = getQualityColor(brew.ingredients.getDistillQuality(recipe, brew.distillRuns));
|
||||||
|
}
|
||||||
|
brew.updateDistillLore(prefix, potionMeta);
|
||||||
}
|
}
|
||||||
addOrReplaceLore(potionMeta, prefix, lore);
|
|
||||||
addOrReplaceEffects(potionMeta, brew.getEffects());
|
addOrReplaceEffects(potionMeta, brew.getEffects());
|
||||||
|
|
||||||
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality + ", alc: " + brew.calcAlcohol());
|
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality + ", alc: " + brew.calcAlcohol());
|
||||||
@@ -228,25 +240,25 @@ public class Brew {
|
|||||||
brew.currentRecipe = recipe;
|
brew.currentRecipe = recipe;
|
||||||
P.p.log("Final " + recipe.getName(5) + " has Quality: " + brew.quality);
|
P.p.log("Final " + recipe.getName(5) + " has Quality: " + brew.quality);
|
||||||
|
|
||||||
if (brew.ageTime >= 1) {
|
|
||||||
String lore = " Fassgereift";
|
|
||||||
String prefix = P.p.color("&7");
|
|
||||||
if (brew.ageTime == 1) {
|
|
||||||
prefix = prefix + "Ein Jahr";
|
|
||||||
} else if (brew.ageTime < 201) {
|
|
||||||
prefix = prefix + (int) Math.floor(brew.ageTime) + " Jahre";
|
|
||||||
} else {
|
|
||||||
prefix = prefix + "Hunderte Jahre";
|
|
||||||
}
|
|
||||||
addOrReplaceLore(potionMeta, prefix, lore);
|
|
||||||
addOrReplaceEffects(potionMeta, brew.getEffects());
|
|
||||||
}
|
|
||||||
|
|
||||||
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(brew.quality)));
|
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(brew.quality)));
|
||||||
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
|
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
|
||||||
item.setItemMeta(potionMeta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lore
|
||||||
|
if (colorInBarrels != hasColorLore(potionMeta)) {
|
||||||
|
brew.convertLore(potionMeta, colorInBarrels);
|
||||||
|
} else {
|
||||||
|
if (brew.ageTime >= 1) {
|
||||||
|
String prefix = P.p.color("&7");
|
||||||
|
if (colorInBarrels) {
|
||||||
|
prefix = getQualityColor(brew.ingredients.getAgeQuality(brew.currentRecipe, brew.ageTime));
|
||||||
|
}
|
||||||
|
brew.updateAgeLore(prefix, potionMeta);
|
||||||
|
addOrReplaceEffects(potionMeta, brew.getEffects());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.setItemMeta(potionMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,6 +276,83 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lore -----------
|
||||||
|
|
||||||
|
// Converts to/from qualitycolored Lore
|
||||||
|
public void convertLore(PotionMeta meta, Boolean toQuality) {
|
||||||
|
if (currentRecipe == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (meta == null) {
|
||||||
|
P.p.log("has no meta");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta.setLore(null);
|
||||||
|
|
||||||
|
// Ingredients
|
||||||
|
int quality;
|
||||||
|
String prefix = P.p.color("&7");
|
||||||
|
String lore;
|
||||||
|
if (toQuality) {
|
||||||
|
quality = ingredients.getIngredientQuality(currentRecipe);
|
||||||
|
prefix = getQualityColor(quality);
|
||||||
|
lore = "Zutaten";
|
||||||
|
addOrReplaceLore(meta, prefix, lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cooking
|
||||||
|
if (toQuality) {
|
||||||
|
if (distillRuns > 0 == currentRecipe.needsDistilling()) {
|
||||||
|
quality = ingredients.getCookingQuality(currentRecipe, distillRuns > 0);
|
||||||
|
prefix = getQualityColor(quality) + ingredients.getCookedTime() + " minute";
|
||||||
|
if (ingredients.getCookedTime() > 1) {
|
||||||
|
prefix = prefix + "n";
|
||||||
|
}
|
||||||
|
lore = " gegärt";
|
||||||
|
addOrReplaceLore(meta, prefix, lore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Distilling
|
||||||
|
if (distillRuns > 0) {
|
||||||
|
if (toQuality) {
|
||||||
|
quality = ingredients.getDistillQuality(currentRecipe, distillRuns);
|
||||||
|
prefix = getQualityColor(quality);
|
||||||
|
}
|
||||||
|
updateDistillLore(prefix, meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ageing
|
||||||
|
if (ageTime >= 1) {
|
||||||
|
if (toQuality) {
|
||||||
|
quality = ingredients.getAgeQuality(currentRecipe, ageTime);
|
||||||
|
prefix = getQualityColor(quality);
|
||||||
|
}
|
||||||
|
updateAgeLore(prefix, meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets the DistillLore. Prefix is the color to be used
|
||||||
|
public void updateDistillLore(String prefix, PotionMeta meta) {
|
||||||
|
if (distillRuns > 1) {
|
||||||
|
prefix = prefix + distillRuns + "-fach ";
|
||||||
|
}
|
||||||
|
addOrReplaceLore(meta, prefix, "destilliert");
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets the AgeLore. Prefix is the color to be used
|
||||||
|
public void updateAgeLore(String prefix, PotionMeta meta) {
|
||||||
|
if (ageTime >= 1 && ageTime < 2) {
|
||||||
|
prefix = prefix + "Ein Jahr";
|
||||||
|
} else if (ageTime < 201) {
|
||||||
|
prefix = prefix + (int) Math.floor(ageTime) + " Jahre";
|
||||||
|
} else {
|
||||||
|
prefix = prefix + "Hunderte Jahre";
|
||||||
|
}
|
||||||
|
addOrReplaceLore(meta, prefix, " Fassgereift");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adds or replaces a line of Lore. Searches for Substring lore and replaces it
|
||||||
public static void addOrReplaceLore(PotionMeta meta, String prefix, String lore) {
|
public static void addOrReplaceLore(PotionMeta meta, String prefix, String lore) {
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
List<String> existingLore = meta.getLore();
|
List<String> existingLore = meta.getLore();
|
||||||
@@ -282,6 +371,7 @@ public class Brew {
|
|||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the Index of a String from the list that contains this substring
|
||||||
public static int indexOfSubstring(List<String> list, String substring) {
|
public static int indexOfSubstring(List<String> list, String substring) {
|
||||||
for (int index = 0; index < list.size(); index++) {
|
for (int index = 0; index < list.size(); index++) {
|
||||||
String string = list.get(index);
|
String string = list.get(index);
|
||||||
@@ -292,6 +382,14 @@ public class Brew {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// True if the PotionMeta has colored Lore
|
||||||
|
public static Boolean hasColorLore(PotionMeta meta) {
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
return !meta.getLore().get(1).startsWith(P.p.color("&7"));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// gets the Color that represents a quality in Lore
|
// gets the Color that represents a quality in Lore
|
||||||
public static String getQualityColor(int quality) {
|
public static String getQualityColor(int quality) {
|
||||||
String color;
|
String color;
|
||||||
|
|||||||
@@ -137,6 +137,14 @@ public class P extends JavaPlugin {
|
|||||||
// various Settings
|
// various Settings
|
||||||
autosave = config.getInt("autosave", 3);
|
autosave = config.getInt("autosave", 3);
|
||||||
BPlayer.pukeItemId = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND")).getId();
|
BPlayer.pukeItemId = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND")).getId();
|
||||||
|
BPlayer.overdrinkKick = config.getBoolean("enableKickOnOverdrink", false);
|
||||||
|
BPlayer.enableHome = config.getBoolean("enableHome", false);
|
||||||
|
BPlayer.enableLoginDisallow = config.getBoolean("enableLoginDisallow", false);
|
||||||
|
BPlayer.enablePuke = config.getBoolean("enablePuke", false);
|
||||||
|
BPlayer.wakeString = config.getString("wakeString", "Ohh nein! Ich kann mich nicht erinnern, wie ich hier hergekommen bin...");
|
||||||
|
BPlayer.homeType = config.getString("homeType", null);
|
||||||
|
Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
|
||||||
|
Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
|
||||||
|
|
||||||
// loading recipes
|
// loading recipes
|
||||||
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ 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;
|
||||||
import org.bukkit.event.inventory.BrewEvent;
|
import org.bukkit.event.inventory.BrewEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.BrewerInventory;
|
import org.bukkit.inventory.BrewerInventory;
|
||||||
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
@@ -46,4 +49,31 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert to non colored Lore when taking out of Barrel/Brewer
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
if (event.getInventory().getType() == InventoryType.BREWING) {
|
||||||
|
if (event.getSlot() > 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (event.getInventory().getType() != InventoryType.CHEST) {
|
||||||
|
if (!event.getInventory().getTitle().equals("Fass")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack item = event.getCurrentItem();
|
||||||
|
if (item != null) {
|
||||||
|
if (item.getTypeId() == 373) {
|
||||||
|
if (item.hasItemMeta()) {
|
||||||
|
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||||
|
Brew brew = Brew.get(meta);
|
||||||
|
if (brew != null) {
|
||||||
|
brew.convertLore(meta, false);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user