mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 07:49:03 +00:00
Merge remote-tracking branch 'refs/remotes/origin/WIP-Brewingchanges'
Conflicts: config.yml src/com/dre/brewery/BPlayer.java src/com/dre/brewery/listeners/CommandListener.java
This commit is contained in:
@@ -15,14 +15,13 @@ import com.dre.brewery.BIngredients;
|
||||
public class BCauldron {
|
||||
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<BCauldron>();
|
||||
|
||||
private BIngredients ingredients;
|
||||
private BIngredients ingredients = new BIngredients();
|
||||
private Block block;
|
||||
private int state;
|
||||
private int state = 1;
|
||||
private boolean someRemoved = false;
|
||||
|
||||
public BCauldron(Block block, Material ingredient) {
|
||||
this.block = block;
|
||||
this.state = 1;
|
||||
this.ingredients = new BIngredients();
|
||||
add(ingredient);
|
||||
bcauldrons.add(this);
|
||||
}
|
||||
@@ -41,11 +40,19 @@ public class BCauldron {
|
||||
|| block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||
// add a minute to cooking time
|
||||
state++;
|
||||
if (someRemoved) {
|
||||
ingredients = ingredients.clone();
|
||||
someRemoved = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add an ingredient to the cauldron
|
||||
public void add(Material ingredient) {
|
||||
if (someRemoved) {
|
||||
ingredients = ingredients.clone();
|
||||
someRemoved = false;
|
||||
}
|
||||
ingredients.add(ingredient);
|
||||
block.getWorld().playEffect(block.getLocation(), Effect.EXTINGUISH, 0);
|
||||
if (state > 1) {
|
||||
@@ -98,6 +105,8 @@ public class BCauldron {
|
||||
|
||||
if (block.getData() == 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
} else {
|
||||
bcauldron.someRemoved = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -154,7 +163,7 @@ public class BCauldron {
|
||||
if (cauldron.state != 1) {
|
||||
config.set(prefix + ".state", cauldron.state);
|
||||
}
|
||||
cauldron.ingredients.save(config.createSection(prefix + ".ingredients"));
|
||||
config.set(prefix + ".ingredients", cauldron.ingredients.serializeIngredients());
|
||||
id++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,29 +17,25 @@ public class BIngredients {
|
||||
public static ArrayList<Material> possibleIngredients = new ArrayList<Material>();
|
||||
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
|
||||
public static Map<Material, String> cookedNames = new HashMap<Material, String>();
|
||||
private static int lastId = 0;
|
||||
|
||||
private int id;
|
||||
private Map<Material, Integer> ingredients = new HashMap<Material, Integer>();
|
||||
private int cookedTime;
|
||||
|
||||
// Represents ingredients in Cauldron, Brew
|
||||
// Init a new BIngredients
|
||||
public BIngredients() {
|
||||
this.id = lastId;
|
||||
lastId++;
|
||||
}
|
||||
|
||||
// Load from File
|
||||
public BIngredients(Map<Material, Integer> ingredients, int cookedTime) {
|
||||
this.ingredients = ingredients;
|
||||
this.cookedTime = cookedTime;
|
||||
}
|
||||
|
||||
//returns the recipe with the given name
|
||||
public static BRecipe getRecipeByName(String name) {
|
||||
for (BRecipe recipe : recipes) {
|
||||
if (recipe.getName(5).equalsIgnoreCase(name)) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
this.id = lastId;
|
||||
lastId++;
|
||||
}
|
||||
|
||||
// Add an ingredient to this
|
||||
@@ -68,8 +64,8 @@ public class BIngredients {
|
||||
if (cookRecipe != null) {
|
||||
// Potion is best with cooking only
|
||||
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
|
||||
P.p.log("cooked potion has Quality: " + quality);
|
||||
Brew brew = new Brew(uid, quality, cookRecipe, clone());
|
||||
P.p.debugLog("cooked potion has Quality: " + quality);
|
||||
Brew brew = new Brew(uid, quality, cookRecipe, this);
|
||||
Brew.addOrReplaceEffects(potionMeta, brew.getEffects());
|
||||
|
||||
cookedName = cookRecipe.getName(quality);
|
||||
@@ -77,7 +73,7 @@ public class BIngredients {
|
||||
|
||||
} else {
|
||||
// new base potion
|
||||
new Brew(uid, clone());
|
||||
new Brew(uid, this);
|
||||
|
||||
if (state <= 1) {
|
||||
cookedName = "Schlammiger Sud";
|
||||
@@ -123,7 +119,7 @@ public class BIngredients {
|
||||
|
||||
// best recipe for current state of potion, STILL not always returns the
|
||||
// correct one...
|
||||
public BRecipe getBestRecipe(byte wood, float time, boolean distilled) {
|
||||
public BRecipe getBestRecipe(float wood, float time, boolean distilled) {
|
||||
float quality = 0;
|
||||
int ingredientQuality = 0;
|
||||
int cookingQuality = 0;
|
||||
@@ -134,13 +130,13 @@ public class BIngredients {
|
||||
ingredientQuality = getIngredientQuality(recipe);
|
||||
cookingQuality = getCookingQuality(recipe, distilled);
|
||||
|
||||
if (ingredientQuality > -1) {
|
||||
if (recipe.needsToAge()) {
|
||||
if (ingredientQuality > -1 && cookingQuality > -1) {
|
||||
if (recipe.needsToAge() || time > 0.5) {
|
||||
// needs riping in barrel
|
||||
ageQuality = getAgeQuality(recipe, time);
|
||||
woodQuality = getWoodQuality(recipe, wood);
|
||||
P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) +
|
||||
" age Quality: " + getAgeQuality(recipe, time) + " for " + recipe.getName(5));
|
||||
P.p.debugLog("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality +
|
||||
" Wood Quality: " + woodQuality + " age Quality: " + ageQuality + " for " + recipe.getName(5));
|
||||
|
||||
// is this recipe better than the previous best?
|
||||
if ((((float) ingredientQuality + cookingQuality + woodQuality + ageQuality) / 4) > quality) {
|
||||
@@ -148,7 +144,7 @@ public class BIngredients {
|
||||
bestRecipe = recipe;
|
||||
}
|
||||
} else {
|
||||
P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " for " + recipe.getName(5));
|
||||
P.p.debugLog("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " for " + recipe.getName(5));
|
||||
// calculate quality without age and barrel
|
||||
if ((((float) ingredientQuality + cookingQuality) / 2) > quality) {
|
||||
quality = ((float) ingredientQuality + cookingQuality) / 2;
|
||||
@@ -158,7 +154,7 @@ public class BIngredients {
|
||||
}
|
||||
}
|
||||
if (bestRecipe != null) {
|
||||
P.p.log("best recipe: " + bestRecipe.getName(5) + " has Quality= " + quality);
|
||||
P.p.debugLog("best recipe: " + bestRecipe.getName(5) + " has Quality= " + quality);
|
||||
}
|
||||
return bestRecipe;
|
||||
}
|
||||
@@ -166,7 +162,7 @@ public class BIngredients {
|
||||
// returns recipe that is cooking only and matches the ingredients and
|
||||
// cooking time
|
||||
public BRecipe getCookRecipe() {
|
||||
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, false);
|
||||
BRecipe bestRecipe = getBestRecipe(0, 0, false);
|
||||
|
||||
// Check if best recipe is cooking only
|
||||
if (bestRecipe != null) {
|
||||
@@ -179,8 +175,8 @@ public class BIngredients {
|
||||
|
||||
// returns the currently best matching recipe for distilling for the
|
||||
// ingredients and cooking time
|
||||
public BRecipe getdistillRecipe() {
|
||||
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, true);
|
||||
public BRecipe getdistillRecipe(float wood, float time) {
|
||||
BRecipe bestRecipe = getBestRecipe(wood, time, true);
|
||||
|
||||
// Check if best recipe needs to be destilled
|
||||
if (bestRecipe != null) {
|
||||
@@ -193,7 +189,7 @@ public class BIngredients {
|
||||
|
||||
// returns currently best matching recipe for ingredients, cooking- and
|
||||
// ageingtime
|
||||
public BRecipe getAgeRecipe(byte wood, float time, boolean distilled) {
|
||||
public BRecipe getAgeRecipe(float wood, float time, boolean distilled) {
|
||||
BRecipe bestRecipe = getBestRecipe(wood, time, distilled);
|
||||
|
||||
if (bestRecipe != null) {
|
||||
@@ -226,7 +222,7 @@ public class BIngredients {
|
||||
badStuff++;
|
||||
if (badStuff < ingredients.size()) {
|
||||
// when there are other ingredients
|
||||
quality -= count * 2;
|
||||
quality -= count * (recipe.getDifficulty() / 2);
|
||||
continue;
|
||||
} else {
|
||||
// ingredients dont fit at all
|
||||
@@ -234,7 +230,7 @@ public class BIngredients {
|
||||
}
|
||||
}
|
||||
// calculate the quality
|
||||
quality -= (((float) Math.abs(count - recipe.amountOf(ingredient)) / recipe.allowedCountDiff(recipe.amountOf(ingredient))) * 10.0);
|
||||
quality -= ((float) Math.abs(count - recipe.amountOf(ingredient)) / recipe.allowedCountDiff(recipe.amountOf(ingredient))) * 10.0;
|
||||
}
|
||||
if (quality >= 0) {
|
||||
return Math.round(quality);
|
||||
@@ -245,14 +241,17 @@ public class BIngredients {
|
||||
// returns the quality regarding the cooking-time conditioning given Recipe
|
||||
public int getCookingQuality(BRecipe recipe, boolean distilled) {
|
||||
if (!recipe.needsDistilling() == distilled) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
int quality = 10 - (int) Math.round(((float) Math.abs(cookedTime - recipe.getCookingTime()) / recipe.allowedTimeDiff(recipe.getCookingTime())) * 10.0);
|
||||
|
||||
if (quality > 0) {
|
||||
if (quality >= 0) {
|
||||
if (cookedTime <= 1) {
|
||||
return 0;
|
||||
}
|
||||
return quality;
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// returns pseudo quality of distilling. 0 if doesnt match the need of the recipes distilling
|
||||
@@ -264,12 +263,12 @@ public class BIngredients {
|
||||
}
|
||||
|
||||
// returns the quality regarding the barrel wood conditioning given Recipe
|
||||
public int getWoodQuality(BRecipe recipe, byte wood) {
|
||||
if (recipe.getWood() == 0x8) {
|
||||
public int getWoodQuality(BRecipe recipe, float wood) {
|
||||
if (recipe.getWood() == 0) {
|
||||
// type of wood doesnt matter
|
||||
return 10;
|
||||
}
|
||||
int quality = 10 - (int) Math.round(recipe.getWoodDiff(wood) * recipe.getDifficulty());
|
||||
int quality = 10 - Math.round(recipe.getWoodDiff(wood) * recipe.getDifficulty());
|
||||
|
||||
if (quality > 0) {
|
||||
return quality;
|
||||
@@ -295,22 +294,23 @@ public class BIngredients {
|
||||
return copy;
|
||||
}
|
||||
|
||||
// saves data into ingredient section of Brew/BCauldron
|
||||
public void save(ConfigurationSection config) {
|
||||
// saves data into main Ingredient section. Returns the save id
|
||||
public int save(ConfigurationSection config) {
|
||||
String path = "Ingredients." + id;
|
||||
if (cookedTime != 0) {
|
||||
config.set("cookedTime", cookedTime);
|
||||
config.set(path + ".cookedTime", cookedTime);
|
||||
}
|
||||
config.set(path + ".mats", serializeIngredients());
|
||||
return id;
|
||||
}
|
||||
|
||||
// convert the ingredient Material to id
|
||||
// convert the ingredient Material to id
|
||||
public Map<Integer, Integer> serializeIngredients() {
|
||||
Map<Integer, Integer> mats = new HashMap<Integer, Integer>();
|
||||
for (Material mat : ingredients.keySet()) {
|
||||
mats.put(mat.getId(), ingredients.get(mat));
|
||||
}
|
||||
// list all Material ids with their amount
|
||||
ConfigurationSection matSection = config.createSection("mats");
|
||||
for (int id : mats.keySet()) {
|
||||
matSection.set("" + id, mats.get(id));
|
||||
}
|
||||
return mats;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,12 +19,13 @@ import com.dre.brewery.Brew;
|
||||
|
||||
public class BPlayer {
|
||||
public static Map<String, BPlayer> players = new HashMap<String, BPlayer>();// Players name and BPlayer
|
||||
public static Map<Material, Integer> drainItems = new HashMap<Material, Integer>();// DrainItem Material and Strength
|
||||
private static Map<Player, Integer> pTasks = new HashMap<Player, Integer>();// Player and count
|
||||
private static int taskId;
|
||||
|
||||
// Settings
|
||||
private static int taskId;
|
||||
public static Map<Material, Integer> drainItems = new HashMap<Material, Integer>();// DrainItem Material and Strength
|
||||
public static int pukeItemId;
|
||||
public static int hangoverTime;
|
||||
public static boolean overdrinkKick;
|
||||
public static boolean enableHome;
|
||||
public static boolean enableLoginDisallow;
|
||||
@@ -72,8 +73,9 @@ public class BPlayer {
|
||||
return org.bukkit.Bukkit.getPlayer(getPlayerName());
|
||||
}*/
|
||||
|
||||
// returns the Player if online
|
||||
public static Player getPlayer(String name) {
|
||||
return org.bukkit.Bukkit.getPlayer(name);
|
||||
return org.bukkit.Bukkit.getPlayerExact(name);
|
||||
}
|
||||
|
||||
// returns true if drinking was successful
|
||||
@@ -92,19 +94,21 @@ public class BPlayer {
|
||||
players.put(player.getName(), bPlayer);
|
||||
}
|
||||
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) {
|
||||
|
||||
addBrewEffects(brew, player);
|
||||
if (brew.getQuality() < 5) {
|
||||
addQualityEffects(brew.getQuality(), brewAlc, player);
|
||||
}
|
||||
addQualityEffects(brew.getQuality(), brewAlc, player);
|
||||
|
||||
} else {
|
||||
bPlayer.drinkCap(player);
|
||||
}
|
||||
P.p.msg(player, P.p.languageReader.get("Player_DrunkInfo", "" + bPlayer.getDrunkeness(), "" + bPlayer.getQuality()));
|
||||
P.p.msg(player, "Du bist nun " + bPlayer.drunkeness + "% betrunken, mit einer Qualität von " + bPlayer.getQuality());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -140,7 +144,9 @@ public class BPlayer {
|
||||
|
||||
// drain the drunkeness by amount, returns true when player has to be removed
|
||||
public boolean drain(String name, int amount) {
|
||||
quality -= getQuality() * amount;
|
||||
if (drunkeness > 0) {
|
||||
quality -= getQuality() * amount;
|
||||
}
|
||||
drunkeness -= amount;
|
||||
if (drunkeness > 0) {
|
||||
if (offlineDrunk == 0) {
|
||||
@@ -148,8 +154,16 @@ public class BPlayer {
|
||||
offlineDrunk = drunkeness;
|
||||
}
|
||||
}
|
||||
} else if (drunkeness <= (-1) * offlineDrunk) {
|
||||
return true;
|
||||
} else {
|
||||
if (offlineDrunk == 0) {
|
||||
return true;
|
||||
}
|
||||
quality = getQuality();
|
||||
if (drunkeness <= -offlineDrunk) {
|
||||
if (drunkeness <= -hangoverTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -195,6 +209,9 @@ public class BPlayer {
|
||||
passedOut = true;
|
||||
}
|
||||
|
||||
|
||||
// #### Login ####
|
||||
|
||||
// can the player login or is he too drunk
|
||||
public int canJoin() {
|
||||
if (drunkeness <= 70) {
|
||||
@@ -267,6 +284,10 @@ public class BPlayer {
|
||||
passedOut = false;
|
||||
}
|
||||
|
||||
public void disconnecting() {
|
||||
offlineDrunk = drunkeness;
|
||||
}
|
||||
|
||||
public void goHome(final Player player) {
|
||||
if (homeType != null) {
|
||||
Location home = null;
|
||||
@@ -289,13 +310,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);
|
||||
PotionEffectType.HUNGER.createEffect(duration, amplifier).apply(player);
|
||||
}
|
||||
// #### Puking ####
|
||||
|
||||
// Chance that players puke on big drunkeness
|
||||
// runs every 6 sec, average chance is 10%, so should puke about every 60 sec
|
||||
@@ -357,6 +373,9 @@ public class BPlayer {
|
||||
item.setPickupDelay(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
// #### Effects ####
|
||||
|
||||
public void drunkEffects(Player player) {
|
||||
int duration = 10 - getQuality();
|
||||
duration += drunkeness / 2;
|
||||
@@ -371,17 +390,30 @@ public class BPlayer {
|
||||
|
||||
public static void addQualityEffects(int quality, int brewAlc, Player player) {
|
||||
int duration = 7 - quality;
|
||||
duration *= 250;
|
||||
PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player);
|
||||
|
||||
if (brewAlc > 15) {
|
||||
duration = 10 - quality;
|
||||
duration += brewAlc;
|
||||
duration *= 40;
|
||||
if (quality == 0) {
|
||||
duration *= 500;
|
||||
} else if (quality <= 5) {
|
||||
duration *= 250;
|
||||
} else {
|
||||
duration = 200;
|
||||
duration = 100;
|
||||
if (brewAlc <= 10) {
|
||||
duration = 0;
|
||||
}
|
||||
}
|
||||
if (duration > 0) {
|
||||
PotionEffectType.POISON.createEffect(duration, 0).apply(player);
|
||||
}
|
||||
|
||||
if (brewAlc > 10) {
|
||||
if (quality <= 5) {
|
||||
duration = 10 - quality;
|
||||
duration += brewAlc;
|
||||
duration *= 60;
|
||||
} else {
|
||||
duration = 120;
|
||||
}
|
||||
PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player);
|
||||
}
|
||||
PotionEffectType.POISON.createEffect(duration, 0).apply(player);
|
||||
}
|
||||
|
||||
public static void addBrewEffects(Brew brew, Player player) {
|
||||
@@ -394,7 +426,8 @@ public class BPlayer {
|
||||
if (type.isInstant()) {
|
||||
type.createEffect(0, duration - 1).apply(player);
|
||||
} else {
|
||||
int amplifier = brew.getQuality() / 3;
|
||||
int amplifier = brew.getQuality() / 4;
|
||||
duration /= type.getDurationModifier();
|
||||
type.createEffect(duration * 20, amplifier).apply(player);
|
||||
}
|
||||
}
|
||||
@@ -402,9 +435,21 @@ 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() {
|
||||
for (String name : players.keySet()) {
|
||||
BPlayer bplayer = players.get(name);
|
||||
for (Map.Entry<String, BPlayer> entry : players.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
BPlayer bplayer = entry.getValue();
|
||||
|
||||
if (bplayer.drunkeness > 30) {
|
||||
if (bplayer.offlineDrunk == 0) {
|
||||
@@ -427,7 +472,8 @@ public class BPlayer {
|
||||
public static void onUpdate() {
|
||||
if (!players.isEmpty()) {
|
||||
int soberPerMin = 2;
|
||||
for (Iterator<Map.Entry<String, BPlayer>> iter = players.entrySet().iterator(); iter.hasNext();) {
|
||||
Iterator<Map.Entry<String, BPlayer>> iter = players.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, BPlayer> entry = iter.next();
|
||||
String name = entry.getKey();
|
||||
BPlayer bplayer = entry.getValue();
|
||||
@@ -457,7 +503,9 @@ public class BPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
// getter
|
||||
|
||||
// #### getter/setter ####
|
||||
|
||||
public int getDrunkeness() {
|
||||
return drunkeness;
|
||||
}
|
||||
@@ -480,16 +528,18 @@ public class BPlayer {
|
||||
P.p.errorLog("drunkeness should not be 0!");
|
||||
return quality;
|
||||
}
|
||||
if (drunkeness < 0) {
|
||||
return quality;
|
||||
}
|
||||
return Math.round(quality / drunkeness);
|
||||
}
|
||||
|
||||
// opposite of quality
|
||||
public int getHangoverQuality() {
|
||||
return -getQuality() + 10;
|
||||
}
|
||||
|
||||
public int getHangoverProgress() {
|
||||
return offlineDrunk + drunkeness;
|
||||
if (drunkeness < 0) {
|
||||
return quality + 11;
|
||||
}
|
||||
return -getQuality() + 11;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class BRecipe {
|
||||
private Map<Material, Integer> ingredients = new HashMap<Material, Integer>();// material and amount
|
||||
private int cookingTime;// time to cook in cauldron
|
||||
private int distillruns;// runs through the brewer
|
||||
private int 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 String color;// color of the destilled/finished potion
|
||||
private int difficulty;// difficulty to brew the potion, how exact the instruction has to be followed
|
||||
@@ -21,22 +21,39 @@ public class BRecipe {
|
||||
private Map<String, Integer> effects = new HashMap<String, Integer>(); // Special Effect, Duration
|
||||
|
||||
public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
|
||||
String[] name = configSectionRecipes.getString(recipeId + ".name").split("/");
|
||||
if (name.length > 2) {
|
||||
this.name = name;
|
||||
String nameList = configSectionRecipes.getString(recipeId + ".name");
|
||||
if (nameList != null) {
|
||||
String[] name = nameList.split("/");
|
||||
if (name.length > 2) {
|
||||
this.name = name;
|
||||
} else {
|
||||
this.name = new String[1];
|
||||
this.name[0] = name[0];
|
||||
}
|
||||
} else {
|
||||
this.name = new String[1];
|
||||
this.name[0] = name[0];
|
||||
return;
|
||||
}
|
||||
List<String> ingredientsList = configSectionRecipes.getStringList(recipeId + ".ingredients");
|
||||
for (String item : ingredientsList) {
|
||||
String[] ingredParts = item.split("/");
|
||||
ingredParts[0] = ingredParts[0].toUpperCase();
|
||||
this.ingredients.put(Material.getMaterial(ingredParts[0]), P.p.parseInt(ingredParts[1]));
|
||||
if (ingredientsList != null) {
|
||||
for (String item : ingredientsList) {
|
||||
String[] ingredParts = item.split("/");
|
||||
if (ingredParts.length == 2) {
|
||||
Material mat = Material.matchMaterial(ingredParts[0]);
|
||||
if (mat != null) {
|
||||
this.ingredients.put(Material.matchMaterial(ingredParts[0]), P.p.parseInt(ingredParts[1]));
|
||||
} else {
|
||||
P.p.errorLog("Unbekanntes Material: " + ingredParts[0]);
|
||||
this.ingredients = null;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime");
|
||||
this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns");
|
||||
this.wood = configSectionRecipes.getInt(recipeId + ".wood");
|
||||
this.wood = (byte) configSectionRecipes.getInt(recipeId + ".wood");
|
||||
this.age = configSectionRecipes.getInt(recipeId + ".age");
|
||||
this.color = configSectionRecipes.getString(recipeId + ".color");
|
||||
this.difficulty = configSectionRecipes.getInt(recipeId + ".difficulty");
|
||||
@@ -47,7 +64,11 @@ public class BRecipe {
|
||||
for (String effectString : effectStringList) {
|
||||
String[] effectSplit = effectString.split("/");
|
||||
String effect = effectSplit[0];
|
||||
if (effect.equalsIgnoreCase("WEAKNESS") || effect.equalsIgnoreCase("INCREASE_DAMAGE") || effect.equalsIgnoreCase("SLOW") || effect.equalsIgnoreCase("SPEED") || effect.equalsIgnoreCase("REGERATION")) {
|
||||
if (effect.equalsIgnoreCase("WEAKNESS") ||
|
||||
effect.equalsIgnoreCase("INCREASE_DAMAGE") ||
|
||||
effect.equalsIgnoreCase("SLOW") ||
|
||||
effect.equalsIgnoreCase("SPEED") ||
|
||||
effect.equalsIgnoreCase("REGENERATION")) {
|
||||
// hide these effects as they put crap into lore
|
||||
effect = effect + "X";
|
||||
}
|
||||
@@ -62,6 +83,9 @@ public class BRecipe {
|
||||
|
||||
// allowed deviation to the recipes count of ingredients at the given difficulty
|
||||
public int allowedCountDiff(int count) {
|
||||
if (count < 8) {
|
||||
count = 8;
|
||||
}
|
||||
int allowedCountDiff = Math.round((float) ((11.0 - difficulty) * (count / 10.0)));
|
||||
|
||||
if (allowedCountDiff == 0) {
|
||||
@@ -72,11 +96,11 @@ public class BRecipe {
|
||||
|
||||
// allowed deviation to the recipes cooking-time at the given difficulty
|
||||
public int allowedTimeDiff(int time) {
|
||||
if (time < 8) {
|
||||
time = 8;
|
||||
}
|
||||
int allowedTimeDiff = Math.round((float) ((11.0 - difficulty) * (time / 10.0)));
|
||||
|
||||
while (allowedTimeDiff >= time) {
|
||||
allowedTimeDiff -= 1;
|
||||
}
|
||||
if (allowedTimeDiff == 0) {
|
||||
return 1;
|
||||
}
|
||||
@@ -84,18 +108,8 @@ public class BRecipe {
|
||||
}
|
||||
|
||||
// difference between given and recipe-wanted woodtype
|
||||
public float getWoodDiff(byte wood) {
|
||||
int woodType = 0;
|
||||
if (wood == 0x0) {
|
||||
woodType = 2;
|
||||
} else if (wood == 0x1) {
|
||||
woodType = 4;
|
||||
} else if (wood == 0x2) {
|
||||
woodType = 1;
|
||||
} else if (wood == 0x3) {
|
||||
woodType = 3;
|
||||
}
|
||||
return Math.abs(woodType - wood);
|
||||
public float getWoodDiff(float wood) {
|
||||
return Math.abs(wood - this.wood);
|
||||
}
|
||||
|
||||
public boolean isCookingOnly() {
|
||||
@@ -132,6 +146,11 @@ public class BRecipe {
|
||||
return false;
|
||||
}
|
||||
|
||||
// true if name and ingredients are correct
|
||||
public boolean isValid() {
|
||||
return (name != null && ingredients != null && !ingredients.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
// Getter
|
||||
|
||||
@@ -167,21 +186,15 @@ public class BRecipe {
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color.toUpperCase();
|
||||
if (color != null) {
|
||||
return color.toUpperCase();
|
||||
}
|
||||
return "BLUE";
|
||||
}
|
||||
|
||||
// get the woodtype in blockData-byte
|
||||
// get the woodtype
|
||||
public byte getWood() {
|
||||
if (wood == 1) {
|
||||
return 0x2;
|
||||
} else if (wood == 2) {
|
||||
return 0x0;
|
||||
} else if (wood == 3) {
|
||||
return 0x3;
|
||||
} else if (wood == 4) {
|
||||
return 0x1;
|
||||
}
|
||||
return 0x8;
|
||||
return wood;
|
||||
}
|
||||
|
||||
public float getAge() {
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class Barrel {
|
||||
@@ -75,23 +76,25 @@ public class Barrel {
|
||||
inventory = org.bukkit.Bukkit.createInventory(null, 9, "Fass");
|
||||
}
|
||||
} else {
|
||||
// if nobody has the inventory opened
|
||||
if (inventory.getViewers().isEmpty()) {
|
||||
// if inventory contains potions
|
||||
if (inventory.contains(373)) {
|
||||
long loadTime = System.nanoTime();
|
||||
for (ItemStack item : inventory.getContents()) {
|
||||
if (item != null) {
|
||||
if (item.getTypeId() == 373) {
|
||||
if (item.hasItemMeta()) {
|
||||
Brew.age(item, time, getWood());
|
||||
if (time > 0) {
|
||||
// if nobody has the inventory opened
|
||||
if (inventory.getViewers().isEmpty()) {
|
||||
// if inventory contains potions
|
||||
if (inventory.contains(373)) {
|
||||
byte wood = getWood();
|
||||
long loadTime = System.nanoTime();
|
||||
for (ItemStack item : inventory.getContents()) {
|
||||
if (item != null) {
|
||||
Brew brew = Brew.get(item);
|
||||
if (brew != null) {
|
||||
brew.age(item, time, wood);
|
||||
}
|
||||
}
|
||||
}
|
||||
loadTime = System.nanoTime() - loadTime;
|
||||
float ftime = (float) (loadTime / 1000000.0);
|
||||
P.p.debugLog("opening Barrel with potions (" + ftime + "ms)");
|
||||
}
|
||||
loadTime = System.nanoTime() - loadTime;
|
||||
float ftime = (float) (loadTime / 1000000.0);
|
||||
P.p.log("opening Barrel with potions (" + ftime + "ms)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,9 +132,15 @@ public class Barrel {
|
||||
ItemStack[] items = inventory.getContents();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
if (item.getTypeId() == 373) {
|
||||
Brew brew = Brew.get(item);
|
||||
if (brew != null) {
|
||||
// Brew before throwing
|
||||
Brew.age(item, time, getWood());
|
||||
brew.age(item, time, getWood());
|
||||
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||
if (Brew.hasColorLore(meta)) {
|
||||
brew.convertLore(meta, false);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
// "broken" is the block that destroyed, throw them there!
|
||||
if (broken != null) {
|
||||
@@ -275,19 +284,28 @@ public class Barrel {
|
||||
wood = this.spigot.getRelative(0, 0, -1);
|
||||
}
|
||||
if (wood.getTypeId() == 5) {
|
||||
return wood.getData();
|
||||
byte data = wood.getData();
|
||||
if (data == 0x0) {
|
||||
return 2;
|
||||
} else if (data == 0x1) {
|
||||
return 4;
|
||||
} else if (data == 0x2) {
|
||||
return 1;
|
||||
} else {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (wood.getTypeId() == 53) {
|
||||
return 0x0;
|
||||
return 2;
|
||||
}
|
||||
if (wood.getTypeId() == 134) {
|
||||
return 0x1;
|
||||
return 4;
|
||||
}
|
||||
if (wood.getTypeId() == 135) {
|
||||
return 0x2;
|
||||
return 1;
|
||||
}
|
||||
if (wood.getTypeId() == 136) {
|
||||
return 0x3;
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -357,7 +375,6 @@ public class Barrel {
|
||||
int x = startX;
|
||||
int y = 0;
|
||||
int z = startZ;
|
||||
// P.p.log("startX="+startX+" startZ="+startZ+" endX="+endX+" endZ="+endZ+" direction="+direction);
|
||||
while (y <= 1) {
|
||||
while (x <= endX) {
|
||||
while (z <= endZ) {
|
||||
@@ -423,12 +440,10 @@ public class Barrel {
|
||||
int x = startX;
|
||||
int y = 0;
|
||||
int z = startZ;
|
||||
// P.p.log("startX="+startX+" startZ="+startZ+" endX="+endX+" endZ="+endZ+" direction="+direction);
|
||||
while (y <= 2) {
|
||||
while (x <= endX) {
|
||||
while (z <= endZ) {
|
||||
typeId = spigot.getRelative(x, y, z).getTypeId();
|
||||
// spigot.getRelative(x,y,z).setTypeId(1);
|
||||
if (direction == 1 || direction == 2) {
|
||||
if (y == 1 && z == 0) {
|
||||
if (x == -2 || x == -3 || x == 2 || x == 3) {
|
||||
|
||||
+249
-117
@@ -22,13 +22,13 @@ public class Brew {
|
||||
public static Boolean colorInBarrels; // color the Lore while in Barrels
|
||||
public static Boolean colorInBrewer; // color the Lore while in Brewer
|
||||
|
||||
//public static Map<ItemStack, List<String>> oldLore = new HashMap<ItemStack, List<String>>();
|
||||
|
||||
private BIngredients ingredients;
|
||||
private int quality;
|
||||
private int distillRuns;
|
||||
private float ageTime;
|
||||
private float wood;
|
||||
private BRecipe currentRecipe;
|
||||
private boolean unlabeled;
|
||||
|
||||
public Brew(int uid, BIngredients ingredients) {
|
||||
this.ingredients = ingredients;
|
||||
@@ -44,13 +44,15 @@ public class Brew {
|
||||
}
|
||||
|
||||
// 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, float wood, String recipe, Boolean unlabeled) {
|
||||
potions.put(uid, this);
|
||||
this.ingredients = ingredients;
|
||||
this.quality = quality;
|
||||
this.distillRuns = distillRuns;
|
||||
this.ageTime = ageTime;
|
||||
this.currentRecipe = BIngredients.getRecipeByName(recipe);
|
||||
potions.put(uid, this);
|
||||
this.wood = wood;
|
||||
this.unlabeled = unlabeled;
|
||||
setRecipeFromString(recipe);
|
||||
}
|
||||
|
||||
// returns a Brew by its UID
|
||||
@@ -116,6 +118,37 @@ public class Brew {
|
||||
return uid;
|
||||
}
|
||||
|
||||
//returns the recipe with the given name, recalculates if not found
|
||||
public boolean setRecipeFromString(String name) {
|
||||
currentRecipe = null;
|
||||
if (name != null && !name.equals("")) {
|
||||
for (BRecipe recipe : BIngredients.recipes) {
|
||||
if (recipe.getName(5).equalsIgnoreCase(name)) {
|
||||
currentRecipe = recipe;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (quality > 0) {
|
||||
currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0);
|
||||
if (currentRecipe != null) {
|
||||
this.quality = calcQuality();
|
||||
P.p.log("Brew was made from Recipe: '" + name + "' which could not be found. '" + currentRecipe.getName(5) + "' used instead!");
|
||||
return true;
|
||||
} else {
|
||||
P.p.errorLog("Brew was made from Recipe: '" + name + "' which could not be found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean reloadRecipe() {
|
||||
if (currentRecipe != null) {
|
||||
return setRecipeFromString(currentRecipe.getName(5));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Copy a Brew with a new unique ID and return its item
|
||||
public ItemStack copy(ItemStack item) {
|
||||
@@ -133,36 +166,62 @@ public class Brew {
|
||||
Brew brew = new Brew(uid, quality, currentRecipe, ingredients);
|
||||
brew.distillRuns = distillRuns;
|
||||
brew.ageTime = ageTime;
|
||||
brew.unlabeled = unlabeled;
|
||||
return brew;
|
||||
}
|
||||
|
||||
// calculate alcohol from recipe
|
||||
public int calcAlcohol() {
|
||||
if (quality == 0) {
|
||||
// Give bad potions some alc
|
||||
int badAlc = 0;
|
||||
if (distillRuns > 1) {
|
||||
badAlc = distillRuns;
|
||||
}
|
||||
if (ageTime > 10) {
|
||||
badAlc += 5;
|
||||
} else if (ageTime > 2) {
|
||||
badAlc += 3;
|
||||
}
|
||||
if (currentRecipe != null) {
|
||||
return badAlc;
|
||||
} else {
|
||||
return badAlc / 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentRecipe != null) {
|
||||
int alc = currentRecipe.getAlcohol();
|
||||
alc *= ((float) quality / 10.0);
|
||||
if (currentRecipe.needsDistilling()) {
|
||||
// distillable Potions should have full alc after 6 distills
|
||||
float factor = 1.4F / (distillRuns + 1);
|
||||
factor += 0.8;
|
||||
alc /= factor;
|
||||
if (distillRuns == 0) {
|
||||
return 0;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
// calculating quality
|
||||
public int calcQuality(BRecipe recipe, byte wood, boolean distilled) {
|
||||
public int calcQuality() {
|
||||
// calculate quality from all of the factors
|
||||
float quality = (
|
||||
|
||||
ingredients.getIngredientQuality(recipe) +
|
||||
ingredients.getCookingQuality(recipe, distilled) +
|
||||
ingredients.getWoodQuality(recipe, wood) +
|
||||
ingredients.getAgeQuality(recipe, ageTime));
|
||||
|
||||
quality /= 4;
|
||||
float quality = ingredients.getIngredientQuality(currentRecipe) + ingredients.getCookingQuality(currentRecipe, distillRuns > 0);
|
||||
if (currentRecipe.needsToAge() || ageTime > 0.5) {
|
||||
quality += ingredients.getWoodQuality(currentRecipe, wood) + ingredients.getAgeQuality(currentRecipe, ageTime);
|
||||
quality /= 4;
|
||||
} else {
|
||||
quality /= 2;
|
||||
}
|
||||
return (int) Math.round(quality);
|
||||
}
|
||||
|
||||
@@ -171,24 +230,37 @@ public class Brew {
|
||||
}
|
||||
|
||||
public boolean canDistill() {
|
||||
if (distillRuns >= 6) {
|
||||
if (currentRecipe != null) {
|
||||
return currentRecipe.getDistillRuns() > distillRuns;
|
||||
} else if (distillRuns >= 6) {
|
||||
return false;
|
||||
} else {
|
||||
if (currentRecipe != null) {
|
||||
return currentRecipe.needsDistilling();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// return special effect
|
||||
public Map<String, Integer> getEffects() {
|
||||
if (currentRecipe != null) {
|
||||
if (currentRecipe != null && quality > 0) {
|
||||
return currentRecipe.getEffects();
|
||||
}
|
||||
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 ---------------
|
||||
|
||||
// distill all custom potions in the brewer
|
||||
@@ -196,103 +268,118 @@ public class Brew {
|
||||
int slot = 0;
|
||||
while (slot < 3) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
// distill custom potion in given slot
|
||||
public static void distillSlot(BrewerInventory inv, int slot) {
|
||||
ItemStack slotItem = inv.getItem(slot);
|
||||
PotionMeta potionMeta = (PotionMeta) slotItem.getItemMeta();
|
||||
Brew brew = get(potionMeta);
|
||||
BRecipe recipe = brew.ingredients.getdistillRecipe();
|
||||
|
||||
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
|
||||
distillRuns += 1;
|
||||
BRecipe recipe = ingredients.getdistillRecipe(wood, ageTime);
|
||||
if (recipe != null) {
|
||||
// distillRuns will have an effect on the amount of alcohol, not the quality
|
||||
brew.quality = brew.calcQuality(recipe, (byte) 0, true);
|
||||
brew.distillRuns += 1;
|
||||
brew.currentRecipe = recipe;
|
||||
currentRecipe = recipe;
|
||||
quality = calcQuality();
|
||||
|
||||
// Distill Lore
|
||||
if (colorInBrewer != hasColorLore(potionMeta)) {
|
||||
brew.convertLore(potionMeta, colorInBrewer);
|
||||
} 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));
|
||||
}
|
||||
addOrReplaceEffects(potionMeta, getEffects());
|
||||
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
|
||||
slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
|
||||
} else {
|
||||
quality = 0;
|
||||
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);
|
||||
}
|
||||
|
||||
// Ageing Section ------------------
|
||||
|
||||
public static void age(ItemStack item, float time, byte wood) {
|
||||
public void age(ItemStack item, float time, byte woodType) {
|
||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
Brew brew = get(potionMeta);
|
||||
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)));
|
||||
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
|
||||
}
|
||||
}
|
||||
|
||||
// Lore
|
||||
if (colorInBarrels != hasColorLore(potionMeta)) {
|
||||
brew.convertLore(potionMeta, colorInBarrels);
|
||||
ageTime += time;
|
||||
|
||||
// if younger than half a day, it shouldnt get aged form
|
||||
if (ageTime > 0.5) {
|
||||
if (wood == 0) {
|
||||
wood = woodType;
|
||||
} else {
|
||||
if (brew.ageTime >= 1) {
|
||||
String prefix = P.p.color("&7");
|
||||
if (colorInBarrels) {
|
||||
prefix = getQualityColor(brew.ingredients.getAgeQuality(brew.currentRecipe, brew.ageTime));
|
||||
}
|
||||
brew.updateAgeLore(prefix, potionMeta);
|
||||
addOrReplaceEffects(potionMeta, brew.getEffects());
|
||||
if (wood != woodType) {
|
||||
woodShift(time, woodType);
|
||||
}
|
||||
}
|
||||
item.setItemMeta(potionMeta);
|
||||
BRecipe recipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0);
|
||||
if (recipe != null) {
|
||||
currentRecipe = recipe;
|
||||
quality = calcQuality();
|
||||
|
||||
addOrReplaceEffects(potionMeta, getEffects());
|
||||
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
|
||||
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
|
||||
} else {
|
||||
quality = 0;
|
||||
potionMeta.setDisplayName(P.p.color("&f" + "Verdorbenes Getränk"));
|
||||
item.setDurability(PotionColor.GREY.getColorId(canDistill()));
|
||||
}
|
||||
}
|
||||
|
||||
// Lore
|
||||
if (currentRecipe != null) {
|
||||
if (colorInBarrels != hasColorLore(potionMeta)) {
|
||||
convertLore(potionMeta, colorInBarrels);
|
||||
}
|
||||
}
|
||||
if (ageTime >= 1) {
|
||||
String prefix = P.p.color("&7");
|
||||
if (colorInBarrels && currentRecipe != null) {
|
||||
prefix = getQualityColor(ingredients.getAgeQuality(currentRecipe, ageTime));
|
||||
}
|
||||
updateAgeLore(prefix, potionMeta);
|
||||
}
|
||||
if (ageTime > 0.5) {
|
||||
if (colorInBarrels && !unlabeled && currentRecipe != null) {
|
||||
updateWoodLore(potionMeta);
|
||||
}
|
||||
}
|
||||
item.setItemMeta(potionMeta);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
// Slowly shift the wood of the Brew to the new Type
|
||||
public void woodShift(float time, byte to) {
|
||||
byte factor = 1;
|
||||
if (ageTime > 5) {
|
||||
factor = 2;
|
||||
} else if (ageTime > 10) {
|
||||
factor = 2;
|
||||
factor += Math.round(ageTime / 10);
|
||||
}
|
||||
if (wood > to) {
|
||||
wood -= time / factor;
|
||||
if (wood < to) {
|
||||
wood = to;
|
||||
}
|
||||
} else {
|
||||
wood += time / factor;
|
||||
if (wood > to) {
|
||||
wood = to;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,17 +390,13 @@ public class Brew {
|
||||
if (currentRecipe == null) {
|
||||
return;
|
||||
}
|
||||
if (meta == null) {
|
||||
P.p.log("has no meta");
|
||||
return;
|
||||
}
|
||||
meta.setLore(null);
|
||||
|
||||
// Ingredients
|
||||
int quality;
|
||||
String prefix = P.p.color("&7");
|
||||
String lore;
|
||||
if (toQuality) {
|
||||
|
||||
// Ingredients
|
||||
if (toQuality && !unlabeled) {
|
||||
quality = ingredients.getIngredientQuality(currentRecipe);
|
||||
prefix = getQualityColor(quality);
|
||||
lore = "Zutaten";
|
||||
@@ -321,7 +404,7 @@ public class Brew {
|
||||
}
|
||||
|
||||
// Cooking
|
||||
if (toQuality) {
|
||||
if (toQuality && !unlabeled) {
|
||||
if (distillRuns > 0 == currentRecipe.needsDistilling()) {
|
||||
quality = ingredients.getCookingQuality(currentRecipe, distillRuns > 0);
|
||||
prefix = getQualityColor(quality) + ingredients.getCookedTime() + " minute";
|
||||
@@ -350,26 +433,54 @@ public class Brew {
|
||||
}
|
||||
updateAgeLore(prefix, meta);
|
||||
}
|
||||
|
||||
// WoodType
|
||||
if (toQuality && !unlabeled) {
|
||||
if (ageTime > 0.5) {
|
||||
updateWoodLore(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sets the DistillLore. Prefix is the color to be used
|
||||
public void updateDistillLore(String prefix, PotionMeta meta) {
|
||||
if (distillRuns > 1) {
|
||||
prefix = prefix + distillRuns + "-fach ";
|
||||
if (!unlabeled) {
|
||||
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
|
||||
public void updateAgeLore(String prefix, PotionMeta meta) {
|
||||
if (ageTime >= 1 && ageTime < 2) {
|
||||
prefix = prefix + "Ein Jahr";
|
||||
} else if (ageTime < 201) {
|
||||
prefix = prefix + (int) Math.floor(ageTime) + " Jahre";
|
||||
if (!unlabeled) {
|
||||
if (ageTime >= 1 && ageTime < 2) {
|
||||
prefix = prefix + "Ein Jahr ";
|
||||
} else if (ageTime < 201) {
|
||||
prefix = prefix + (int) Math.floor(ageTime) + " Jahre ";
|
||||
} else {
|
||||
prefix = prefix + "Hunderte Jahre ";
|
||||
}
|
||||
}
|
||||
addOrReplaceLore(meta, prefix, "Fassgereift");
|
||||
}
|
||||
|
||||
// updates/sets the color on WoodLore
|
||||
public void updateWoodLore(PotionMeta meta) {
|
||||
if (currentRecipe.getWood() > 0) {
|
||||
int quality = ingredients.getWoodQuality(currentRecipe, wood);
|
||||
addOrReplaceLore(meta, getQualityColor(quality), "Holzart");
|
||||
} else {
|
||||
prefix = prefix + "Hunderte Jahre";
|
||||
if (meta.hasLore()) {
|
||||
List<String> existingLore = meta.getLore();
|
||||
int index = indexOfSubstring(existingLore, "Holzart");
|
||||
if (index > -1) {
|
||||
existingLore.remove(index);
|
||||
meta.setLore(existingLore);
|
||||
}
|
||||
}
|
||||
}
|
||||
addOrReplaceLore(meta, prefix, " Fassgereift");
|
||||
}
|
||||
|
||||
// Adds or replaces a line of Lore. Searches for Substring lore and replaces it
|
||||
@@ -391,6 +502,20 @@ public class Brew {
|
||||
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
|
||||
public static int indexOfSubstring(List<String> list, String substring) {
|
||||
for (int index = 0; index < list.size(); index++) {
|
||||
@@ -429,9 +554,10 @@ public class Brew {
|
||||
|
||||
// Saves all data
|
||||
public static void save(ConfigurationSection config) {
|
||||
for (int uid : potions.keySet()) {
|
||||
for (Map.Entry<Integer, Brew> entry : potions.entrySet()) {
|
||||
int uid = entry.getKey();
|
||||
Brew brew = entry.getValue();
|
||||
ConfigurationSection idConfig = config.createSection("" + uid);
|
||||
Brew brew = potions.get(uid);
|
||||
// not saving unneccessary data
|
||||
if (brew.quality != 0) {
|
||||
idConfig.set("quality", brew.quality);
|
||||
@@ -442,11 +568,17 @@ public class Brew {
|
||||
if (brew.ageTime != 0) {
|
||||
idConfig.set("ageTime", brew.ageTime);
|
||||
}
|
||||
if (brew.wood != -1) {
|
||||
idConfig.set("wood", brew.wood);
|
||||
}
|
||||
if (brew.currentRecipe != null) {
|
||||
idConfig.set("recipe", brew.currentRecipe.getName(5));
|
||||
}
|
||||
if (brew.unlabeled) {
|
||||
idConfig.set("unlabeled", true);
|
||||
}
|
||||
// save the ingredients
|
||||
brew.ingredients.save(idConfig.createSection("ingredients"));
|
||||
idConfig.set("ingId", brew.ingredients.save(config.getParent()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ public class LanguageReader {
|
||||
defaults.put("CMD_Player_Error", "&cDie Qualität muss zwischen 1 und 10 liegen!");
|
||||
defaults.put("CMD_Info_NotDrunk", "&v1 ist nicht betrunken");
|
||||
defaults.put("CMD_Info_Drunk", "&v1 ist &6&v2% &fbetrunken, mit einer Qualität von &6&v1");
|
||||
defaults.put("CMD_UnLabel", "&aDas Label wurde entfernt");
|
||||
defaults.put("CMD_Copy_Error", "&6&v1 &cTränke haben nicht mehr in das Inventar gepasst");
|
||||
|
||||
/* Error */
|
||||
@@ -74,6 +75,7 @@ public class LanguageReader {
|
||||
defaults.put("Help_Help", "&6/br help <Seite> &9Zeigt eine bestimmte Hilfeseite an");
|
||||
defaults.put("Help_Player", "&6/br <Spieler> <%Trunkenheit> <Qualität>&9 Setzt Trunkenheit (und Qualität) eines Spielers");
|
||||
defaults.put("Help_Info", "&6/br Info&9 Zeigt deine aktuelle Trunkenheit und Qualität an");
|
||||
defaults.put("Help_UnLabel", "&6/br UnLabel &9Entfernt die genaue Beschriftung des Trankes");
|
||||
defaults.put("Help_Copy", "&6/br Copy <Anzahl>&9 Kopiert den Trank in deiner Hand");
|
||||
defaults.put("Help_Delete", "&6/br Delete &9Entfernt den Trank in deiner Hand");
|
||||
defaults.put("Help_InfoOther", "&6/br Info <Spieler>&9 Zeigt die aktuelle Trunkenheit und Qualität von <Spieler> an");
|
||||
|
||||
+103
-62
@@ -30,6 +30,7 @@ import com.dre.brewery.listeners.*;
|
||||
|
||||
public class P extends JavaPlugin {
|
||||
public static P p;
|
||||
public static boolean debug;
|
||||
public static int lastBackup = 0;
|
||||
public static int lastSave = 1;
|
||||
public static int autosave = 3;
|
||||
@@ -105,7 +106,7 @@ public class P extends JavaPlugin {
|
||||
this.log(this.getDescription().getName() + " disabled!");
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
public void reload(CommandSender sender) {
|
||||
BIngredients.possibleIngredients.clear();
|
||||
BIngredients.recipes.clear();
|
||||
BIngredients.cookedNames.clear();
|
||||
@@ -113,6 +114,16 @@ public class P extends JavaPlugin {
|
||||
BPlayer.drainItems.clear();
|
||||
|
||||
readConfig();
|
||||
|
||||
Boolean successful = true;
|
||||
for (Brew brew : Brew.potions.values()) {
|
||||
if (!brew.reloadRecipe()) {
|
||||
successful = false;
|
||||
}
|
||||
}
|
||||
if (!successful) {
|
||||
msg(sender, "&cEs konnten nicht alle Rezepte wiederhergesellt werden: Siehe Serverlog!");
|
||||
}
|
||||
}
|
||||
|
||||
public void msg(CommandSender sender, String msg) {
|
||||
@@ -123,6 +134,12 @@ public class P extends JavaPlugin {
|
||||
this.msg(Bukkit.getConsoleSender(), msg);
|
||||
}
|
||||
|
||||
public void debugLog(String msg) {
|
||||
if (debug) {
|
||||
this.msg(Bukkit.getConsoleSender(), "&2[Debug] &f" + msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void errorLog(String msg) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
||||
}
|
||||
@@ -144,7 +161,9 @@ public class P extends JavaPlugin {
|
||||
|
||||
// various Settings
|
||||
autosave = config.getInt("autosave", 3);
|
||||
debug = config.getBoolean("debug", false);
|
||||
BPlayer.pukeItemId = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND")).getId();
|
||||
BPlayer.hangoverTime = config.getInt("hangoverDays", 0) * 24 * 60;
|
||||
BPlayer.overdrinkKick = config.getBoolean("enableKickOnOverdrink", false);
|
||||
BPlayer.enableHome = config.getBoolean("enableHome", false);
|
||||
BPlayer.enableLoginDisallow = config.getBoolean("enableLoginDisallow", false);
|
||||
@@ -157,7 +176,12 @@ public class P extends JavaPlugin {
|
||||
ConfigurationSection configSection = config.getConfigurationSection("recipes");
|
||||
if (configSection != null) {
|
||||
for (String recipeId : configSection.getKeys(false)) {
|
||||
BIngredients.recipes.add(new BRecipe(configSection, recipeId));
|
||||
BRecipe recipe = new BRecipe(configSection, recipeId);
|
||||
if (recipe.isValid()) {
|
||||
BIngredients.recipes.add(recipe);
|
||||
} else {
|
||||
errorLog("Laden des Rezeptes mit id: '" + recipeId + "' fehlgeschlagen!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,8 +190,12 @@ public class P extends JavaPlugin {
|
||||
if (configSection != null) {
|
||||
for (String ingredient : configSection.getKeys(false)) {
|
||||
Material mat = Material.matchMaterial(ingredient);
|
||||
BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null)));
|
||||
BIngredients.possibleIngredients.add(mat);
|
||||
if (mat != null) {
|
||||
BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null)));
|
||||
BIngredients.possibleIngredients.add(mat);
|
||||
} else {
|
||||
errorLog("Unbekanntes Material: " + ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,18 +225,40 @@ public class P extends JavaPlugin {
|
||||
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// loading Ingredients into ingMap
|
||||
Map<String, BIngredients> ingMap = new HashMap<String, BIngredients>();
|
||||
ConfigurationSection section = data.getConfigurationSection("Ingredients");
|
||||
if (section != null) {
|
||||
for (String id : section.getKeys(false)) {
|
||||
ConfigurationSection matSection = section.getConfigurationSection(id + ".mats");
|
||||
if (matSection != null) {
|
||||
// matSection has all the materials + amount as Integers
|
||||
Map<Material, Integer> ingredients = new HashMap<Material, Integer>();
|
||||
for (String ingredient : matSection.getKeys(false)) {
|
||||
// convert to Material
|
||||
ingredients.put(Material.getMaterial(parseInt(ingredient)), matSection.getInt(ingredient));
|
||||
}
|
||||
ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0)));
|
||||
} else {
|
||||
errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loading Brew
|
||||
ConfigurationSection section = data.getConfigurationSection("Brew");
|
||||
section = data.getConfigurationSection("Brew");
|
||||
if (section != null) {
|
||||
// All sections have the UID as name
|
||||
for (String uid : section.getKeys(false)) {
|
||||
BIngredients ingredients = loadIngredients(section.getConfigurationSection(uid + ".ingredients"));
|
||||
BIngredients ingredients = getIngredients(ingMap, section.getString(uid + ".ingId"));
|
||||
int quality = section.getInt(uid + ".quality", 0);
|
||||
int distillRuns = section.getInt(uid + ".distillRuns", 0);
|
||||
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
|
||||
float wood = (float) section.getDouble(uid + ".wood", -1.0);
|
||||
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, wood, recipe, unlabeled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,21 +289,30 @@ public class P extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// loads BIngredients from ingredient section
|
||||
public BIngredients loadIngredients(ConfigurationSection config) {
|
||||
if (config != null) {
|
||||
ConfigurationSection matSection = config.getConfigurationSection("mats");
|
||||
if (matSection != null) {
|
||||
// matSection has all the materials + amount in Integer form
|
||||
Map<Material, Integer> ingredients = new HashMap<Material, Integer>();
|
||||
for (String ingredient : matSection.getKeys(false)) {
|
||||
// convert to Material
|
||||
ingredients.put(Material.getMaterial(parseInt(ingredient)), matSection.getInt(ingredient));
|
||||
}
|
||||
return new BIngredients(ingredients, config.getInt("cookedTime", 0));
|
||||
// returns Ingredients by id from the specified ingMap
|
||||
public BIngredients getIngredients(Map<String, BIngredients> ingMap, String id) {
|
||||
if (!ingMap.isEmpty()) {
|
||||
if (ingMap.containsKey(id)) {
|
||||
return ingMap.get(id);
|
||||
}
|
||||
}
|
||||
errorLog("Ingredient section not found or incomplete in data.yml");
|
||||
errorLog("Ingredient id: '" + id + "' not found in data.yml");
|
||||
return new BIngredients();
|
||||
}
|
||||
|
||||
// loads BIngredients from an ingredient section
|
||||
public BIngredients loadIngredients(ConfigurationSection section) {
|
||||
if (section != null) {
|
||||
// has all the materials + amount as Integers
|
||||
Map<Material, Integer> ingredients = new HashMap<Material, Integer>();
|
||||
for (String ingredient : section.getKeys(false)) {
|
||||
// convert to Material
|
||||
ingredients.put(Material.getMaterial(parseInt(ingredient)), section.getInt(ingredient));
|
||||
}
|
||||
return new BIngredients(ingredients, 0);
|
||||
} else {
|
||||
errorLog("Cauldron is missing Ingredient Section");
|
||||
}
|
||||
return new BIngredients();
|
||||
}
|
||||
|
||||
@@ -367,55 +426,29 @@ public class P extends JavaPlugin {
|
||||
|
||||
FileConfiguration configFile = new YamlConfiguration();
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
float ftime = (float) (time / 1000000.0);
|
||||
p.log("Creating a savefile (" + ftime + "ms)");
|
||||
time = System.nanoTime();
|
||||
|
||||
if (!Brew.potions.isEmpty()) {
|
||||
Brew.save(configFile.createSection("Brew"));
|
||||
}
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
ftime = (float) (time / 1000000.0);
|
||||
p.log("Saving Brew (" + ftime + "ms)");
|
||||
time = System.nanoTime();
|
||||
|
||||
if (!BCauldron.bcauldrons.isEmpty() || oldData.contains("BCauldron")) {
|
||||
BCauldron.save(configFile.createSection("BCauldron"), oldData.getConfigurationSection("BCauldron"));
|
||||
}
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
ftime = (float) (time / 1000000.0);
|
||||
p.log("Saving BCauldrons (" + ftime + "ms)");
|
||||
time = System.nanoTime();
|
||||
|
||||
if (!Barrel.barrels.isEmpty() || oldData.contains("Barrel")) {
|
||||
Barrel.save(configFile.createSection("Barrel"), oldData.getConfigurationSection("Barrel"));
|
||||
}
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
ftime = (float) (time / 1000000.0);
|
||||
p.log("Saving Barrels (" + ftime + "ms)");
|
||||
time = System.nanoTime();
|
||||
|
||||
if (!BPlayer.players.isEmpty()) {
|
||||
BPlayer.save(configFile.createSection("Player"));
|
||||
}
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
ftime = (float) (time / 1000000.0);
|
||||
p.log("Saving players (" + ftime + "ms)");
|
||||
time = System.nanoTime();
|
||||
|
||||
if (!Wakeup.wakeups.isEmpty() || oldData.contains("Wakeup")) {
|
||||
Wakeup.save(configFile.createSection("Wakeup"), oldData.getConfigurationSection("Wakeup"));
|
||||
}
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
ftime = (float) (time / 1000000.0);
|
||||
p.log("Saving Wakeups (" + ftime + "ms)");
|
||||
time = System.nanoTime();
|
||||
saveWorldNames(configFile, oldData.getConfigurationSection("Worlds"));
|
||||
|
||||
configFile.set("Version", "0.5");
|
||||
|
||||
try {
|
||||
configFile.save(datafile);
|
||||
@@ -426,8 +459,24 @@ public class P extends JavaPlugin {
|
||||
lastSave = 1;
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
ftime = (float) (time / 1000000.0);
|
||||
p.log("Writing Data to File (" + ftime + "ms)");
|
||||
float ftime = (float) (time / 1000000.0);
|
||||
p.debugLog("Writing Data to File (" + ftime + "ms)");
|
||||
}
|
||||
|
||||
public void saveWorldNames(FileConfiguration root, ConfigurationSection old) {
|
||||
if (old != null) {
|
||||
root.set("Worlds", old);
|
||||
}
|
||||
for (World world : p.getServer().getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
worldName = getDxlName(worldName);
|
||||
root.set("Worlds." + worldName, 0);
|
||||
} else {
|
||||
worldName = world.getUID().toString();
|
||||
root.set("Worlds." + worldName, world.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Utility
|
||||
@@ -443,7 +492,7 @@ public class P extends JavaPlugin {
|
||||
for (File file : dungeonFolder.listFiles()) {
|
||||
if (!file.isDirectory()) {
|
||||
if (file.getName().startsWith(".id_")) {
|
||||
return file.getName().substring(1);
|
||||
return file.getName().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -535,26 +584,18 @@ public class P extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long time = System.nanoTime();
|
||||
|
||||
for (BCauldron cauldron : BCauldron.bcauldrons) {
|
||||
cauldron.onUpdate();// runs every min to update cooking time
|
||||
}
|
||||
Barrel.onUpdate();// runs every min to check and update ageing time
|
||||
BPlayer.onUpdate();// updates players drunkeness
|
||||
|
||||
debugLog("Update");
|
||||
|
||||
if (lastSave >= autosave) {
|
||||
saveData();// save all data
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
float ftime = (float) (time / 1000000.0);
|
||||
p.log("Update and saving (" + ftime + "ms)");
|
||||
} else {
|
||||
lastSave++;
|
||||
|
||||
time = System.nanoTime() - time;
|
||||
float ftime = (float) (time / 1000000.0);
|
||||
p.log("Update (" + ftime + "ms)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import com.dre.brewery.BCauldron;
|
||||
import com.dre.brewery.Barrel;
|
||||
@@ -31,12 +30,9 @@ public class BlockListener implements Listener {
|
||||
Block block = event.getBlock();
|
||||
// remove cauldron
|
||||
if (block.getType() == Material.CAULDRON) {
|
||||
if (block.getRelative(BlockFace.DOWN).getType() == Material.FIRE || block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
|
||||
|| block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||
if (block.getData() != 0) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(block);
|
||||
}
|
||||
if (block.getData() != 0) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(block);
|
||||
}
|
||||
// remove barrel and throw potions on the ground
|
||||
} else if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class CommandListener implements CommandExecutor {
|
||||
} else if (cmd.equalsIgnoreCase("reload")) {
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.reload")) {
|
||||
p.reload();
|
||||
p.reload(sender);
|
||||
p.msg(sender, p.languageReader.get("CMD_Reload"));
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_NoPermissions"));
|
||||
@@ -82,6 +82,14 @@ public class CommandListener implements CommandExecutor {
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.delete")) {
|
||||
cmdDelete(sender);
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_NoPermissions");
|
||||
}
|
||||
|
||||
} else if (cmd.equalsIgnoreCase("unlabel")) {
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.unlabel")) {
|
||||
cmdUnlabel(sender);
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_NoPermissions"));
|
||||
}
|
||||
@@ -143,6 +151,10 @@ public class CommandListener implements CommandExecutor {
|
||||
cmds.add (p.languageReader.get("Help_Info"));
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.unlabel")) {
|
||||
cmds.add (p.languageReader.get("Help_UnLabel");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.copy")) {
|
||||
cmds.add (p.languageReader.get("Help_Copy"));
|
||||
}
|
||||
@@ -230,6 +242,9 @@ public class CommandListener implements CommandExecutor {
|
||||
public void cmdPlayer(CommandSender sender, String[] args) {
|
||||
|
||||
int drunkeness = p.parseInt(args[1]);
|
||||
if (drunkeness < 0) {
|
||||
return;
|
||||
}
|
||||
int quality = -1;
|
||||
if (args.length > 2) {
|
||||
quality = p.parseInt(args[2]);
|
||||
@@ -335,4 +350,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, p.languageReader.get("CMD_UnLabel");
|
||||
return;
|
||||
}
|
||||
}
|
||||
p.msg(sender, p.languageReader.get("Error_ItemNotPotion");
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("Error_PlayerCommand");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,10 +56,12 @@ public class InventoryListener implements Listener {
|
||||
if (event.getSlot() > 2) {
|
||||
return;
|
||||
}
|
||||
} else if (event.getInventory().getType() != InventoryType.CHEST) {
|
||||
} else if (event.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (!event.getInventory().getTitle().equals("Fass")) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = event.getCurrentItem();
|
||||
@@ -69,8 +71,10 @@ public class InventoryListener implements Listener {
|
||||
PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||
Brew brew = Brew.get(meta);
|
||||
if (brew != null) {
|
||||
brew.convertLore(meta, false);
|
||||
item.setItemMeta(meta);
|
||||
if (Brew.hasColorLore(meta)) {
|
||||
brew.convertLore(meta, false);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.dre.brewery.listeners;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -30,66 +32,68 @@ public class PlayerListener implements Listener {
|
||||
|
||||
if (clickedBlock != null) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (clickedBlock.getType() == Material.CAULDRON) {
|
||||
if (clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.FIRE || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
|
||||
|| clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||
Material materialInHand = event.getMaterial();
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = event.getItem();
|
||||
Player player = event.getPlayer();
|
||||
if (!player.isSneaking()) {
|
||||
if (clickedBlock.getType() == Material.CAULDRON) {
|
||||
if (clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.FIRE || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
|
||||
|| clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||
Material materialInHand = event.getMaterial();
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
|
||||
if (materialInHand == Material.WATCH) {
|
||||
BCauldron.printTime(player, clickedBlock);
|
||||
|
||||
if (materialInHand == Material.WATCH) {
|
||||
BCauldron.printTime(player, clickedBlock);
|
||||
|
||||
// fill a glass bottle with potion
|
||||
} else if (materialInHand == Material.GLASS_BOTTLE) {
|
||||
if (player.getInventory().firstEmpty() != -1 || item.getAmount() == 1) {
|
||||
if (BCauldron.fill(player, clickedBlock)) {
|
||||
// fill a glass bottle with potion
|
||||
} else if (materialInHand == Material.GLASS_BOTTLE) {
|
||||
if (player.getInventory().firstEmpty() != -1 || item.getAmount() == 1) {
|
||||
if (BCauldron.fill(player, clickedBlock)) {
|
||||
event.setCancelled(true);
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
} else {
|
||||
player.setItemInHand(new ItemStack(0));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// reset cauldron when refilling to prevent
|
||||
// unlimited source of potions
|
||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||
if (clickedBlock.getData() != 0) {
|
||||
if (clickedBlock.getData() < 3) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(clickedBlock);
|
||||
}
|
||||
}
|
||||
|
||||
// add ingredient to cauldron that meet the previous
|
||||
// contitions
|
||||
} else if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
||||
if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) {
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
} else {
|
||||
player.setItemInHand(new ItemStack(0));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// reset cauldron when refilling to prevent
|
||||
// unlimited source of potions
|
||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||
if (clickedBlock.getData() != 0) {
|
||||
if (clickedBlock.getData() < 3) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(clickedBlock);
|
||||
}
|
||||
}
|
||||
|
||||
// add ingredient to cauldron that meet the previous
|
||||
// contitions
|
||||
} else if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
||||
if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) {
|
||||
if (item.getAmount() > 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
} else {
|
||||
player.setItemInHand(new ItemStack(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// access a barrel
|
||||
} else if (clickedBlock.getType() == Material.FENCE || clickedBlock.getType() == Material.NETHER_FENCE || clickedBlock.getType() == Material.SIGN
|
||||
|| clickedBlock.getType() == Material.WALL_SIGN) {
|
||||
Barrel barrel = Barrel.get(clickedBlock);
|
||||
if (barrel != null) {
|
||||
event.setCancelled(true);
|
||||
Block broken = Barrel.getBrokenBlock(clickedBlock);
|
||||
// barrel is built correctly
|
||||
if (broken == null) {
|
||||
barrel.open(event.getPlayer());
|
||||
} else {
|
||||
barrel.remove(broken);
|
||||
// access a barrel
|
||||
} else if (clickedBlock.getType() == Material.FENCE || clickedBlock.getType() == Material.NETHER_FENCE || clickedBlock.getType() == Material.SIGN
|
||||
|| clickedBlock.getType() == Material.WALL_SIGN) {
|
||||
Barrel barrel = Barrel.get(clickedBlock);
|
||||
if (barrel != null) {
|
||||
event.setCancelled(true);
|
||||
Block broken = Barrel.getBrokenBlock(clickedBlock);
|
||||
// barrel is built correctly
|
||||
if (broken == null) {
|
||||
barrel.open(player);
|
||||
} else {
|
||||
barrel.remove(broken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,6 +135,20 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// Player has died! Decrease Drunkeness by 20
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
String playerName = event.getPlayer().getName();
|
||||
BPlayer bPlayer = BPlayer.get(playerName);
|
||||
if (bPlayer != null) {
|
||||
if (bPlayer.getDrunkeness() > 20) {
|
||||
bPlayer.setData(bPlayer.getDrunkeness() - 20, 0);
|
||||
} else {
|
||||
BPlayer.players.remove(playerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// player walks while drunk, push him around!
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
@@ -165,4 +183,12 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
BPlayer bplayer = BPlayer.get(event.getPlayer().getName());
|
||||
if (bplayer != null) {
|
||||
bplayer.disconnecting();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user