Added cmd Unlabel & Several Fixes

This commit is contained in:
Sn0wStorm
2013-08-30 21:19:49 +02:00
parent d1e9ad29f8
commit ea06f2d707
11 changed files with 245 additions and 151 deletions
+7 -7
View File
@@ -41,7 +41,7 @@ drainItems:
# Färben der Iteminformationen je nach Qualität während sie sich 1. im Fass und/oder 2. im Braustand befinden # Färben der Iteminformationen je nach Qualität während sie sich 1. im Fass und/oder 2. im Braustand befinden
colorInBarrels: true colorInBarrels: true
colorInBrewer: true colorInBrewer: false
# Autosave Intervall in Minuten # Autosave Intervall in Minuten
autosave: 3 autosave: 3
@@ -49,11 +49,11 @@ autosave: 3
# Rezepte für Getränke # Rezepte für Getränke
# name: Verschiedene Namen für schlecht/mittel/gut # name: Verschiedene Namen für schlecht/mittel/gut (Farbcodes möglich: z.b. &6)
# ingredients: Auflistung von material/Anzahl # ingredients: Auflistung von material/Anzahl
# cookingtime: Zeit in Echtminuten die die Zutaten kochen müssen # cookingtime: Zeit in Echtminuten die die Zutaten kochen müssen
# distillruns: Wie oft destilliert werden muss 0-10 (0=ohne Destillieren) # distillruns: Wie oft destilliert werden muss für vollen Alkoholgehalt (0=ohne Destillieren)
# wood: Holz des Fasses 0=alle Holzsorten 1=Birch 2=Oak 3=Jungle 4=Pine # wood: Holz des Fasses 0=alle Holzsorten 1=Birch 2=Oak 3=Jungle 4=Spruce
# age: Zeit in Minecraft-Tagen, die das Getränk im Fass reifen muss 0= kein reifen # age: Zeit in Minecraft-Tagen, die das Getränk im Fass reifen muss 0= kein reifen
# color: Farbe des Getränks nach destillieren/reifen. DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY # color: Farbe des Getränks nach destillieren/reifen. DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY
# difficulty: 1-10 Genauigkeit der Einhaltung der Vorgaben (1 = ungenau/einfach 10 = sehr genau/schwer) # difficulty: 1-10 Genauigkeit der Einhaltung der Vorgaben (1 = ungenau/einfach 10 = sehr genau/schwer)
@@ -97,7 +97,7 @@ recipes:
difficulty: 2 difficulty: 2
alcohol: 7 alcohol: 7
4: 4:
name: Scheußlicher Met/Met/Goldener Met name: Scheußlicher Met/Met/&6Goldener Met
ingredients: ingredients:
- SUGAR_CANE/6 - SUGAR_CANE/6
cookingtime: 3 cookingtime: 3
@@ -108,7 +108,7 @@ recipes:
difficulty: 2 difficulty: 2
alcohol: 9 alcohol: 9
5: 5:
name: Apfelmet/Süßer Apfelmet/Goldensüßer Apfelmet name: Apfelmet/Süßer Apfelmet/&6Goldensüßer Apfelmet
ingredients: ingredients:
- SUGAR_CANE/6 - SUGAR_CANE/6
- APPLE/2 - APPLE/2
@@ -122,7 +122,7 @@ recipes:
effects: effects:
- WATER_BREATHINGX/150 - WATER_BREATHINGX/150
6: 6:
name: Bitterer Rum/Würziger Rum/Goldener Rum name: Bitterer Rum/Würziger Rum/&6Goldener Rum
ingredients: ingredients:
- SUGAR_CANE/14 - SUGAR_CANE/14
cookingtime: 5 cookingtime: 5
+6
View File
@@ -64,6 +64,9 @@ Auch hier können anhand der Erklärungen und Beispiele bestehende "Wörter" ver
<tr> <tr>
<td>/br [Spieler] [Trunkenheit] [Qualität]</td><td>Setzen der Spielerwerte. Trunkenheit in %, Qualität von 1-10.</td> <td>/br [Spieler] [Trunkenheit] [Qualität]</td><td>Setzen der Spielerwerte. Trunkenheit in %, Qualität von 1-10.</td>
</tr> </tr>
<tr>
<td>/br UnLabel</td><td>Versteckt die genauen Zahlen in der Beschriftung des Trankes in der Hand unwiederbringlich</td>
</tr>
<tr> <tr>
<td>/br Copy [Anzahl]</td><td>Kopiert den Trank in der Hand. Optional kann die Anzahl angegeben werden</td> <td>/br Copy [Anzahl]</td><td>Kopiert den Trank in der Hand. Optional kann die Anzahl angegeben werden</td>
</tr> </tr>
@@ -99,6 +102,9 @@ Auch hier können anhand der Erklärungen und Beispiele bestehende "Wörter" ver
<tr> <tr>
<th>Permission</th><th>Ermöglichter Befehl</th><th>Beschreibung</th> <th>Permission</th><th>Ermöglichter Befehl</th><th>Beschreibung</th>
</tr> </tr>
<tr>
<td>brewery.cmd.unlabel</td><td>UnLabel</td><td>Teile der Trankbeschriftung verstecken</td>
</tr>
<tr> <tr>
<td>brewery.cmd.info</td><td>Info</td><td>Informationen über die eigene Trunkenheit</td> <td>brewery.cmd.info</td><td>Info</td><td>Informationen über die eigene Trunkenheit</td>
</tr> </tr>
+3 -3
View File
@@ -139,8 +139,8 @@ public class BIngredients {
// needs riping in barrel // needs riping in barrel
ageQuality = getAgeQuality(recipe, time); ageQuality = getAgeQuality(recipe, time);
woodQuality = getWoodQuality(recipe, wood); woodQuality = getWoodQuality(recipe, wood);
P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) + P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + woodQuality +
" age Quality: " + getAgeQuality(recipe, time) + " for " + recipe.getName(5)); " age Quality: " + ageQuality + " for " + recipe.getName(5));
// is this recipe better than the previous best? // is this recipe better than the previous best?
if ((((float) ingredientQuality + cookingQuality + woodQuality + ageQuality) / 4) > quality) { if ((((float) ingredientQuality + cookingQuality + woodQuality + ageQuality) / 4) > quality) {
@@ -269,7 +269,7 @@ public class BIngredients {
// type of wood doesnt matter // type of wood doesnt matter
return 10; return 10;
} }
int quality = 10 - (int) Math.round(recipe.getWoodDiff(wood) * recipe.getDifficulty()); int quality = 10 - (recipe.getWoodDiff(wood) * recipe.getDifficulty());
if (quality > 0) { if (quality > 0) {
return quality; return quality;
+41 -19
View File
@@ -73,8 +73,9 @@ public class BPlayer {
return org.bukkit.Bukkit.getPlayer(getPlayerName()); return org.bukkit.Bukkit.getPlayer(getPlayerName());
}*/ }*/
// returns the Player if online
public static Player getPlayer(String name) { public static Player getPlayer(String name) {
return org.bukkit.Bukkit.getPlayer(name); return org.bukkit.Bukkit.getPlayerExact(name);
} }
// returns true if drinking was successful // returns true if drinking was successful
@@ -93,14 +94,16 @@ public class BPlayer {
players.put(player.getName(), bPlayer); players.put(player.getName(), bPlayer);
} }
bPlayer.drunkeness += brewAlc; bPlayer.drunkeness += brewAlc;
bPlayer.quality += brew.getQuality() * brewAlc; if (brew.getQuality() > 0) {
bPlayer.quality += brew.getQuality() * brewAlc;
} else {
bPlayer.quality += brewAlc;
}
if (bPlayer.drunkeness <= 100) { if (bPlayer.drunkeness <= 100) {
addBrewEffects(brew, player); addBrewEffects(brew, player);
if (brew.getQuality() < 5) { addQualityEffects(brew.getQuality(), brewAlc, player);
addQualityEffects(brew.getQuality(), brewAlc, player);
}
} else { } else {
bPlayer.drinkCap(player); bPlayer.drinkCap(player);
@@ -196,6 +199,9 @@ public class BPlayer {
passedOut = true; passedOut = true;
} }
// #### Login ####
// can the player login or is he too drunk // can the player login or is he too drunk
public int canJoin() { public int canJoin() {
if (drunkeness <= 70) { if (drunkeness <= 70) {
@@ -290,13 +296,8 @@ public class BPlayer {
} }
} }
public void hangoverEffects(final Player player) {
int duration = offlineDrunk * 50 * getHangoverQuality();
int amplifier = getHangoverQuality() / 3;
PotionEffectType.SLOW.createEffect(duration, amplifier).apply(player); // #### Puking ####
PotionEffectType.HUNGER.createEffect(duration, amplifier).apply(player);
}
// Chance that players puke on big drunkeness // Chance that players puke on big drunkeness
// runs every 6 sec, average chance is 10%, so should puke about every 60 sec // runs every 6 sec, average chance is 10%, so should puke about every 60 sec
@@ -358,6 +359,9 @@ public class BPlayer {
item.setPickupDelay(Integer.MAX_VALUE); item.setPickupDelay(Integer.MAX_VALUE);
} }
// #### Effects ####
public void drunkEffects(Player player) { public void drunkEffects(Player player) {
int duration = 10 - getQuality(); int duration = 10 - getQuality();
duration += drunkeness / 2; duration += drunkeness / 2;
@@ -372,17 +376,21 @@ public class BPlayer {
public static void addQualityEffects(int quality, int brewAlc, Player player) { public static void addQualityEffects(int quality, int brewAlc, Player player) {
int duration = 7 - quality; int duration = 7 - quality;
duration *= 250; if (quality <= 5) {
PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player); duration *= 250;
if (brewAlc > 15) {
duration = 10 - quality;
duration += brewAlc;
duration *= 40;
} else { } else {
duration = 200; duration = 200;
} }
PotionEffectType.POISON.createEffect(duration, 0).apply(player); PotionEffectType.POISON.createEffect(duration, 0).apply(player);
if (brewAlc > 10 && quality <= 5) {
duration = 10 - quality;
duration += brewAlc;
duration *= 60;
} else {
duration = 240;
}
PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player);
} }
public static void addBrewEffects(Brew brew, Player player) { public static void addBrewEffects(Brew brew, Player player) {
@@ -396,6 +404,7 @@ public class BPlayer {
type.createEffect(0, duration - 1).apply(player); type.createEffect(0, duration - 1).apply(player);
} else { } else {
int amplifier = brew.getQuality() / 3; int amplifier = brew.getQuality() / 3;
duration /= type.getDurationModifier();
type.createEffect(duration * 20, amplifier).apply(player); type.createEffect(duration * 20, amplifier).apply(player);
} }
} }
@@ -403,6 +412,17 @@ public class BPlayer {
} }
} }
public void hangoverEffects(final Player player) {
int duration = offlineDrunk * 50 * getHangoverQuality();
int amplifier = getHangoverQuality() / 3;
PotionEffectType.SLOW.createEffect(duration, amplifier).apply(player);
PotionEffectType.HUNGER.createEffect(duration, amplifier).apply(player);
}
// #### Sheduled ####
public static void drunkeness() { public static void drunkeness() {
for (String name : players.keySet()) { for (String name : players.keySet()) {
BPlayer bplayer = players.get(name); BPlayer bplayer = players.get(name);
@@ -458,7 +478,9 @@ public class BPlayer {
} }
} }
// getter
// #### getter/setter ####
public int getDrunkeness() { public int getDrunkeness() {
return drunkeness; return drunkeness;
} }
+2 -2
View File
@@ -84,7 +84,7 @@ public class BRecipe {
} }
// difference between given and recipe-wanted woodtype // difference between given and recipe-wanted woodtype
public float getWoodDiff(byte wood) { public int getWoodDiff(byte wood) {
int woodType = 0; int woodType = 0;
if (wood == 0x0) { if (wood == 0x0) {
woodType = 2; woodType = 2;
@@ -95,7 +95,7 @@ public class BRecipe {
} else if (wood == 0x3) { } else if (wood == 0x3) {
woodType = 3; woodType = 3;
} }
return Math.abs(woodType - wood); return Math.abs(woodType - this.wood);
} }
public boolean isCookingOnly() { public boolean isCookingOnly() {
+7 -6
View File
@@ -79,13 +79,13 @@ public class Barrel {
if (inventory.getViewers().isEmpty()) { if (inventory.getViewers().isEmpty()) {
// if inventory contains potions // if inventory contains potions
if (inventory.contains(373)) { if (inventory.contains(373)) {
byte wood = getWood();
long loadTime = System.nanoTime(); long loadTime = System.nanoTime();
for (ItemStack item : inventory.getContents()) { for (ItemStack item : inventory.getContents()) {
if (item != null) { if (item != null) {
if (item.getTypeId() == 373) { Brew brew = Brew.get(item);
if (item.hasItemMeta()) { if (brew != null) {
Brew.age(item, time, getWood()); brew.age(item, time, wood);
}
} }
} }
} }
@@ -129,9 +129,10 @@ public class Barrel {
ItemStack[] items = inventory.getContents(); ItemStack[] items = inventory.getContents();
for (ItemStack item : items) { for (ItemStack item : items) {
if (item != null) { if (item != null) {
if (item.getTypeId() == 373) { Brew brew = Brew.get(item);
if (brew != null) {
// Brew before throwing // Brew before throwing
Brew.age(item, time, getWood()); brew.age(item, time, getWood());
} }
// "broken" is the block that destroyed, throw them there! // "broken" is the block that destroyed, throw them there!
if (broken != null) { if (broken != null) {
+134 -102
View File
@@ -29,6 +29,7 @@ public class Brew {
private int distillRuns; private int distillRuns;
private float ageTime; private float ageTime;
private BRecipe currentRecipe; private BRecipe currentRecipe;
private boolean unlabeled;
public Brew(int uid, BIngredients ingredients) { public Brew(int uid, BIngredients ingredients) {
this.ingredients = ingredients; this.ingredients = ingredients;
@@ -44,12 +45,13 @@ public class Brew {
} }
// loading from file // loading from file
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, String recipe) { public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, String recipe, Boolean unlabeled) {
this.ingredients = ingredients; this.ingredients = ingredients;
this.quality = quality; this.quality = quality;
this.distillRuns = distillRuns; this.distillRuns = distillRuns;
this.ageTime = ageTime; this.ageTime = ageTime;
this.currentRecipe = BIngredients.getRecipeByName(recipe); this.currentRecipe = BIngredients.getRecipeByName(recipe);
this.unlabeled = unlabeled;
potions.put(uid, this); potions.put(uid, this);
} }
@@ -133,21 +135,38 @@ public class Brew {
Brew brew = new Brew(uid, quality, currentRecipe, ingredients); Brew brew = new Brew(uid, quality, currentRecipe, ingredients);
brew.distillRuns = distillRuns; brew.distillRuns = distillRuns;
brew.ageTime = ageTime; brew.ageTime = ageTime;
brew.unlabeled = unlabeled;
return brew; return brew;
} }
// calculate alcohol from recipe // calculate alcohol from recipe
public int calcAlcohol() { public int calcAlcohol() {
if (quality == 0) {
// Give bad potions some alc
if (distillRuns > 1) {
return distillRuns;
} else {
return 1;
}
}
if (currentRecipe != null) { if (currentRecipe != null) {
int alc = currentRecipe.getAlcohol(); int alc = currentRecipe.getAlcohol();
alc *= ((float) quality / 10.0);
if (currentRecipe.needsDistilling()) { if (currentRecipe.needsDistilling()) {
// distillable Potions should have full alc after 6 distills if (distillRuns == 0) {
float factor = 1.4F / (distillRuns + 1); return 0;
factor += 0.8; }
alc /= factor; // bad quality can decrease alc by up to 40%
alc *= 1 - ((float) (10 - quality) * 0.04);
// distillable Potions should have half alc after one and full alc after all needed distills
alc /= 2;
alc *= 1.0F + ((float) distillRuns / currentRecipe.getDistillRuns()) ;
} else {
// quality decides 10% - 100%
alc *= ((float) quality / 10.0);
}
if (alc > 0) {
return alc;
} }
return alc;
} }
return 0; return 0;
} }
@@ -171,24 +190,37 @@ public class Brew {
} }
public boolean canDistill() { public boolean canDistill() {
if (distillRuns >= 6) { if (currentRecipe != null) {
return currentRecipe.getDistillRuns() > distillRuns;
} else if (distillRuns >= 6) {
return false; return false;
} else {
if (currentRecipe != null) {
return currentRecipe.needsDistilling();
}
} }
return true; return true;
} }
// return special effect // return special effect
public Map<String, Integer> getEffects() { public Map<String, Integer> getEffects() {
if (currentRecipe != null) { if (currentRecipe != null && quality > 0) {
return currentRecipe.getEffects(); return currentRecipe.getEffects();
} }
return null; return null;
} }
// Set unlabeled to true to hide the numbers in Lore
public void unLabel(ItemStack item) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
if (meta.hasLore()) {
if (distillRuns > 0) {
addOrReplaceLore(meta, P.p.color("&7"), "Destilliert");
}
if (ageTime >= 1) {
addOrReplaceLore(meta, P.p.color("&7"), "Fassgereift");
}
item.setItemMeta(meta);
}
unlabeled = true;
}
// Distilling section --------------- // Distilling section ---------------
// distill all custom potions in the brewer // distill all custom potions in the brewer
@@ -196,104 +228,87 @@ public class Brew {
int slot = 0; int slot = 0;
while (slot < 3) { while (slot < 3) {
if (contents[slot]) { if (contents[slot]) {
distillSlot(inv, slot); ItemStack slotItem = inv.getItem(slot);
PotionMeta potionMeta = (PotionMeta) slotItem.getItemMeta();
Brew brew = get(potionMeta);
brew.distillSlot(slotItem, potionMeta);
} }
slot++; slot++;
} }
} }
// distill custom potion in given slot // distill custom potion in given slot
public static void distillSlot(BrewerInventory inv, int slot) { public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
ItemStack slotItem = inv.getItem(slot); distillRuns += 1;
PotionMeta potionMeta = (PotionMeta) slotItem.getItemMeta(); BRecipe recipe = ingredients.getdistillRecipe();
Brew brew = get(potionMeta);
BRecipe recipe = brew.ingredients.getdistillRecipe();
if (recipe != null) { if (recipe != null) {
// distillRuns will have an effect on the amount of alcohol, not the quality // distillRuns will have an effect on the amount of alcohol, not the quality
brew.quality = brew.calcQuality(recipe, (byte) 0, true); quality = calcQuality(recipe, (byte) 0, true);
brew.distillRuns += 1; currentRecipe = recipe;
brew.currentRecipe = recipe; P.p.log("destilled " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol());
// Distill Lore addOrReplaceEffects(potionMeta, getEffects());
if (colorInBrewer != hasColorLore(potionMeta)) { potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
brew.convertLore(potionMeta, colorInBrewer); slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
} else {
String prefix = P.p.color("&7");
if (colorInBrewer) {
prefix = getQualityColor(brew.ingredients.getDistillQuality(recipe, brew.distillRuns));
}
brew.updateDistillLore(prefix, potionMeta);
}
addOrReplaceEffects(potionMeta, brew.getEffects());
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality + ", alc: " + brew.calcAlcohol());
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(brew.quality)));
// if the potion should be further distillable
if (recipe.getDistillRuns() > 1 && brew.distillRuns <= 5) {
slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(true));
} else {
slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
}
} else { } else {
quality = 0;
potionMeta.setDisplayName(P.p.color("&f" + "Undefinierbares Destillat")); potionMeta.setDisplayName(P.p.color("&f" + "Undefinierbares Destillat"));
slotItem.setDurability(PotionColor.GREY.getColorId(brew.distillRuns <= 5)); slotItem.setDurability(PotionColor.GREY.getColorId(canDistill()));
} }
// Distill Lore
if (currentRecipe != null) {
if (colorInBrewer != hasColorLore(potionMeta)) {
convertLore(potionMeta, colorInBrewer);
}
}
String prefix = P.p.color("&7");
if (colorInBrewer && currentRecipe != null) {
prefix = getQualityColor(ingredients.getDistillQuality(recipe, distillRuns));
}
updateDistillLore(prefix, potionMeta);
slotItem.setItemMeta(potionMeta); slotItem.setItemMeta(potionMeta);
} }
// Ageing Section ------------------ // Ageing Section ------------------
public static void age(ItemStack item, float time, byte wood) { public void age(ItemStack item, float time, byte wood) {
PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
Brew brew = get(potionMeta); ageTime += time;
if (brew != null) {
brew.ageTime += time;
// if younger than half a day, it shouldnt get aged form
if (brew.ageTime > 0.5) {
BRecipe recipe = brew.ingredients.getAgeRecipe(wood, brew.ageTime, brew.distillRuns > 0);
if (recipe != null) {
brew.quality = brew.calcQuality(recipe, wood, brew.distillRuns > 0);
brew.currentRecipe = recipe;
P.p.log("Final " + recipe.getName(5) + " has Quality: " + brew.quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(brew.quality))); // if younger than half a day, it shouldnt get aged form
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false)); if (ageTime > 0.5) {
} BRecipe recipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0);
} if (recipe != null) {
currentRecipe = recipe;
quality = calcQuality(recipe, wood, distillRuns > 0);
P.p.log("Final " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol());
// Lore addOrReplaceEffects(potionMeta, getEffects());
if (colorInBarrels != hasColorLore(potionMeta)) { potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
brew.convertLore(potionMeta, colorInBarrels); item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
} else { } else {
if (brew.ageTime >= 1) { quality = 0;
String prefix = P.p.color("&7"); potionMeta.setDisplayName(P.p.color("&f" + "Verdorbenes Getränk"));
if (colorInBarrels) { item.setDurability(PotionColor.GREY.getColorId(canDistill()));
prefix = getQualityColor(brew.ingredients.getAgeQuality(brew.currentRecipe, brew.ageTime));
}
brew.updateAgeLore(prefix, potionMeta);
addOrReplaceEffects(potionMeta, brew.getEffects());
}
} }
item.setItemMeta(potionMeta);
} }
}
public static void addOrReplaceEffects(PotionMeta meta, Map<String, Integer> effects) { // Lore
if (effects != null) { if (currentRecipe != null) {
for (Map.Entry<String, Integer> entry : effects.entrySet()) { if (colorInBarrels != hasColorLore(potionMeta)) {
if (!entry.getKey().endsWith("X")) { convertLore(potionMeta, colorInBarrels);
PotionEffectType type = PotionEffectType.getByName(entry.getKey());
if (type != null) {
meta.addCustomEffect(type.createEffect(0, 0), true);
}
}
} }
} }
if (ageTime >= 1) {
String prefix = P.p.color("&7");
if (colorInBarrels && currentRecipe != null) {
prefix = getQualityColor(ingredients.getAgeQuality(currentRecipe, ageTime));
}
updateAgeLore(prefix, potionMeta);
}
item.setItemMeta(potionMeta);
} }
// Lore ----------- // Lore -----------
@@ -303,17 +318,13 @@ public class Brew {
if (currentRecipe == null) { if (currentRecipe == null) {
return; return;
} }
if (meta == null) {
P.p.log("has no meta");
return;
}
meta.setLore(null); meta.setLore(null);
// Ingredients
int quality; int quality;
String prefix = P.p.color("&7"); String prefix = P.p.color("&7");
String lore; String lore;
if (toQuality) {
// Ingredients
if (toQuality && !unlabeled) {
quality = ingredients.getIngredientQuality(currentRecipe); quality = ingredients.getIngredientQuality(currentRecipe);
prefix = getQualityColor(quality); prefix = getQualityColor(quality);
lore = "Zutaten"; lore = "Zutaten";
@@ -321,7 +332,7 @@ public class Brew {
} }
// Cooking // Cooking
if (toQuality) { if (toQuality && !unlabeled) {
if (distillRuns > 0 == currentRecipe.needsDistilling()) { if (distillRuns > 0 == currentRecipe.needsDistilling()) {
quality = ingredients.getCookingQuality(currentRecipe, distillRuns > 0); quality = ingredients.getCookingQuality(currentRecipe, distillRuns > 0);
prefix = getQualityColor(quality) + ingredients.getCookedTime() + " minute"; prefix = getQualityColor(quality) + ingredients.getCookedTime() + " minute";
@@ -354,22 +365,26 @@ public class Brew {
// sets the DistillLore. Prefix is the color to be used // sets the DistillLore. Prefix is the color to be used
public void updateDistillLore(String prefix, PotionMeta meta) { public void updateDistillLore(String prefix, PotionMeta meta) {
if (distillRuns > 1) { if (!unlabeled) {
prefix = prefix + distillRuns + "-fach "; if (distillRuns > 1) {
prefix = prefix + distillRuns + "-fach ";
}
} }
addOrReplaceLore(meta, prefix, "destilliert"); addOrReplaceLore(meta, prefix, "Destilliert");
} }
// sets the AgeLore. Prefix is the color to be used // sets the AgeLore. Prefix is the color to be used
public void updateAgeLore(String prefix, PotionMeta meta) { public void updateAgeLore(String prefix, PotionMeta meta) {
if (ageTime >= 1 && ageTime < 2) { if (!unlabeled) {
prefix = prefix + "Ein Jahr"; if (ageTime >= 1 && ageTime < 2) {
} else if (ageTime < 201) { prefix = prefix + "Ein Jahr ";
prefix = prefix + (int) Math.floor(ageTime) + " Jahre"; } else if (ageTime < 201) {
} else { prefix = prefix + (int) Math.floor(ageTime) + " Jahre ";
prefix = prefix + "Hunderte Jahre"; } else {
prefix = prefix + "Hunderte Jahre ";
}
} }
addOrReplaceLore(meta, prefix, " Fassgereift"); addOrReplaceLore(meta, prefix, "Fassgereift");
} }
// Adds or replaces a line of Lore. Searches for Substring lore and replaces it // Adds or replaces a line of Lore. Searches for Substring lore and replaces it
@@ -391,6 +406,20 @@ public class Brew {
meta.setLore(newLore); meta.setLore(newLore);
} }
// Adds the Effect names to the Items description
public static void addOrReplaceEffects(PotionMeta meta, Map<String, Integer> effects) {
if (effects != null) {
for (Map.Entry<String, Integer> entry : effects.entrySet()) {
if (!entry.getKey().endsWith("X")) {
PotionEffectType type = PotionEffectType.getByName(entry.getKey());
if (type != null) {
meta.addCustomEffect(type.createEffect(0, 0), true);
}
}
}
}
}
// Returns the Index of a String from the list that contains this substring // 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++) {
@@ -445,6 +474,9 @@ public class Brew {
if (brew.currentRecipe != null) { if (brew.currentRecipe != null) {
idConfig.set("recipe", brew.currentRecipe.getName(5)); idConfig.set("recipe", brew.currentRecipe.getName(5));
} }
if (brew.unlabeled) {
idConfig.set("unlabeled", true);
}
// save the ingredients // save the ingredients
brew.ingredients.save(idConfig.createSection("ingredients")); brew.ingredients.save(idConfig.createSection("ingredients"));
} }
+2 -1
View File
@@ -200,8 +200,9 @@ public class P extends JavaPlugin {
int distillRuns = section.getInt(uid + ".distillRuns", 0); int distillRuns = section.getInt(uid + ".distillRuns", 0);
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0); float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
String recipe = section.getString(uid + ".recipe", null); String recipe = section.getString(uid + ".recipe", null);
Boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, recipe); new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, recipe, unlabeled);
} }
} }
@@ -7,7 +7,6 @@ import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import com.dre.brewery.BCauldron; import com.dre.brewery.BCauldron;
import com.dre.brewery.Barrel; import com.dre.brewery.Barrel;
@@ -31,12 +30,9 @@ public class BlockListener implements Listener {
Block block = event.getBlock(); Block block = event.getBlock();
// remove cauldron // remove cauldron
if (block.getType() == Material.CAULDRON) { if (block.getType() == Material.CAULDRON) {
if (block.getRelative(BlockFace.DOWN).getType() == Material.FIRE || block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA if (block.getData() != 0) {
|| block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) { // will only remove when existing
if (block.getData() != 0) { BCauldron.remove(block);
// will only remove when existing
BCauldron.remove(block);
}
} }
// remove barrel and throw potions on the ground // remove barrel and throw potions on the ground
} else if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) { } else if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) {
@@ -86,6 +86,14 @@ public class CommandListener implements CommandExecutor {
p.msg(sender, "&cDu hast keine Rechte dies zu tun!"); p.msg(sender, "&cDu hast keine Rechte dies zu tun!");
} }
} else if (cmd.equalsIgnoreCase("unlabel")) {
if (p.permission.has(sender, "brewery.cmd.unlabel")) {
cmdUnlabel(sender);
} else {
p.msg(sender, "&cDu hast keine Rechte dies zu tun!");
}
} else { } else {
if (p.getServer().getPlayerExact(cmd) != null || BPlayer.players.containsKey(cmd)) { if (p.getServer().getPlayerExact(cmd) != null || BPlayer.players.containsKey(cmd)) {
@@ -143,6 +151,10 @@ public class CommandListener implements CommandExecutor {
cmds.add ("&6/br Info&9 Zeigt deine aktuelle Trunkenheit und Qualität an"); cmds.add ("&6/br Info&9 Zeigt deine aktuelle Trunkenheit und Qualität an");
} }
if (p.permission.has(sender, "brewery.cmd.unlabel")) {
cmds.add ("&6/br UnLabel &9Entfernt die genaue Beschriftung des Trankes");
}
if (p.permission.has(sender, "brewery.cmd.copy")) { if (p.permission.has(sender, "brewery.cmd.copy")) {
cmds.add ("&6/br Copy <Anzahl>&9 Kopiert den Trank in deiner Hand"); cmds.add ("&6/br Copy <Anzahl>&9 Kopiert den Trank in deiner Hand");
} }
@@ -335,4 +347,24 @@ public class CommandListener implements CommandExecutor {
} }
public void cmdUnlabel(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
ItemStack hand = player.getItemInHand();
if (hand != null) {
Brew brew = Brew.get(hand);
if (brew != null) {
brew.unLabel(hand);
p.msg(sender, "&aDas Label wurde entfernt");
return;
}
}
p.msg(sender, "&cDas Item in deiner Hand konnte nicht als Trank identifiziert werden");
} else {
p.msg(sender, "&cDieser Befehl kann nur als Spieler ausgeführt werden");
}
}
} }
@@ -56,10 +56,12 @@ public class InventoryListener implements Listener {
if (event.getSlot() > 2) { if (event.getSlot() > 2) {
return; return;
} }
} else if (event.getInventory().getType() != InventoryType.CHEST) { } else if (event.getInventory().getType() == InventoryType.CHEST) {
if (!event.getInventory().getTitle().equals("Fass")) { if (!event.getInventory().getTitle().equals("Fass")) {
return; return;
} }
} else {
return;
} }
ItemStack item = event.getCurrentItem(); ItemStack item = event.getCurrentItem();
@@ -69,8 +71,10 @@ 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) {
brew.convertLore(meta, false); if (Brew.hasColorLore(meta)) {
item.setItemMeta(meta); brew.convertLore(meta, false);
item.setItemMeta(meta);
}
} }
} }
} }