Convert pre 1.11 Brews (cosmetic)

This commit is contained in:
Sn0wStorm 2019-11-15 14:43:26 +01:00
parent 036657747c
commit d0198c9f04
4 changed files with 48 additions and 11 deletions

View File

@ -14,8 +14,10 @@ import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
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 org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
@ -985,19 +987,40 @@ public class Brew implements Cloneable {
getFromPotionEffect(((PotionMeta) meta), true);
}
public void convertPre19(ItemStack item) {
public void convertPre1_9(ItemStack item) {
removeLegacy(item);
PotionMeta potionMeta = ((PotionMeta) item.getItemMeta());
assert potionMeta != null;
BrewLore lore = new BrewLore(this, potionMeta);
lore.removeEffects();
if (hasRecipe()) {
BrewLore lore = new BrewLore(this, potionMeta);
lore.removeEffects();
currentRecipe.getColor().colorBrew(potionMeta, item, canDistill());
lore.removeLegacySpacing();
} else {
PotionColor.GREY.colorBrew(potionMeta, item, canDistill());
new BrewLore(this, potionMeta).removeLegacySpacing();
}
lore.removeLegacySpacing();
save(potionMeta);
item.setItemMeta(potionMeta);
}
public void convertPre1_11(ItemStack item) {
removeLegacy(item);
PotionMeta potionMeta = ((PotionMeta) item.getItemMeta());
assert potionMeta != null;
potionMeta.setBasePotionData(new PotionData(PotionType.UNCRAFTABLE));
BrewLore lore = new BrewLore(this, potionMeta);
lore.removeEffects();
if (hasRecipe()) {
lore.addOrReplaceEffects(currentRecipe.getEffects(), getQuality());
currentRecipe.getColor().colorBrew(potionMeta, item, canDistill());
} else {
PotionColor.GREY.colorBrew(potionMeta, item, canDistill());
}
lore.removeLegacySpacing();
save(potionMeta);
item.setItemMeta(potionMeta);
}

View File

@ -108,11 +108,22 @@ public class InventoryListener implements Listener {
ItemStack item = event.getCurrentItem();
if (item.hasItemMeta()) {
PotionMeta potion = ((PotionMeta) item.getItemMeta());
// convert potions from 1.8 to 1.9 for color and to remove effect descriptions
if (P.use1_9 && !potion.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
Brew brew = Brew.get(potion);
if (brew != null) {
brew.convertPre19(item);
assert potion != null;
if (P.use1_11) {
// Convert potions from 1.10 to 1.11 for new color
if (potion.getColor() == null) {
Brew brew = Brew.get(potion);
if (brew != null) {
brew.convertPre1_11(item);
}
}
} else {
// convert potions from 1.8 to 1.9 for color and to remove effect descriptions
if (P.use1_9 && !potion.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
Brew brew = Brew.get(potion);
if (brew != null) {
brew.convertPre1_9(item);
}
}
}
Brew brew = Brew.get(item);
@ -203,6 +214,7 @@ public class InventoryListener implements Listener {
ItemStack item = event.getCurrentItem();
if (item != null && item.getType() == Material.POTION && item.hasItemMeta()) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
assert meta != null;
Brew brew = Brew.get(meta);
if (brew != null) {
BrewLore lore = null;
@ -325,6 +337,7 @@ public class InventoryListener implements Listener {
ItemStack item = event.getItem();
if (item.getType() == Material.POTION && Brew.isBrew(item)) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
assert meta != null;
if (BrewLore.hasColorLore(meta)) {
// has color lore, convert lore back to normal
Brew brew = Brew.get(meta);

View File

@ -19,7 +19,7 @@ import java.util.List;
public class BRecipe {
public static List<BRecipe> recipes = new ArrayList<>();
private static List<BRecipe> recipes = new ArrayList<>();
public static int numConfigRecipes; // The number of recipes in the list that are from config
private String[] name;

View File

@ -59,6 +59,7 @@ public class PotionColor {
@SuppressWarnings("deprecation")
public void colorBrew(PotionMeta meta, ItemStack potion, boolean destillable) {
if (P.use1_9) {
// We need to Hide Potion Effects even in 1.12, as it would otherwise show "No Effects"
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
if (P.use1_11) {
// BasePotionData was only used for the Color, so starting with 1.12 we can use setColor instead