Implemented Lore Save system

This commit is contained in:
Sn0wStorm
2019-10-11 18:03:42 +02:00
parent cdd50f8504
commit 4b18dceada
9 changed files with 393 additions and 198 deletions
+64 -15
View File
@@ -4,7 +4,6 @@ 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 java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@@ -17,30 +16,39 @@ public class BIngredients {
public static Map<Material, String> cookedNames = new HashMap<>(); public static Map<Material, String> cookedNames = new HashMap<>();
private static int lastId = 0; private static int lastId = 0;
private int id; private int id; // Legacy
private ArrayList<ItemStack> ingredients = new ArrayList<>(); private List<ItemStack> ingredients = new ArrayList<>();
private Map<Material, Integer> materials = new HashMap<>(); // Merged List Of ingredients that doesnt consider Durability private Map<Material, Integer> materials = new HashMap<>(); // Merged List Of ingredients that doesnt consider Durability
private int cookedTime; private int cookedTime;
// Represents ingredients in Cauldron, Brew // Represents ingredients in Cauldron, Brew
// Init a new BIngredients // Init a new BIngredients
public BIngredients() { public BIngredients() {
this.id = lastId; //this.id = lastId;
lastId++; //lastId++;
} }
// Load from File // Load from File
public BIngredients(ArrayList<ItemStack> ingredients, int cookedTime) { public BIngredients(List<ItemStack> ingredients, int cookedTime) {
this.ingredients = ingredients; this.ingredients = ingredients;
this.cookedTime = cookedTime; this.cookedTime = cookedTime;
this.id = lastId; //this.id = lastId;
lastId++; //lastId++;
for (ItemStack item : ingredients) { for (ItemStack item : ingredients) {
addMaterial(item); addMaterial(item);
} }
} }
// Load from legacy Brew section
public BIngredients(List<ItemStack> ingredients, int cookedTime, boolean legacy) {
this(ingredients, cookedTime);
if (legacy) {
this.id = lastId;
lastId++;
}
}
// Add an ingredient to this // Add an ingredient to this
public void add(ItemStack ingredient) { public void add(ItemStack ingredient) {
addMaterial(ingredient); addMaterial(ingredient);
@@ -72,14 +80,15 @@ public class BIngredients {
cookedTime = state; cookedTime = state;
String cookedName = null; String cookedName = null;
BRecipe cookRecipe = getCookRecipe(); BRecipe cookRecipe = getCookRecipe();
Brew brew;
int uid = Brew.generateUID(); //int uid = Brew.generateUID();
if (cookRecipe != null) { if (cookRecipe != null) {
// Potion is best with cooking only // Potion is best with cooking only
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0); int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
P.p.debugLog("cooked potion has Quality: " + quality); P.p.debugLog("cooked potion has Quality: " + quality);
Brew brew = new Brew(uid, quality, cookRecipe, this); brew = new Brew(quality, cookRecipe, this);
Brew.addOrReplaceEffects(potionMeta, brew.getEffects(), brew.getQuality()); Brew.addOrReplaceEffects(potionMeta, brew.getEffects(), brew.getQuality());
cookedName = cookRecipe.getName(quality); cookedName = cookRecipe.getName(quality);
@@ -87,7 +96,7 @@ public class BIngredients {
} else { } else {
// new base potion // new base potion
new Brew(uid, this); brew = new Brew(this);
if (state <= 1) { if (state <= 1) {
cookedName = P.p.languageReader.get("Brew_ThickBrew"); cookedName = P.p.languageReader.get("Brew_ThickBrew");
@@ -117,14 +126,17 @@ public class BIngredients {
uid *= 4; uid *= 4;
} }
// This effect stores the UID in its Duration // This effect stores the UID in its Duration
potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect(uid, 0), true); //potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
brew.touch();
brew.save(potionMeta);
potion.setItemMeta(potionMeta); potion.setItemMeta(potionMeta);
return potion; return potion;
} }
// returns amount of ingredients // returns amount of ingredients
private int getIngredientsCount() { public int getIngredientsCount() {
int count = 0; int count = 0;
for (ItemStack item : ingredients) { for (ItemStack item : ingredients) {
count += item.getAmount(); count += item.getAmount();
@@ -290,7 +302,7 @@ public class BIngredients {
} }
// returns pseudo quality of distilling. 0 if doesnt match the need of the recipes distilling // returns pseudo quality of distilling. 0 if doesnt match the need of the recipes distilling
public int getDistillQuality(BRecipe recipe, int distillRuns) { public int getDistillQuality(BRecipe recipe, byte distillRuns) {
if (recipe.needsDistilling() != distillRuns > 0) { if (recipe.needsDistilling() != distillRuns > 0) {
return 0; return 0;
} }
@@ -316,7 +328,12 @@ public class BIngredients {
} }
// Creates a copy ingredients // Creates a copy ingredients
@Override
public BIngredients clone() { public BIngredients clone() {
try {
super.clone();
} catch (CloneNotSupportedException ingored) {
}
BIngredients copy = new BIngredients(); BIngredients copy = new BIngredients();
copy.ingredients.addAll(ingredients); copy.ingredients.addAll(ingredients);
copy.materials.putAll(materials); copy.materials.putAll(materials);
@@ -324,7 +341,14 @@ public class BIngredients {
return copy; return copy;
} }
public void testStore(DataOutputStream out) throws IOException { @Override
public String toString() {
return "BIngredients{" +
"cookedTime=" + cookedTime +
", total ingedients: " + getIngredientsCount() + '}';
}
/*public void testStore(DataOutputStream out) throws IOException {
out.writeInt(cookedTime); out.writeInt(cookedTime);
out.writeByte(ingredients.size()); out.writeByte(ingredients.size());
for (ItemStack item : ingredients) { for (ItemStack item : ingredients) {
@@ -353,9 +377,34 @@ public class BIngredients {
P.p.log("amount wrong"); P.p.log("amount wrong");
} }
} }
}*/
public void save(DataOutputStream out) throws IOException {
out.writeInt(cookedTime);
out.writeByte(ingredients.size());
for (ItemStack item : ingredients) {
out.writeUTF(item.getType().name());
out.writeShort(item.getAmount());
out.writeShort(item.getDurability());
}
}
public static BIngredients load(DataInputStream in) throws IOException {
int cookedTime = in.readInt();
byte size = in.readByte();
List<ItemStack> ing = new ArrayList<>(size);
for (; size > 0; size--) {
Material mat = Material.getMaterial(in.readUTF());
if (mat != null) {
ing.add(new ItemStack(mat, in.readShort(), in.readShort()));
}
}
return new BIngredients(ing, cookedTime);
} }
// saves data into main Ingredient section. Returns the save id // saves data into main Ingredient section. Returns the save id
// Only needed for legacy potions
@Deprecated
public int save(ConfigurationSection config) { public int save(ConfigurationSection config) {
String path = "Ingredients." + id; String path = "Ingredients." + id;
if (cookedTime != 0) { if (cookedTime != 0) {
+15 -8
View File
@@ -4,7 +4,6 @@ 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 java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -14,7 +13,7 @@ public class BRecipe {
private String[] name; private String[] name;
private ArrayList<ItemStack> ingredients = new ArrayList<>(); // material and amount private ArrayList<ItemStack> ingredients = new ArrayList<>(); // material and amount
private int cookingTime; // time to cook in cauldron private int cookingTime; // time to cook in cauldron
private int distillruns; // runs through the brewer private byte distillruns; // runs through the brewer
private int distillTime; // time for one distill run in seconds private int distillTime; // time for one distill run in seconds
private byte wood; // type of wood the barrel has to consist of private byte wood; // type of wood the barrel has to consist of
private int age; // time in minecraft days for the potions to age in barrels private int age; // time in minecraft days for the potions to age in barrels
@@ -90,7 +89,12 @@ public class BRecipe {
} }
} }
this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime", 1); this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime", 1);
this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns", 0); int dis = configSectionRecipes.getInt(recipeId + ".distillruns", 0);
if (dis > Byte.MAX_VALUE) {
this.distillruns = Byte.MAX_VALUE;
} else {
this.distillruns = (byte) dis;
}
this.distillTime = configSectionRecipes.getInt(recipeId + ".distilltime", 0) * 20; this.distillTime = configSectionRecipes.getInt(recipeId + ".distilltime", 0) * 20;
this.wood = (byte) configSectionRecipes.getInt(recipeId + ".wood", 0); this.wood = (byte) configSectionRecipes.getInt(recipeId + ".wood", 0);
this.age = configSectionRecipes.getInt(recipeId + ".age", 0); this.age = configSectionRecipes.getInt(recipeId + ".age", 0);
@@ -247,8 +251,6 @@ public class BRecipe {
ItemStack potion = new ItemStack(Material.POTION); ItemStack potion = new ItemStack(Material.POTION);
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
int uid = Brew.generateUID();
ArrayList<ItemStack> list = new ArrayList<>(ingredients.size()); ArrayList<ItemStack> list = new ArrayList<>(ingredients.size());
for (ItemStack item : ingredients) { for (ItemStack item : ingredients) {
if (item.getDurability() == -1) { if (item.getDurability() == -1) {
@@ -260,7 +262,7 @@ public class BRecipe {
BIngredients bIngredients = new BIngredients(list, cookingTime); BIngredients bIngredients = new BIngredients(list, cookingTime);
Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true, 0); Brew brew = new Brew(bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true);
Brew.PotionColor.fromString(getColor()).colorBrew(potionMeta, potion, false); Brew.PotionColor.fromString(getColor()).colorBrew(potionMeta, potion, false);
potionMeta.setDisplayName(P.p.color("&f" + getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
@@ -270,11 +272,12 @@ public class BRecipe {
uid *= 4; uid *= 4;
} }
// This effect stores the UID in its Duration // This effect stores the UID in its Duration
potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect(uid, 0), true); //potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
brew.convertLore(potionMeta, false); brew.convertLore(potionMeta, false);
Brew.addOrReplaceEffects(potionMeta, effects, quality); Brew.addOrReplaceEffects(potionMeta, effects, quality);
brew.touch(); brew.touch();
brew.save(potionMeta);
potion.setItemMeta(potionMeta); potion.setItemMeta(potionMeta);
return potion; return potion;
@@ -322,7 +325,7 @@ public class BRecipe {
return cookingTime; return cookingTime;
} }
public int getDistillRuns() { public byte getDistillRuns() {
return distillruns; return distillruns;
} }
@@ -358,4 +361,8 @@ public class BRecipe {
return effects; return effects;
} }
@Override
public String toString() {
return "BRecipe{" + getName(5) + '}';
}
} }
+254 -104
View File
@@ -1,11 +1,16 @@
package com.dre.brewery; package com.dre.brewery;
import org.bukkit.Color; import org.bukkit.Color;
import com.dre.brewery.lore.Base91DecoderStream;
import com.dre.brewery.lore.Base91EncoderStream;
import com.dre.brewery.lore.LoreLoadStream;
import com.dre.brewery.lore.LoreSaveStream;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.BrewerInventory; import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@@ -24,40 +29,35 @@ public class Brew {
// represents the liquid in the brewed Potions // represents the liquid in the brewed Potions
public static Map<Integer, Brew> potions = new HashMap<>(); public static Map<Integer, Brew> legacyPotions = new HashMap<>();
public static long installTime = System.currentTimeMillis(); // plugin install time in millis after epoch public static long installTime = System.currentTimeMillis(); // plugin install time in millis after epoch
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
private BIngredients ingredients; private BIngredients ingredients;
private int quality; private int quality;
private int distillRuns; private byte distillRuns;
private float ageTime; private float ageTime;
private float wood; private float wood;
private BRecipe currentRecipe; private BRecipe currentRecipe;
private boolean unlabeled; private boolean unlabeled;
private boolean persistent; private boolean persistent;
private boolean stat; // static potions should not be changed private boolean stat; // static potions should not be changed
private int lastUpdate; // last update in hours after install time //private int lastUpdate; // last update in hours after install time
public Brew(int uid, BIngredients ingredients) { public Brew(BIngredients ingredients) {
this.ingredients = ingredients; this.ingredients = ingredients;
touch();
potions.put(uid, this);
} }
// quality already set // quality already set
public Brew(int uid, int quality, BRecipe recipe, BIngredients ingredients) { public Brew(int quality, BRecipe recipe, BIngredients ingredients) {
this.ingredients = ingredients; this.ingredients = ingredients;
this.quality = quality; this.quality = quality;
this.currentRecipe = recipe; this.currentRecipe = recipe;
touch();
potions.put(uid, this);
} }
// loading from file // loading with all values set
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) { public Brew(BIngredients ingredients, int quality, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat) {
potions.put(uid, this);
this.ingredients = ingredients; this.ingredients = ingredients;
this.quality = quality; this.quality = quality;
this.distillRuns = distillRuns; this.distillRuns = distillRuns;
@@ -66,44 +66,95 @@ public class Brew {
this.unlabeled = unlabeled; this.unlabeled = unlabeled;
this.persistent = persistent; this.persistent = persistent;
this.stat = stat; this.stat = stat;
this.lastUpdate = lastUpdate;
setRecipeFromString(recipe); setRecipeFromString(recipe);
} }
// returns a Brew by its UID // Loading from InputStream
public static Brew get(int uid) { private Brew() {
if (uid < -1) {
if (!potions.containsKey(uid)) {
P.p.errorLog("Database failure! unable to find UID " + uid + " of a custom Potion!");
return null;// throw some exception?
}
} else {
return null;
}
return potions.get(uid);
} }
// returns a Brew by PotionMeta // returns a Brew by ItemMeta
public static Brew get(PotionMeta meta) { public static Brew get(ItemMeta meta) {
return get(getUID(meta)); if (meta.hasLore()) {
if (meta instanceof PotionMeta && ((PotionMeta) meta).hasCustomEffect(PotionEffectType.REGENERATION)) {
Brew brew = load(meta);
if (brew != null) {
brew = getFromPotionEffect(((PotionMeta) meta), false);
}
return brew;
} else {
return load(meta);
}
}
return null;
} }
// returns a Brew by ItemStack // returns a Brew by ItemStack
public static Brew get(ItemStack item) { public static Brew get(ItemStack item) {
if (item.getType() == Material.POTION) { if (item.getType() == Material.POTION) {
if (item.hasItemMeta()) { if (item.hasItemMeta()) {
return get((PotionMeta) item.getItemMeta()); ItemMeta meta = item.getItemMeta();
if (meta.hasLore()) {
if (meta instanceof PotionMeta && ((PotionMeta) meta).hasCustomEffect(PotionEffectType.REGENERATION)) {
Brew brew = load(meta);
if (brew != null) {
((PotionMeta) meta).removeCustomEffect(PotionEffectType.REGENERATION);
} else {
brew = getFromPotionEffect(((PotionMeta) meta), true);
if (brew == null) return null;
brew.save(meta);
}
item.setItemMeta(meta);
return brew;
} else {
return load(meta);
}
}
} }
} }
return null; return null;
} }
private static Brew getFromPotionEffect(PotionMeta potionMeta, boolean remove) {
for (PotionEffect effect : potionMeta.getCustomEffects()) {
if (effect.getType().equals(PotionEffectType.REGENERATION)) {
if (effect.getDuration() < -1) {
if (remove) {
return legacyPotions.remove(effect.getDuration());
} else {
return legacyPotions.get(effect.getDuration());
}
}
}
}
return null;
}
// returns a Brew by its UID
// Does not work anymore with new save system
@Deprecated
public static Brew get(int uid) {
if (uid < -1) {
if (!legacyPotions.containsKey(uid)) {
P.p.errorLog("Database failure! unable to find UID " + uid + " of a custom Potion!");
return null;// throw some exception?
}
} else {
return null;
}
return legacyPotions.get(uid);
}
// returns UID of custom Potion item // returns UID of custom Potion item
// Does not work anymore with new save system
@Deprecated
public static int getUID(ItemStack item) { public static int getUID(ItemStack item) {
return getUID((PotionMeta) item.getItemMeta()); return getUID((PotionMeta) item.getItemMeta());
} }
// returns UID of custom Potion meta // returns UID of custom Potion meta
// Does not work anymore with new save system
@Deprecated
public static int getUID(PotionMeta potionMeta) { public static int getUID(PotionMeta potionMeta) {
if (potionMeta.hasCustomEffect(PotionEffectType.REGENERATION)) { if (potionMeta.hasCustomEffect(PotionEffectType.REGENERATION)) {
for (PotionEffect effect : potionMeta.getCustomEffects()) { for (PotionEffect effect : potionMeta.getCustomEffects()) {
@@ -118,13 +169,13 @@ public class Brew {
} }
// generate an UID // generate an UID
public static int generateUID() { /*public static int generateUID() {
int uid = -2; int uid = -2;
while (potions.containsKey(uid)) { while (potions.containsKey(uid)) {
uid -= 1; uid -= 1;
} }
return uid; return uid;
} }*/
//returns the recipe with the given name, recalculates if not found //returns the recipe with the given name, recalculates if not found
public boolean setRecipeFromString(String name) { public boolean setRecipeFromString(String name) {
@@ -158,7 +209,8 @@ public class Brew {
} }
// Copy a Brew with a new unique ID and return its item // Copy a Brew with a new unique ID and return its item
public ItemStack copy(ItemStack item) { // Not needed anymore
/*public ItemStack copy(ItemStack item) {
ItemStack copy = item.clone(); ItemStack copy = item.clone();
int uid = generateUID(); int uid = generateUID();
clone(uid); clone(uid);
@@ -170,11 +222,13 @@ public class Brew {
meta.addCustomEffect((PotionEffectType.REGENERATION).createEffect(uid, 0), true); meta.addCustomEffect((PotionEffectType.REGENERATION).createEffect(uid, 0), true);
copy.setItemMeta(meta); copy.setItemMeta(meta);
return copy; return copy;
} }*/
// Clones this instance with a new unique ID // Clones this instance
public Brew clone(int uid) { @Override
Brew brew = new Brew(uid, quality, currentRecipe, ingredients); public Brew clone() throws CloneNotSupportedException {
super.clone();
Brew brew = new Brew(quality, currentRecipe, ingredients);
brew.distillRuns = distillRuns; brew.distillRuns = distillRuns;
brew.ageTime = ageTime; brew.ageTime = ageTime;
brew.unlabeled = unlabeled; brew.unlabeled = unlabeled;
@@ -184,12 +238,28 @@ public class Brew {
return brew; return brew;
} }
@Override
public String toString() {
return "Brew{" +
ingredients + " ingredients" +
", quality=" + quality +
", distillRuns=" + distillRuns +
", ageTime=" + ageTime +
", wood=" + wood +
", currentRecipe=" + currentRecipe +
", unlabeled=" + unlabeled +
", persistent=" + persistent +
", stat=" + stat +
'}';
}
// remove potion from file (drinking, despawning, combusting, cmdDeleting, should be more!) // remove potion from file (drinking, despawning, combusting, cmdDeleting, should be more!)
public void remove(ItemStack item) { // Not needed anymore
/*public void remove(ItemStack item) {
if (!persistent) { if (!persistent) {
potions.remove(getUID(item)); potions.remove(getUID(item));
} }
} }*/
// calculate alcohol from recipe // calculate alcohol from recipe
public int calcAlcohol() { public int calcAlcohol() {
@@ -283,11 +353,12 @@ public class Brew {
} }
// Do some regular updates // Do some regular updates
// Currently does nothing, but may be used to update something on this brew
public void touch() { public void touch() {
lastUpdate = (int) ((double) (System.currentTimeMillis() - installTime) / 3600000D); //lastUpdate = (int) ((double) (System.currentTimeMillis() - installTime) / 3600000D);
} }
public int getDistillRuns() { public byte getDistillRuns() {
return distillRuns; return distillRuns;
} }
@@ -299,16 +370,23 @@ public class Brew {
return currentRecipe; return currentRecipe;
} }
// Not needed anymore
// TODO remove
@Deprecated
public boolean isPersistent() { public boolean isPersistent() {
return persistent; return persistent;
} }
// Make a potion persistent to not delete it when drinking it // Make a potion persistent to not delete it when drinking it
// Not needed anymore
@Deprecated
public void makePersistent() { public void makePersistent() {
persistent = true; persistent = true;
} }
// Remove the Persistence Flag from a brew, so it will be normally deleted when drinking it // Remove the Persistence Flag from a brew, so it will be normally deleted when drinking it
// Not needed anymore
@Deprecated
public void removePersistence() { public void removePersistence() {
persistent = false; persistent = false;
} }
@@ -329,9 +407,9 @@ public class Brew {
} }
} }
public int getLastUpdate() { /*public int getLastUpdate() {
return lastUpdate; return lastUpdate;
} }*/
// Distilling section --------------- // Distilling section ---------------
@@ -382,6 +460,7 @@ public class Brew {
} }
updateDistillLore(prefix, potionMeta); updateDistillLore(prefix, potionMeta);
touch(); touch();
save(potionMeta);
slotItem.setItemMeta(potionMeta); slotItem.setItemMeta(potionMeta);
} }
@@ -454,6 +533,7 @@ public class Brew {
} }
} }
touch(); touch();
save(potionMeta);
item.setItemMeta(potionMeta); item.setItemMeta(potionMeta);
} }
@@ -607,14 +687,14 @@ public class Brew {
} }
} }
// Removes all effects except regeneration which stores data // Removes all effects
public static void removeEffects(PotionMeta meta) { public static void removeEffects(PotionMeta meta) {
if (meta.hasCustomEffects()) { if (meta.hasCustomEffects()) {
for (PotionEffect effect : meta.getCustomEffects()) { for (PotionEffect effect : meta.getCustomEffects()) {
PotionEffectType type = effect.getType(); PotionEffectType type = effect.getType();
if (!type.equals(PotionEffectType.REGENERATION)) { //if (!type.equals(PotionEffectType.REGENERATION)) {
meta.removeCustomEffect(type); meta.removeCustomEffect(type);
} //}
} }
} }
} }
@@ -652,83 +732,153 @@ public class Brew {
return P.p.color(color); return P.p.color(color);
} }
public void testStore(DataOutputStream out) throws IOException { private static Brew load(ItemMeta meta) {
out.writeByte(86); // Parity LoreLoadStream loreStream;
out.writeByte(1); // Version try {
out.writeInt(quality); loreStream = new LoreLoadStream(meta, 0);
int bools = 0; } catch (IllegalArgumentException ignored) {
bools += (distillRuns != 0 ? 1 : 0); return null;
bools += (ageTime > 0 ? 2 : 0);
bools += (wood != -1 ? 4 : 0);
bools += (currentRecipe != null ? 8 : 0);
bools += (unlabeled ? 16 : 0);
bools += (persistent ? 32 : 0);
bools += (stat ? 64 : 0);
out.writeByte(bools);
if (distillRuns != 0) {
out.writeByte(distillRuns);
} }
if (ageTime > 0) { DataInputStream in = new DataInputStream(new Base91DecoderStream(loreStream));
out.writeFloat(ageTime); try {
if (in.readByte() != 86) {
P.p.errorLog("parity check failed on Brew while loading, trying to load anyways!");
}
Brew brew = new Brew();
byte ver = in.readByte();
switch (ver) {
case 1:
brew.loadFromStream(in);
break;
default:
P.p.errorLog("Brew has data stored in v" + ver + " this version supports up to v1");
return null;
}
return brew;
} catch (IOException e) {
P.p.errorLog("IO Error while loading Brew");
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
if (wood != -1) { return null;
out.writeFloat(wood);
}
if (currentRecipe != null) {
out.writeUTF(currentRecipe.getName(5));
}
ingredients.testStore(out);
} }
public void testLoad(DataInputStream in) throws IOException { // TODO load and save Ingredients
if (in.readByte() != 86) {
P.p.log("parity check failed"); private void loadFromStream(DataInputStream in) throws IOException {
return; quality = in.readByte();
}
if (in.readByte() != 1) {
P.p.log("unknown version");
return;
}
if (in.readInt() != quality) {
P.p.log("quality wrong");
}
int bools = in.readUnsignedByte(); int bools = in.readUnsignedByte();
if ((bools & 1) != 0) { if ((bools & 1) != 0) {
if (in.readByte() != distillRuns) { distillRuns = in.readByte();
P.p.log("distillruns wrong");
}
} }
if ((bools & 2) != 0) { if ((bools & 2) != 0) {
if (in.readFloat() != ageTime) { ageTime = in.readFloat();
P.p.log("agetime wrong");
}
} }
if ((bools & 4) != 0) { if ((bools & 4) != 0) {
if (in.readFloat() != wood) { wood = in.readFloat();
P.p.log("wood wrong");
}
} }
if ((bools & 8) != 0) { if ((bools & 8) != 0) {
if (!in.readUTF().equals(currentRecipe.getName(5))) { setRecipeFromString(in.readUTF());
P.p.log("currecipe wrong"); } else {
setRecipeFromString(null);
}
unlabeled = (bools & 16) != 0;
persistent = (bools & 32) != 0;
stat = (bools & 64) != 0;
}
// Save brew data into meta/lore
public void save(ItemMeta meta) {
LoreSaveStream loreStream = new LoreSaveStream(meta, 0);
saveToStream(new DataOutputStream(new Base91EncoderStream(loreStream)));
}
// Save brew data into the meta/lore of the specified item
// The meta on the item changes, so to make further changes to the meta, item.getItemMeta() has to be called again after this
public void save(ItemStack item) {
ItemMeta meta;
if (!item.hasItemMeta()) {
meta = P.p.getServer().getItemFactory().getItemMeta(item.getType());
} else {
meta = item.getItemMeta();
}
save(meta);
item.setItemMeta(meta);
}
public void saveToStream(DataOutputStream out) {
try {
out.writeByte(86); // Parity/sanity
out.writeByte(1); // Version
if (quality > 10) {
quality = 10;
}
out.writeByte((byte) quality);
int bools = 0;
bools |= ((distillRuns != 0) ? 1 : 0);
bools |= (ageTime > 0 ? 2 : 0);
bools |= (wood != -1 ? 4 : 0);
bools |= (currentRecipe != null ? 8 : 0);
bools |= (unlabeled ? 16 : 0);
bools |= (persistent ? 32 : 0); // TODO remove persistence
bools |= (stat ? 64 : 0);
out.writeByte(bools);
if (distillRuns != 0) {
out.writeByte(distillRuns);
}
if (ageTime > 0) {
out.writeFloat(ageTime);
}
if (wood != -1) {
out.writeFloat(wood);
}
if (currentRecipe != null) {
out.writeUTF(currentRecipe.getName(5));
}
} catch (IOException e) {
P.p.errorLog("IO Error while saving Brew");
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
} }
} }
if ((bools & 16) != 0 && !unlabeled) { }
P.p.log("unlabeled wrong");
// Load potion data from data file for backwards compatibility
public static void loadLegacy(BIngredients ingredients, int uid, int quality, byte distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat) {
Brew brew = new Brew(ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat);
legacyPotions.put(uid, brew);
}
// remove legacy potiondata from item
public static void removeLegacy(ItemStack item) {
if (legacyPotions.isEmpty()) return;
if (!item.hasItemMeta()) return;
ItemMeta meta = item.getItemMeta();
if (!(meta instanceof PotionMeta)) return;
for (PotionEffect effect : ((PotionMeta) meta).getCustomEffects()) {
if (effect.getType().equals(PotionEffectType.REGENERATION)) {
if (effect.getDuration() < -1) {
legacyPotions.remove(effect.getDuration());
return;
}
}
} }
if ((bools & 32) != 0 && !persistent) {
P.p.log("persistent wrong");
}
if ((bools & 64) != 0 && !stat) {
P.p.log("stat wrong");
}
ingredients.testLoad(in);
P.p.log("load successful");
} }
// Saves all data // Saves all data
// Legacy method to save to data file
@Deprecated
public static void save(ConfigurationSection config) { public static void save(ConfigurationSection config) {
for (Map.Entry<Integer, Brew> entry : potions.entrySet()) { for (Map.Entry<Integer, Brew> entry : legacyPotions.entrySet()) {
int uid = entry.getKey(); int uid = entry.getKey();
Brew brew = entry.getValue(); Brew brew = entry.getValue();
ConfigurationSection idConfig = config.createSection("" + uid); ConfigurationSection idConfig = config.createSection("" + uid);
@@ -757,9 +907,9 @@ public class Brew {
if (brew.stat) { if (brew.stat) {
idConfig.set("stat", true); idConfig.set("stat", true);
} }
if (brew.lastUpdate > 0) { /*if (brew.lastUpdate > 0) {
idConfig.set("lastUpdate", brew.lastUpdate); idConfig.set("lastUpdate", brew.lastUpdate);
} }*/
// save the ingredients // save the ingredients
idConfig.set("ingId", brew.ingredients.save(config.getParent())); idConfig.set("ingId", brew.ingredients.save(config.getParent()));
} }
+11 -15
View File
@@ -11,10 +11,6 @@ import com.dre.brewery.integration.WGBarrel7;
import com.dre.brewery.integration.WGBarrelNew; import com.dre.brewery.integration.WGBarrelNew;
import com.dre.brewery.integration.WGBarrelOld; import com.dre.brewery.integration.WGBarrelOld;
import com.dre.brewery.listeners.*; import com.dre.brewery.listeners.*;
import com.dre.brewery.lore.Base91DecoderStream;
import com.dre.brewery.lore.Base91EncoderStream;
import com.dre.brewery.lore.LoreLoadStream;
import com.dre.brewery.lore.LoreSaveStream;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -91,7 +87,7 @@ public class P extends JavaPlugin {
//P.p.log("§" + (use1_9 ? "a":"c") + "1.9 " + "§" + (use1_11 ? "a":"c") + "1.11 " + "§" + (use1_13 ? "a":"c") + "1.13 " + "§" + (use1_14 ? "a":"c") + "1.14"); //P.p.log("§" + (use1_9 ? "a":"c") + "1.9 " + "§" + (use1_11 ? "a":"c") + "1.11 " + "§" + (use1_13 ? "a":"c") + "1.13 " + "§" + (use1_14 ? "a":"c") + "1.14");
try { /*try {
ItemMeta meta = new ItemStack(Material.POTION).getItemMeta(); ItemMeta meta = new ItemStack(Material.POTION).getItemMeta();
DataOutputStream data = new DataOutputStream(new Base91EncoderStream(new LoreSaveStream(meta, 3))); DataOutputStream data = new DataOutputStream(new Base91EncoderStream(new LoreSaveStream(meta, 3)));
@@ -125,7 +121,7 @@ public class P extends JavaPlugin {
/*basE91 basE91 = new basE91(); basE91 basE91 = new basE91();
int[] input = new int[] {12, 65, 324, 5, 12, 129459, 1234567, Integer.MIN_VALUE, Integer.MAX_VALUE}; int[] input = new int[] {12, 65, 324, 5, 12, 129459, 1234567, Integer.MIN_VALUE, Integer.MAX_VALUE};
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(stream); DataOutputStream data = new DataOutputStream(stream);
@@ -198,11 +194,11 @@ public class P extends JavaPlugin {
} }
tdata.close(); tdata.close();
test = test;*/ test = test;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }*/
// load the Config // load the Config
@@ -338,7 +334,7 @@ public class P extends JavaPlugin {
BIngredients.recipes.clear(); BIngredients.recipes.clear();
BIngredients.cookedNames.clear(); BIngredients.cookedNames.clear();
BPlayer.clear(); BPlayer.clear();
Brew.potions.clear(); Brew.legacyPotions.clear();
Wakeup.wakeups.clear(); Wakeup.wakeups.clear();
Words.words.clear(); Words.words.clear();
Words.ignoreText.clear(); Words.ignoreText.clear();
@@ -387,7 +383,7 @@ public class P extends JavaPlugin {
// Reload Recipes // Reload Recipes
boolean successful = true; boolean successful = true;
for (Brew brew : Brew.potions.values()) { for (Brew brew : Brew.legacyPotions.values()) {
if (!brew.reloadRecipe()) { if (!brew.reloadRecipe()) {
successful = false; successful = false;
} }
@@ -603,30 +599,30 @@ public class P extends JavaPlugin {
if (matSection != null) { if (matSection != null) {
// matSection has all the materials + amount as Integers // matSection has all the materials + amount as Integers
ArrayList<ItemStack> ingredients = deserializeIngredients(matSection); ArrayList<ItemStack> ingredients = deserializeIngredients(matSection);
ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0))); ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0), true));
} else { } else {
errorLog("Ingredient id: '" + id + "' incomplete in data.yml"); errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
} }
} }
} }
// loading Brew // loading Brew legacy
section = data.getConfigurationSection("Brew"); section = data.getConfigurationSection("Brew");
if (section != null) { if (section != null) {
// All sections have the UID as name // All sections have the UID as name
for (String uid : section.getKeys(false)) { for (String uid : section.getKeys(false)) {
BIngredients ingredients = getIngredients(ingMap, section.getString(uid + ".ingId")); BIngredients ingredients = getIngredients(ingMap, section.getString(uid + ".ingId"));
int quality = section.getInt(uid + ".quality", 0); int quality = section.getInt(uid + ".quality", 0);
int distillRuns = section.getInt(uid + ".distillRuns", 0); byte distillRuns = (byte) section.getInt(uid + ".distillRuns", 0);
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0); float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
float wood = (float) section.getDouble(uid + ".wood", -1.0); float wood = (float) section.getDouble(uid + ".wood", -1.0);
String recipe = section.getString(uid + ".recipe", null); String recipe = section.getString(uid + ".recipe", null);
boolean unlabeled = section.getBoolean(uid + ".unlabeled", false); boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
boolean persistent = section.getBoolean(uid + ".persist", false); boolean persistent = section.getBoolean(uid + ".persist", false);
boolean stat = section.getBoolean(uid + ".stat", false); boolean stat = section.getBoolean(uid + ".stat", false);
int lastUpdate = section.getInt("lastUpdate", 0); //int lastUpdate = section.getInt("lastUpdate", 0);
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate); Brew.loadLegacy(ingredients, parseInt(uid), quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat);
} }
} }
+1 -1
View File
@@ -64,7 +64,7 @@ public class DataSave extends BukkitRunnable {
configFile.set("installTime", Brew.installTime); configFile.set("installTime", Brew.installTime);
configFile.set("MCBarrelTime", MCBarrel.mcBarrelTime); configFile.set("MCBarrelTime", MCBarrel.mcBarrelTime);
if (!Brew.potions.isEmpty()) { if (!Brew.legacyPotions.isEmpty()) {
Brew.save(configFile.createSection("Brew")); Brew.save(configFile.createSection("Brew"));
} }
@@ -380,6 +380,7 @@ public class CommandListener implements CommandExecutor {
} }
} }
@Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void cmdCopy(CommandSender sender, int count) { public void cmdCopy(CommandSender sender, int count) {
@@ -395,7 +396,7 @@ public class CommandListener implements CommandExecutor {
Brew brew = Brew.get(hand); Brew brew = Brew.get(hand);
if (brew != null) { if (brew != null) {
while (count > 0) { while (count > 0) {
ItemStack item = brew.copy(hand); ItemStack item = hand.clone();
if (!(player.getInventory().addItem(item)).isEmpty()) { if (!(player.getInventory().addItem(item)).isEmpty()) {
p.msg(sender, p.languageReader.get("CMD_Copy_Error", "" + count)); p.msg(sender, p.languageReader.get("CMD_Copy_Error", "" + count));
return; return;
@@ -417,6 +418,7 @@ public class CommandListener implements CommandExecutor {
} }
@Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void cmdDelete(CommandSender sender) { public void cmdDelete(CommandSender sender) {
@@ -429,7 +431,7 @@ public class CommandListener implements CommandExecutor {
if (brew.isPersistent()) { if (brew.isPersistent()) {
p.msg(sender, p.languageReader.get("CMD_PersistRemove")); p.msg(sender, p.languageReader.get("CMD_PersistRemove"));
} else { } else {
brew.remove(hand); //brew.remove(hand);
player.setItemInHand(new ItemStack(Material.AIR)); player.setItemInHand(new ItemStack(Material.AIR));
} }
return; return;
@@ -442,6 +444,7 @@ public class CommandListener implements CommandExecutor {
} }
@Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void cmdPersist(CommandSender sender) { public void cmdPersist(CommandSender sender) {
@@ -461,6 +464,7 @@ public class CommandListener implements CommandExecutor {
p.msg(sender, p.languageReader.get("CMD_Persistent")); p.msg(sender, p.languageReader.get("CMD_Persistent"));
} }
brew.touch(); brew.touch();
brew.save(hand);
return; return;
} }
} }
@@ -492,6 +496,7 @@ public class CommandListener implements CommandExecutor {
p.msg(sender, p.languageReader.get("CMD_Static")); p.msg(sender, p.languageReader.get("CMD_Static"));
} }
brew.touch(); brew.touch();
brew.save(hand);
return; return;
} }
} }
@@ -513,6 +518,7 @@ public class CommandListener implements CommandExecutor {
if (brew != null) { if (brew != null) {
brew.unLabel(hand); brew.unLabel(hand);
brew.touch(); brew.touch();
brew.save(hand);
p.msg(sender, p.languageReader.get("CMD_UnLabel")); p.msg(sender, p.languageReader.get("CMD_UnLabel"));
return; return;
} }
@@ -28,10 +28,7 @@ public class EntityListener implements Listener {
public void onItemDespawn(ItemDespawnEvent event) { public void onItemDespawn(ItemDespawnEvent event) {
ItemStack item = event.getEntity().getItemStack(); ItemStack item = event.getEntity().getItemStack();
if (item.getType() == Material.POTION) { if (item.getType() == Material.POTION) {
Brew brew = Brew.get(item); Brew.removeLegacy(item);
if (brew != null) {
brew.remove(item);
}
} }
} }
@@ -42,10 +39,7 @@ public class EntityListener implements Listener {
if (entity instanceof Item) { if (entity instanceof Item) {
ItemStack item = ((Item) entity).getItemStack(); ItemStack item = ((Item) entity).getItemStack();
if (item.getType() == Material.POTION) { if (item.getType() == Material.POTION) {
Brew brew = Brew.get(item); Brew.removeLegacy(item);
if (brew != null) {
brew.remove(item);
}
} }
} }
} }
@@ -7,10 +7,6 @@ import com.dre.brewery.Brew;
import com.dre.brewery.MCBarrel; import com.dre.brewery.MCBarrel;
import com.dre.brewery.P; import com.dre.brewery.P;
import com.dre.brewery.integration.LogBlockBarrel; import com.dre.brewery.integration.LogBlockBarrel;
import com.dre.brewery.lore.Base91DecoderStream;
import com.dre.brewery.lore.Base91EncoderStream;
import com.dre.brewery.lore.LoreLoadStream;
import com.dre.brewery.lore.LoreSaveStream;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@@ -38,9 +34,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@@ -209,25 +202,13 @@ public class InventoryListener implements Listener {
for (int slot = 0; slot < 3; slot++) { for (int slot = 0; slot < 3; slot++) {
item = inv.getItem(slot); item = inv.getItem(slot);
if (item != null) { if (item != null) {
contents[slot] = Brew.get(item); if (item.getType() == Material.POTION) {
} if (item.hasItemMeta()) {
} Brew pot = Brew.get(item);
return contents; if (pot != null && (!distill || pot.canDistill())) { // need at least one distillable potion.
} return true;
}
private byte hasCustom(BrewerInventory brewer) { }
ItemStack item = brewer.getItem(3); // ingredient
boolean glowstone = (item != null && Material.GLOWSTONE_DUST == item.getType()); // need dust in the top slot.
byte customFound = 0;
for (Brew brew : getDistillContents(brewer)) {
if (brew != null) {
if (!glowstone) {
return 1;
}
if (brew.canDistill()) {
return 2;
} else {
customFound = 1;
} }
} }
} }
@@ -249,14 +230,24 @@ public class InventoryListener implements Listener {
private boolean runDistill(BrewerInventory inv) { private boolean runDistill(BrewerInventory inv) {
boolean custom = false; boolean custom = false;
Brew[] contents = getDistillContents(inv); Boolean[] contents = new Boolean[3];
for (int slot = 0; slot < 3; slot++) { while (slot < 3) {
if (contents[slot] == null) continue; item = inv.getItem(slot);
if (contents[slot].canDistill()) { contents[slot] = false;
// is further distillable if (item != null) {
custom = true; if (item.getType() == Material.POTION) {
} else { if (item.hasItemMeta()) {
contents[slot] = null; Brew brew = Brew.get(item);
if (brew != null) {
// has custom potion in "slot"
if (brew.canDistill()) {
// is further distillable
contents[slot] = true;
custom = true;
}
}
}
}
} }
} }
if (custom) { if (custom) {
@@ -305,14 +296,16 @@ public class InventoryListener implements Listener {
item.setItemMeta(potion); item.setItemMeta(potion);
} }
} }
brew.touch(); P.p.log(brew.toString());
//P.p.log(potion.getLore().get(0));
//brew.touch();
try { /*try {
DataInputStream in = new DataInputStream(new Base91DecoderStream(new LoreLoadStream(potion))); DataInputStream in = new DataInputStream(new Base91DecoderStream(new LoreLoadStream(potion)));
brew.testLoad(in); brew.testLoad(in);
/*if (in.readByte() == 27 && in.skip(48) > 0) { *//*if (in.readByte() == 27 && in.skip(48) > 0) {
in.mark(100); in.mark(100);
if (in.readUTF().equals("TESTHalloª∆Ω") && in.readInt() == 34834 && in.skip(4) > 0 && in.readLong() == Long.MAX_VALUE) { if (in.readUTF().equals("TESTHalloª∆Ω") && in.readInt() == 34834 && in.skip(4) > 0 && in.readLong() == Long.MAX_VALUE) {
in.reset(); in.reset();
@@ -326,7 +319,7 @@ public class InventoryListener implements Listener {
} }
} else { } else {
P.p.log("false1"); P.p.log("false1");
}*/ }*//*
in.close(); in.close();
} catch (IllegalArgumentException argExc) { } catch (IllegalArgumentException argExc) {
@@ -339,7 +332,7 @@ public class InventoryListener implements Listener {
brew.testStore(out); brew.testStore(out);
/*out.writeByte(27); *//*out.writeByte(27);
out.writeLong(1111); //skip out.writeLong(1111); //skip
out.writeLong(1111); //skip out.writeLong(1111); //skip
out.writeLong(1111); //skip out.writeLong(1111); //skip
@@ -349,16 +342,16 @@ public class InventoryListener implements Listener {
out.writeUTF("TESTHalloª∆Ω"); out.writeUTF("TESTHalloª∆Ω");
out.writeInt(34834); out.writeInt(34834);
out.writeInt(6436); //skip out.writeInt(6436); //skip
out.writeLong(Long.MAX_VALUE);*/ out.writeLong(Long.MAX_VALUE);*//*
out.close(); out.close();
/*StringBuilder b = new StringBuilder(); *//*StringBuilder b = new StringBuilder();
for (char c : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$%&()*+,-./:;<=>?@[]^_`{|}~\"".toCharArray()) { for (char c : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$%&()*+,-./:;<=>?@[]^_`{|}~\"".toCharArray()) {
b.append('§').append(c); b.append('§').append(c);
} }
List<String> lore = potion.getLore(); List<String> lore = potion.getLore();
lore.add(b.toString()); lore.add(b.toString());
potion.setLore(lore);*/ potion.setLore(lore);*//*
item.setItemMeta(potion); item.setItemMeta(potion);
} catch (IOException h) { } catch (IOException h) {
@@ -367,7 +360,7 @@ public class InventoryListener implements Listener {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }*/
} }
} }
} }
@@ -257,9 +257,9 @@ public class PlayerListener implements Listener {
Brew brew = Brew.get(item); Brew brew = Brew.get(item);
if (brew != null) { if (brew != null) {
BPlayer.drink(brew, player); BPlayer.drink(brew, player);
if (player.getGameMode() != GameMode.CREATIVE) { /*if (player.getGameMode() != org.bukkit.GameMode.CREATIVE) {
brew.remove(item); brew.remove(item);
} }*/
if (P.use1_9) { if (P.use1_9) {
if (player.getGameMode() != GameMode.CREATIVE) { if (player.getGameMode() != GameMode.CREATIVE) {
// replace the potion with an empty potion to avoid effects // replace the potion with an empty potion to avoid effects