mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 06:38:56 +00:00
Fix Potion Colors, using PotionType
Workaround additional misleading effects showing in Lore by hiding all Potion Effects
This commit is contained in:
@@ -1,16 +1,13 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class BIngredients {
|
public class BIngredients {
|
||||||
public static Set<Material> possibleIngredients = new HashSet<Material>();
|
public static Set<Material> possibleIngredients = new HashSet<Material>();
|
||||||
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
|
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
|
||||||
@@ -83,11 +80,7 @@ public class BIngredients {
|
|||||||
Brew.addOrReplaceEffects(potionMeta, brew.getEffects(), brew.getQuality());
|
Brew.addOrReplaceEffects(potionMeta, brew.getEffects(), brew.getQuality());
|
||||||
|
|
||||||
cookedName = cookRecipe.getName(quality);
|
cookedName = cookRecipe.getName(quality);
|
||||||
if (P.use1_9) {
|
Brew.PotionColor.valueOf(cookRecipe.getColor()).colorBrew(potionMeta, potion, false);
|
||||||
potionMeta.setMainEffect(Brew.PotionColor.valueOf(cookRecipe.getColor()).getEffect());
|
|
||||||
} else {
|
|
||||||
potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// new base potion
|
// new base potion
|
||||||
@@ -95,22 +88,14 @@ public class BIngredients {
|
|||||||
|
|
||||||
if (state <= 1) {
|
if (state <= 1) {
|
||||||
cookedName = P.p.languageReader.get("Brew_ThickBrew");
|
cookedName = P.p.languageReader.get("Brew_ThickBrew");
|
||||||
if (P.use1_9) {
|
Brew.PotionColor.BLUE.colorBrew(potionMeta, potion, false);
|
||||||
potionMeta.setMainEffect(Brew.PotionColor.BLUE.getEffect());
|
|
||||||
} else {
|
|
||||||
potion.setDurability(Brew.PotionColor.BLUE.getColorId(false));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (Material ingredient : materials.keySet()) {
|
for (Material ingredient : materials.keySet()) {
|
||||||
if (cookedNames.containsKey(ingredient)) {
|
if (cookedNames.containsKey(ingredient)) {
|
||||||
// if more than half of the ingredients is of one kind
|
// if more than half of the ingredients is of one kind
|
||||||
if (materials.get(ingredient) > (getIngredientsCount() / 2)) {
|
if (materials.get(ingredient) > (getIngredientsCount() / 2)) {
|
||||||
cookedName = cookedNames.get(ingredient);
|
cookedName = cookedNames.get(ingredient);
|
||||||
if (P.use1_9) {
|
Brew.PotionColor.CYAN.colorBrew(potionMeta, potion, true);
|
||||||
potionMeta.setMainEffect(Brew.PotionColor.CYAN.getEffect());
|
|
||||||
} else {
|
|
||||||
potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,11 +104,7 @@ public class BIngredients {
|
|||||||
if (cookedName == null) {
|
if (cookedName == null) {
|
||||||
// if no name could be found
|
// if no name could be found
|
||||||
cookedName = P.p.languageReader.get("Brew_Undefined");
|
cookedName = P.p.languageReader.get("Brew_Undefined");
|
||||||
if (P.use1_9) {
|
Brew.PotionColor.CYAN.colorBrew(potionMeta, potion, true);
|
||||||
potionMeta.setMainEffect(Brew.PotionColor.CYAN.getEffect());
|
|
||||||
} else {
|
|
||||||
potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
potionMeta.setDisplayName(P.p.color("&f" + cookedName));
|
potionMeta.setDisplayName(P.p.color("&f" + cookedName));
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BRecipe {
|
public class BRecipe {
|
||||||
|
|
||||||
private String[] name;
|
private String[] name;
|
||||||
@@ -204,11 +205,7 @@ public class BRecipe {
|
|||||||
|
|
||||||
Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true);
|
Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true);
|
||||||
|
|
||||||
if (P.use1_9) {
|
Brew.PotionColor.valueOf(getColor()).colorBrew(potionMeta, potion, false);
|
||||||
potionMeta.setMainEffect(Brew.PotionColor.valueOf(getColor()).getEffect());
|
|
||||||
} else {
|
|
||||||
potion.setDurability(Brew.PotionColor.valueOf(getColor()).getColorId(false));
|
|
||||||
}
|
|
||||||
potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
|
potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
|
||||||
// This effect stores the UID in its Duration
|
// This effect stores the UID in its Duration
|
||||||
potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
|
potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
package com.dre.brewery;
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.BrewerInventory;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.bukkit.potion.PotionData;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.inventory.BrewerInventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
|
|
||||||
public class Brew {
|
public class Brew {
|
||||||
|
|
||||||
@@ -238,6 +242,7 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canDistill() {
|
public boolean canDistill() {
|
||||||
|
if (stat) return false;
|
||||||
if (currentRecipe != null) {
|
if (currentRecipe != null) {
|
||||||
return currentRecipe.getDistillRuns() > distillRuns;
|
return currentRecipe.getDistillRuns() > distillRuns;
|
||||||
} else if (distillRuns >= 6) {
|
} else if (distillRuns >= 6) {
|
||||||
@@ -292,17 +297,9 @@ public class Brew {
|
|||||||
this.stat = stat;
|
this.stat = stat;
|
||||||
if (currentRecipe != null && canDistill()) {
|
if (currentRecipe != null && canDistill()) {
|
||||||
if (stat) {
|
if (stat) {
|
||||||
if (P.use1_9) {
|
PotionColor.valueOf(currentRecipe.getColor()).colorBrew(((PotionMeta) potion.getItemMeta()), potion, false);
|
||||||
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
|
|
||||||
potionMeta.setMainEffect(PotionColor.valueOf(currentRecipe.getColor()).getEffect());
|
|
||||||
} else {
|
|
||||||
potion.setDurability(PotionColor.valueOf(currentRecipe.getColor()).getColorId(false));
|
|
||||||
}
|
|
||||||
} else if (P.use1_9) {
|
|
||||||
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
|
|
||||||
potionMeta.setMainEffect(PotionColor.valueOf(currentRecipe.getColor()).getEffect());
|
|
||||||
} else {
|
} else {
|
||||||
potion.setDurability(PotionColor.valueOf(currentRecipe.getColor()).getColorId(true));
|
PotionColor.valueOf(currentRecipe.getColor()).colorBrew(((PotionMeta) potion.getItemMeta()), potion, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,21 +335,13 @@ public class Brew {
|
|||||||
|
|
||||||
addOrReplaceEffects(potionMeta, getEffects(), quality);
|
addOrReplaceEffects(potionMeta, getEffects(), quality);
|
||||||
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
|
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
|
||||||
if (P.use1_9) {
|
PotionColor.valueOf(recipe.getColor()).colorBrew(potionMeta, slotItem, canDistill());
|
||||||
potionMeta.setMainEffect(PotionColor.valueOf(recipe.getColor()).getEffect());
|
|
||||||
} else {
|
|
||||||
slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
quality = 0;
|
quality = 0;
|
||||||
removeEffects(potionMeta);
|
removeEffects(potionMeta);
|
||||||
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_DistillUndefined")));
|
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_DistillUndefined")));
|
||||||
if (P.use1_9) {
|
PotionColor.GREY.colorBrew(potionMeta, slotItem, canDistill());
|
||||||
potionMeta.setMainEffect(PotionColor.GREY.getEffect());
|
|
||||||
} else {
|
|
||||||
slotItem.setDurability(PotionColor.GREY.getColorId(canDistill()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distill Lore
|
// Distill Lore
|
||||||
@@ -394,20 +383,12 @@ public class Brew {
|
|||||||
|
|
||||||
addOrReplaceEffects(potionMeta, getEffects(), quality);
|
addOrReplaceEffects(potionMeta, getEffects(), quality);
|
||||||
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
|
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
|
||||||
if (P.use1_9) {
|
PotionColor.valueOf(recipe.getColor()).colorBrew(potionMeta, item, canDistill());
|
||||||
potionMeta.setMainEffect(PotionColor.valueOf(recipe.getColor()).getEffect());
|
|
||||||
} else {
|
|
||||||
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
quality = 0;
|
quality = 0;
|
||||||
removeEffects(potionMeta);
|
removeEffects(potionMeta);
|
||||||
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_BadPotion")));
|
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_BadPotion")));
|
||||||
if (P.use1_9) {
|
PotionColor.GREY.colorBrew(potionMeta, item, canDistill());
|
||||||
potionMeta.setMainEffect(PotionColor.GREY.getEffect());
|
|
||||||
} else {
|
|
||||||
item.setDurability(PotionColor.GREY.getColorId(canDistill()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -664,25 +645,25 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static enum PotionColor {
|
public static enum PotionColor {
|
||||||
PINK(1, PotionEffectType.REGENERATION),
|
PINK(1, PotionType.REGEN),
|
||||||
CYAN(2, PotionEffectType.SPEED),
|
CYAN(2, PotionType.SPEED),
|
||||||
ORANGE(3, PotionEffectType.FIRE_RESISTANCE),
|
ORANGE(3, PotionType.FIRE_RESISTANCE),
|
||||||
GREEN(4, PotionEffectType.POISON),
|
GREEN(4, PotionType.POISON),
|
||||||
BRIGHT_RED(5, PotionEffectType.HEAL),
|
BRIGHT_RED(5, PotionType.INSTANT_HEAL),
|
||||||
BLUE(6, PotionEffectType.NIGHT_VISION),
|
BLUE(6, PotionType.NIGHT_VISION),
|
||||||
BLACK(8, PotionEffectType.WEAKNESS),
|
BLACK(8, PotionType.WEAKNESS),
|
||||||
RED(9, PotionEffectType.INCREASE_DAMAGE),
|
RED(9, PotionType.STRENGTH),
|
||||||
GREY(10, PotionEffectType.SLOW),
|
GREY(10, PotionType.SLOWNESS),
|
||||||
WATER(11, PotionEffectType.WATER_BREATHING),
|
WATER(11, PotionType.WATER_BREATHING),
|
||||||
DARK_RED(12, PotionEffectType.HARM),
|
DARK_RED(12, PotionType.INSTANT_DAMAGE),
|
||||||
BRIGHT_GREY(14, PotionEffectType.INVISIBILITY);
|
BRIGHT_GREY(14, PotionType.INVISIBILITY);
|
||||||
|
|
||||||
private final int colorId;
|
private final int colorId;
|
||||||
private final PotionEffectType effect;
|
private final PotionType type;
|
||||||
|
|
||||||
private PotionColor(int colorId, PotionEffectType effect) {
|
private PotionColor(int colorId, PotionType type) {
|
||||||
this.colorId = colorId;
|
this.colorId = colorId;
|
||||||
this.effect = effect;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets the Damage Value, that sets a color on the potion
|
// gets the Damage Value, that sets a color on the potion
|
||||||
@@ -694,8 +675,17 @@ public class Brew {
|
|||||||
return (short) (colorId + 32);
|
return (short) (colorId + 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PotionEffectType getEffect() {
|
public PotionType getType() {
|
||||||
return effect;
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void colorBrew(PotionMeta meta, ItemStack potion, boolean destillable) {
|
||||||
|
if (P.use1_9) {
|
||||||
|
meta.setBasePotionData(new PotionData(getType()));
|
||||||
|
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||||
|
} else {
|
||||||
|
potion.setDurability(getColorId(destillable));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.dre.brewery.listeners;
|
|||||||
import com.dre.brewery.Brew;
|
import com.dre.brewery.Brew;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@@ -13,7 +14,7 @@ import org.bukkit.potion.PotionType;
|
|||||||
// Workaround to remove unwanted potion effects
|
// Workaround to remove unwanted potion effects
|
||||||
public class DrinkListener1_9 implements Listener {
|
public class DrinkListener1_9 implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onPlayerDrink(PlayerItemConsumeEvent event) {
|
public void onPlayerDrink(PlayerItemConsumeEvent event) {
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
Brew brew = Brew.get(item);
|
Brew brew = Brew.get(item);
|
||||||
|
|||||||
Reference in New Issue
Block a user