mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 06:38:56 +00:00
@@ -35,18 +35,15 @@ public class BCauldron {
|
|||||||
bcauldrons.add(this);
|
bcauldrons.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
// Check if fire still alive
|
// Check if fire still alive
|
||||||
if(block.getRelative(BlockFace.DOWN).getType() == Material.FIRE ||
|
if (block.getRelative(BlockFace.DOWN).getType() == Material.FIRE || block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
|
||||||
block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA ||
|
|| block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||||
block.getRelative(BlockFace.DOWN).getType() == Material.LAVA){
|
|
||||||
// add a minute to cooking time
|
// add a minute to cooking time
|
||||||
state++;
|
state++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// add an ingredient to the cauldron
|
// add an ingredient to the cauldron
|
||||||
public void add(Material ingredient) {
|
public void add(Material ingredient) {
|
||||||
ingredients.add(ingredient);
|
ingredients.add(ingredient);
|
||||||
@@ -78,7 +75,8 @@ public class BCauldron {
|
|||||||
if (bcauldron.block.equals(block)) {
|
if (bcauldron.block.equals(block)) {
|
||||||
ItemStack potion = bcauldron.ingredients.cook(bcauldron.state);
|
ItemStack potion = bcauldron.ingredients.cook(bcauldron.state);
|
||||||
if (potion != null) {
|
if (potion != null) {
|
||||||
//Bukkit Bug, inventory not updating while in event so this will delay the give
|
// Bukkit Bug, inventory not updating while in event so this
|
||||||
|
// will delay the give
|
||||||
// but could also just use deprecated updateInventory()
|
// but could also just use deprecated updateInventory()
|
||||||
giveItem(player, potion);
|
giveItem(player, potion);
|
||||||
// player.getInventory().addItem(potion);
|
// player.getInventory().addItem(potion);
|
||||||
@@ -121,7 +119,8 @@ public class BCauldron {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//bukkit bug not updating the inventory while executing event, have to schedule the give
|
// bukkit bug not updating the inventory while executing event, have to
|
||||||
|
// schedule the give
|
||||||
public static void giveItem(final Player player, final ItemStack item) {
|
public static void giveItem(final Player player, final ItemStack item) {
|
||||||
P.p.getServer().getScheduler().runTaskLater(P.p, new Runnable() {
|
P.p.getServer().getScheduler().runTaskLater(P.p, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import org.bukkit.inventory.meta.PotionMeta;
|
|||||||
import com.dre.brewery.BRecipe;
|
import com.dre.brewery.BRecipe;
|
||||||
import com.dre.brewery.Brew;
|
import com.dre.brewery.Brew;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class BIngredients {
|
public class BIngredients {
|
||||||
public static ArrayList<Material> possibleIngredients = new ArrayList<Material>();
|
public static ArrayList<Material> possibleIngredients = new ArrayList<Material>();
|
||||||
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
|
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
|
||||||
@@ -50,7 +48,8 @@ public class BIngredients {
|
|||||||
ItemStack potion = new ItemStack(Material.POTION);
|
ItemStack potion = new ItemStack(Material.POTION);
|
||||||
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
|
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
|
||||||
|
|
||||||
//cookedTime is always time in minutes, state may differ with number of ticks
|
// cookedTime is always time in minutes, state may differ with number of
|
||||||
|
// ticks
|
||||||
cookedTime = state;
|
cookedTime = state;
|
||||||
String cookedName = null;
|
String cookedName = null;
|
||||||
BRecipe cookRecipe = getCookRecipe();
|
BRecipe cookRecipe = getCookRecipe();
|
||||||
@@ -99,7 +98,6 @@ public class BIngredients {
|
|||||||
return potion;
|
return potion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// returns amount of ingredients
|
// returns amount of ingredients
|
||||||
private int getIngredientsCount() {
|
private int getIngredientsCount() {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@@ -109,7 +107,8 @@ public class BIngredients {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
//best recipe for current state of potion, STILL not always returns the correct one...
|
// best recipe for current state of potion, STILL not always returns the
|
||||||
|
// correct one...
|
||||||
public BRecipe getBestRecipe(byte wood, float time) {
|
public BRecipe getBestRecipe(byte wood, float time) {
|
||||||
float quality = 0;
|
float quality = 0;
|
||||||
int ingredientQuality = 0;
|
int ingredientQuality = 0;
|
||||||
@@ -122,7 +121,8 @@ public class BIngredients {
|
|||||||
cookingQuality = getCookingQuality(recipe);
|
cookingQuality = getCookingQuality(recipe);
|
||||||
|
|
||||||
if (ingredientQuality > -1) {
|
if (ingredientQuality > -1) {
|
||||||
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.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) + " age Quality: "
|
||||||
|
+ getAgeQuality(recipe, time) + " for " + recipe.getName(5));
|
||||||
if (recipe.needsToAge()) {
|
if (recipe.needsToAge()) {
|
||||||
// needs riping in barrel
|
// needs riping in barrel
|
||||||
ageQuality = getAgeQuality(recipe, time);
|
ageQuality = getAgeQuality(recipe, time);
|
||||||
@@ -148,7 +148,8 @@ public class BIngredients {
|
|||||||
return bestRecipe;
|
return bestRecipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns recipe that is cooking only and matches the ingredients and cooking time
|
// returns recipe that is cooking only and matches the ingredients and
|
||||||
|
// cooking time
|
||||||
public BRecipe getCookRecipe() {
|
public BRecipe getCookRecipe() {
|
||||||
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
|
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
|
||||||
|
|
||||||
@@ -161,7 +162,8 @@ public class BIngredients {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns the currently best matching recipe for distilling for the ingredients and cooking time
|
// returns the currently best matching recipe for distilling for the
|
||||||
|
// ingredients and cooking time
|
||||||
public BRecipe getdistillRecipe() {
|
public BRecipe getdistillRecipe() {
|
||||||
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
|
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
|
||||||
|
|
||||||
@@ -174,7 +176,8 @@ public class BIngredients {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns currently best matching recipe for ingredients, cooking- and ageingtime
|
// returns currently best matching recipe for ingredients, cooking- and
|
||||||
|
// ageingtime
|
||||||
public BRecipe getAgeRecipe(byte wood, float time) {
|
public BRecipe getAgeRecipe(byte wood, float time) {
|
||||||
BRecipe bestRecipe = getBestRecipe(wood, time);
|
BRecipe bestRecipe = getBestRecipe(wood, time);
|
||||||
|
|
||||||
@@ -186,7 +189,8 @@ public class BIngredients {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns the quality of the ingredients conditioning given recipe, -1 if no recipe is near them
|
// returns the quality of the ingredients conditioning given recipe, -1 if
|
||||||
|
// no recipe is near them
|
||||||
public int getIngredientQuality(BRecipe recipe) {
|
public int getIngredientQuality(BRecipe recipe) {
|
||||||
float quality = 10;
|
float quality = 10;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@@ -200,7 +204,8 @@ public class BIngredients {
|
|||||||
if (recipe.amountOf(ingredient) == 0) {
|
if (recipe.amountOf(ingredient) == 0) {
|
||||||
// this ingredient doesnt belong into the recipe
|
// this ingredient doesnt belong into the recipe
|
||||||
if (count > (getIngredientsCount() / 2)) {
|
if (count > (getIngredientsCount() / 2)) {
|
||||||
//when more than half of the ingredients dont fit into the recipe
|
// when more than half of the ingredients dont fit into the
|
||||||
|
// recipe
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
badStuff++;
|
badStuff++;
|
||||||
@@ -216,9 +221,9 @@ public class BIngredients {
|
|||||||
// calculate the quality
|
// 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){
|
/*
|
||||||
quality /= ingredients.size();
|
* if(quality != 0){ quality /= ingredients.size(); }
|
||||||
}*/
|
*/
|
||||||
if (quality >= 0) {
|
if (quality >= 0) {
|
||||||
return Math.round(quality);
|
return Math.round(quality);
|
||||||
}
|
}
|
||||||
@@ -277,8 +282,4 @@ public class BIngredients {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,10 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import com.dre.brewery.Brew;
|
import com.dre.brewery.Brew;
|
||||||
|
|
||||||
public class BPlayer {
|
public class BPlayer {
|
||||||
public static Map<String,BPlayer> players=new HashMap<String,BPlayer>();//Players name and BPlayer
|
public static Map<String, BPlayer> players = new HashMap<String, BPlayer>();// Players
|
||||||
|
// name
|
||||||
|
// and
|
||||||
|
// BPlayer
|
||||||
|
|
||||||
private int quality = 0;// = quality of drunkeness * drunkeness
|
private int quality = 0;// = quality of drunkeness * drunkeness
|
||||||
private int drunkeness = 0;// = amount of drunkeness
|
private int drunkeness = 0;// = amount of drunkeness
|
||||||
@@ -29,7 +32,6 @@ public class BPlayer {
|
|||||||
players.put(name, this);
|
players.put(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static BPlayer get(String name) {
|
public static BPlayer get(String name) {
|
||||||
if (!players.isEmpty()) {
|
if (!players.isEmpty()) {
|
||||||
if (players.containsKey(name)) {
|
if (players.containsKey(name)) {
|
||||||
@@ -80,7 +82,8 @@ public class BPlayer {
|
|||||||
if (entity.isOnGround()) {
|
if (entity.isOnGround()) {
|
||||||
time--;
|
time--;
|
||||||
if (time == 0) {
|
if (time == 0) {
|
||||||
//push him only to the side? or any direction like now
|
// push him only to the side? or any direction
|
||||||
|
// like now
|
||||||
push.setX(Math.random() - 0.5);
|
push.setX(Math.random() - 0.5);
|
||||||
push.setZ(Math.random() - 0.5);
|
push.setZ(Math.random() - 0.5);
|
||||||
player.setVelocity(push);
|
player.setVelocity(push);
|
||||||
@@ -121,7 +124,6 @@ public class BPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// getter
|
// getter
|
||||||
public int getDrunkeness() {
|
public int getDrunkeness() {
|
||||||
return drunkeness;
|
return drunkeness;
|
||||||
@@ -131,5 +133,4 @@ public class BPlayer {
|
|||||||
return Math.round(quality / drunkeness);
|
return Math.round(quality / drunkeness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,17 +7,19 @@ import java.util.HashMap;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
|
||||||
public class BRecipe {
|
public class BRecipe {
|
||||||
|
|
||||||
private String[] name;
|
private String[] name;
|
||||||
private Map<Material,Integer> ingredients = new HashMap<Material,Integer>();//material and amount
|
private Map<Material, Integer> ingredients = new HashMap<Material, Integer>();// 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 int distillruns;// runs through the brewer
|
||||||
private int wood;// type of wood the barrel has to consist of
|
private int 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
|
||||||
private String color;// color of the destilled/finished potion
|
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
|
private int difficulty;// difficulty to brew the potion, how exact the
|
||||||
|
// instruction has to be followed
|
||||||
private int alcohol;// Vol% of alcohol in perfect potion
|
private int alcohol;// Vol% of alcohol in perfect potion
|
||||||
|
|
||||||
public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
|
public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
|
||||||
@@ -43,9 +45,8 @@ public class BRecipe {
|
|||||||
this.alcohol = configSectionRecipes.getInt(recipeId + ".alcohol");
|
this.alcohol = configSectionRecipes.getInt(recipeId + ".alcohol");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allowed deviation to the recipes count of ingredients at the given
|
||||||
|
// difficulty
|
||||||
//allowed deviation to the recipes count of ingredients at the given difficulty
|
|
||||||
public int allowedCountDiff(int count) {
|
public int allowedCountDiff(int count) {
|
||||||
int allowedCountDiff = Math.round((float) ((11.0 - difficulty) * (count / 10.0)));
|
int allowedCountDiff = Math.round((float) ((11.0 - difficulty) * (count / 10.0)));
|
||||||
|
|
||||||
@@ -117,8 +118,6 @@ public class BRecipe {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Getter
|
// Getter
|
||||||
|
|
||||||
// how many of a specific ingredient in the recipe
|
// how many of a specific ingredient in the recipe
|
||||||
@@ -182,5 +181,4 @@ public class BRecipe {
|
|||||||
return alcohol;
|
return alcohol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,8 @@ public class Barrel {
|
|||||||
|
|
||||||
public static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<Barrel>();
|
public static CopyOnWriteArrayList<Barrel> barrels = new CopyOnWriteArrayList<Barrel>();
|
||||||
|
|
||||||
//private CopyOnWriteArrayList<Brew> brews = new CopyOnWriteArrayList<Brew>();
|
// private CopyOnWriteArrayList<Brew> brews = new
|
||||||
|
// CopyOnWriteArrayList<Brew>();
|
||||||
private Block spigot;
|
private Block spigot;
|
||||||
private Inventory inventory;
|
private Inventory inventory;
|
||||||
private float time;
|
private float time;
|
||||||
@@ -165,7 +166,8 @@ private float time;
|
|||||||
// create section only when items in inventory
|
// create section only when items in inventory
|
||||||
invConfig = idConfig.createSection("inv");
|
invConfig = idConfig.createSection("inv");
|
||||||
}
|
}
|
||||||
//ItemStacks are configurationSerializeable, makes them really easy to save
|
// ItemStacks are configurationSerializeable, makes them
|
||||||
|
// really easy to save
|
||||||
invConfig.set(slot + "", item);
|
invConfig.set(slot + "", item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,8 +268,7 @@ private float time;
|
|||||||
int y = -2;
|
int y = -2;
|
||||||
while (y <= 1) {
|
while (y <= 1) {
|
||||||
// Fence and Netherfence
|
// Fence and Netherfence
|
||||||
if(block.getRelative(0,y,0).getTypeId() == 85 ||
|
if (block.getRelative(0, y, 0).getTypeId() == 85 || block.getRelative(0, y, 0).getTypeId() == 113) {
|
||||||
block.getRelative(0,y,0).getTypeId() == 113){
|
|
||||||
return (block.getRelative(0, y, 0));
|
return (block.getRelative(0, y, 0));
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
@@ -275,7 +276,8 @@ private float time;
|
|||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns null if Barrel is correctly placed; the block that is missing when not
|
// returns null if Barrel is correctly placed; the block that is missing
|
||||||
|
// when not
|
||||||
// the barrel needs to be formed correctly
|
// the barrel needs to be formed correctly
|
||||||
public static Block getBrokenBlock(Block spigot) {
|
public static Block getBrokenBlock(Block spigot) {
|
||||||
spigot = getSpigotOfSign(spigot);
|
spigot = getSpigotOfSign(spigot);
|
||||||
|
|||||||
@@ -67,20 +67,17 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns a Brew by ItemStack
|
// returns a Brew by ItemStack
|
||||||
/*public static Brew get(ItemStack item){
|
/*
|
||||||
if(item.getTypeId() == 373){
|
* public static Brew get(ItemStack item){ if(item.getTypeId() == 373){
|
||||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
* PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); return
|
||||||
return get(potionMeta);
|
* get(potionMeta); } return null; }
|
||||||
}
|
*/
|
||||||
return null;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// returns UID of custom Potion item
|
// returns UID of custom Potion item
|
||||||
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
|
||||||
public static int getUID(PotionMeta potionMeta) {
|
public static int getUID(PotionMeta potionMeta) {
|
||||||
if (potionMeta.hasCustomEffect(PotionEffectType.REGENERATION)) {
|
if (potionMeta.hasCustomEffect(PotionEffectType.REGENERATION)) {
|
||||||
@@ -100,7 +97,6 @@ public class Brew {
|
|||||||
potions.remove(getUID(item));
|
potions.remove(getUID(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// generate an UID
|
// generate an UID
|
||||||
public static int generateUID() {
|
public static int generateUID() {
|
||||||
int uid = -2;
|
int uid = -2;
|
||||||
@@ -125,10 +121,7 @@ public class Brew {
|
|||||||
// calculate quality from all of the factors
|
// calculate quality from all of the factors
|
||||||
float quality = (
|
float quality = (
|
||||||
|
|
||||||
ingredients.getIngredientQuality(recipe) +
|
ingredients.getIngredientQuality(recipe) + ingredients.getCookingQuality(recipe) + ingredients.getWoodQuality(recipe, wood) + ingredients.getAgeQuality(recipe, ageTime));
|
||||||
ingredients.getCookingQuality(recipe) +
|
|
||||||
ingredients.getWoodQuality(recipe,wood) +
|
|
||||||
ingredients.getAgeQuality(recipe,ageTime));
|
|
||||||
|
|
||||||
quality /= 4;
|
quality /= 4;
|
||||||
return (int) Math.round(quality);
|
return (int) Math.round(quality);
|
||||||
@@ -143,12 +136,8 @@ public class Brew {
|
|||||||
return alcohol;
|
return alcohol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Distilling section ---------------
|
// Distilling section ---------------
|
||||||
|
|
||||||
|
|
||||||
// distill all custom potions in the brewer
|
// distill all custom potions in the brewer
|
||||||
public static void distillAll(BrewerInventory inv, Integer[] contents) {
|
public static void distillAll(BrewerInventory inv, Integer[] contents) {
|
||||||
int slot = 0;
|
int slot = 0;
|
||||||
@@ -171,7 +160,8 @@ public class Brew {
|
|||||||
brew.quality = brew.calcQuality(recipe, (byte) 0);
|
brew.quality = brew.calcQuality(recipe, (byte) 0);
|
||||||
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality);
|
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality);
|
||||||
brew.distillRuns += 1;
|
brew.distillRuns += 1;
|
||||||
//distillRuns will have an effect on the amount of alcohol, not the quality
|
// distillRuns will have an effect on the amount of alcohol, not the
|
||||||
|
// quality
|
||||||
if (brew.distillRuns > 1) {
|
if (brew.distillRuns > 1) {
|
||||||
ArrayList<String> lore = new ArrayList<String>();
|
ArrayList<String> lore = new ArrayList<String>();
|
||||||
lore.add(brew.distillRuns + " fach Destilliert");
|
lore.add(brew.distillRuns + " fach Destilliert");
|
||||||
@@ -195,12 +185,8 @@ public class Brew {
|
|||||||
slotItem.setItemMeta(potionMeta);
|
slotItem.setItemMeta(potionMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Ageing Section ------------------
|
// Ageing Section ------------------
|
||||||
|
|
||||||
|
|
||||||
public static void age(ItemStack item, float time, byte wood) {
|
public static void age(ItemStack item, float time, byte wood) {
|
||||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||||
Brew brew = get(potionMeta);
|
Brew brew = get(potionMeta);
|
||||||
@@ -248,22 +234,8 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static enum PotionColor {
|
public static enum PotionColor {
|
||||||
PINK(1),
|
PINK(1), CYAN(2), ORANGE(3), GREEN(4), BRIGHT_RED(5), BLUE(6), BLACK(8), RED(9), GREY(10), WATER(11), DARK_RED(12), BRIGHT_GREY(14);
|
||||||
CYAN(2),
|
|
||||||
ORANGE(3),
|
|
||||||
GREEN(4),
|
|
||||||
BRIGHT_RED(5),
|
|
||||||
BLUE(6),
|
|
||||||
BLACK(8),
|
|
||||||
RED(9),
|
|
||||||
GREY(10),
|
|
||||||
WATER(11),
|
|
||||||
DARK_RED(12),
|
|
||||||
BRIGHT_GREY(14);
|
|
||||||
|
|
||||||
private final int colorId;
|
private final int colorId;
|
||||||
|
|
||||||
@@ -281,5 +253,4 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,6 @@ public class P extends JavaPlugin{
|
|||||||
public PlayerListener playerListener;
|
public PlayerListener playerListener;
|
||||||
public EntityListener entityListener;
|
public EntityListener entityListener;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
p = this;
|
p = this;
|
||||||
@@ -47,14 +46,12 @@ public class P extends JavaPlugin{
|
|||||||
p.getServer().getPluginManager().registerEvents(entityListener, p);
|
p.getServer().getPluginManager().registerEvents(entityListener, p);
|
||||||
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 1200, 1200);
|
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 1200, 1200);
|
||||||
|
|
||||||
|
|
||||||
this.log(this.getDescription().getName() + " enabled!");
|
this.log(this.getDescription().getName() + " enabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
|
|
||||||
// Disable listeners
|
// Disable listeners
|
||||||
HandlerList.unregisterAll(p);
|
HandlerList.unregisterAll(p);
|
||||||
|
|
||||||
@@ -78,7 +75,6 @@ public class P extends JavaPlugin{
|
|||||||
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void readConfig() {
|
public void readConfig() {
|
||||||
|
|
||||||
File file = new File(p.getDataFolder(), "config.yml");
|
File file = new File(p.getDataFolder(), "config.yml");
|
||||||
@@ -110,7 +106,6 @@ public class P extends JavaPlugin{
|
|||||||
|
|
||||||
// load all Data
|
// load all Data
|
||||||
public void readData() {
|
public void readData() {
|
||||||
|
|
||||||
File file = new File(p.getDataFolder(), "data.yml");
|
File file = new File(p.getDataFolder(), "data.yml");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
|
||||||
@@ -121,9 +116,8 @@ public class P extends JavaPlugin{
|
|||||||
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)) {
|
||||||
new Brew(
|
new Brew(parseInt(uid), loadIngredients(section.getConfigurationSection(uid + ".ingredients")), section.getInt(uid + ".quality", 0), section.getInt(uid + ".distillRuns", 0),
|
||||||
parseInt(uid), loadIngredients(section.getConfigurationSection(uid+".ingredients")),
|
(float) section.getDouble(uid + ".ageTime", 0.0), section.getInt(uid + ".alcohol", 0));
|
||||||
section.getInt(uid+".quality",0), section.getInt(uid+".distillRuns",0), (float)section.getDouble(uid+".ageTime",0.0), section.getInt(uid+".alcohol",0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,8 +130,7 @@ public class P extends JavaPlugin{
|
|||||||
if (block != null) {
|
if (block != null) {
|
||||||
String[] splitted = block.split("/");
|
String[] splitted = block.split("/");
|
||||||
if (splitted.length == 4) {
|
if (splitted.length == 4) {
|
||||||
new BCauldron(
|
new BCauldron(getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]), parseInt(splitted[2]), parseInt(splitted[3])),
|
||||||
getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]),parseInt(splitted[2]),parseInt(splitted[3])),
|
|
||||||
loadIngredients(section.getConfigurationSection(cauldron + ".ingredients")), section.getInt(cauldron + ".state", 1));
|
loadIngredients(section.getConfigurationSection(cauldron + ".ingredients")), section.getInt(cauldron + ".state", 1));
|
||||||
} else {
|
} else {
|
||||||
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
|
||||||
@@ -160,17 +153,16 @@ public class P extends JavaPlugin{
|
|||||||
// load itemStacks from invSection
|
// load itemStacks from invSection
|
||||||
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
|
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
|
||||||
if (invSection != null) {
|
if (invSection != null) {
|
||||||
//Map<String,ItemStack> inventory = section.getValues(barrel+"inv");
|
// Map<String,ItemStack> inventory =
|
||||||
new Barrel(
|
// section.getValues(barrel+"inv");
|
||||||
getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]),parseInt(splitted[2]),parseInt(splitted[3])),
|
new Barrel(getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]), parseInt(splitted[2]), parseInt(splitted[3])), invSection.getValues(true),
|
||||||
invSection.getValues(true), (float)section.getDouble(barrel+".time",0.0));
|
(float) section.getDouble(barrel + ".time", 0.0));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// errorLog("Inventory of "+section.getCurrentPath()+"."+barrel+" in data.yml is missing");
|
// errorLog("Inventory of "+section.getCurrentPath()+"."+barrel+" in data.yml is missing");
|
||||||
// Barrel has no inventory
|
// Barrel has no inventory
|
||||||
new Barrel(
|
new Barrel(getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]), parseInt(splitted[2]), parseInt(splitted[3])), (float) section.getDouble(barrel
|
||||||
getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]),parseInt(splitted[2]),parseInt(splitted[3])),
|
+ ".time", 0.0));
|
||||||
(float)section.getDouble(barrel+".time",0.0));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
|
||||||
@@ -195,7 +187,6 @@ public class P extends JavaPlugin{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// loads BIngredients from ingredient section
|
// loads BIngredients from ingredient section
|
||||||
public BIngredients loadIngredients(ConfigurationSection config) {
|
public BIngredients loadIngredients(ConfigurationSection config) {
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
@@ -253,8 +244,6 @@ public class P extends JavaPlugin{
|
|||||||
return NumberUtils.toInt(string, 0);
|
return NumberUtils.toInt(string, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class BreweryRunnable implements Runnable {
|
public class BreweryRunnable implements Runnable {
|
||||||
|
|
||||||
public BreweryRunnable() {
|
public BreweryRunnable() {
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ public class Words {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//replace "percent"% of "from" -> "to" in "words", when the string before each "from" "match"es "pre"
|
// replace "percent"% of "from" -> "to" in "words", when the string before
|
||||||
|
// each "from" "match"es "pre"
|
||||||
// Not yet ignoring case :(
|
// Not yet ignoring case :(
|
||||||
public static String distort(String words, String from, String to, String[] pre, boolean match, int percent) {
|
public static String distort(String words, String from, String to, String[] pre, boolean match, int percent) {
|
||||||
if (from.equalsIgnoreCase("-end")) {
|
if (from.equalsIgnoreCase("-end")) {
|
||||||
@@ -102,7 +103,8 @@ public class Words {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (words.contains(from)) {
|
if (words.contains(from)) {
|
||||||
//some characters (*,?) disturb split() which then throws PatternSyntaxException
|
// some characters (*,?) disturb split() which then throws
|
||||||
|
// PatternSyntaxException
|
||||||
try {
|
try {
|
||||||
if (pre == null && percent == 100) {
|
if (pre == null && percent == 100) {
|
||||||
// All occurences of "from" need to be replaced
|
// All occurences of "from" need to be replaced
|
||||||
@@ -186,5 +188,4 @@ public class Words {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,9 +31,8 @@ public class BlockListener implements Listener{
|
|||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
// remove cauldron
|
// remove cauldron
|
||||||
if (block.getType() == Material.CAULDRON) {
|
if (block.getType() == Material.CAULDRON) {
|
||||||
if(block.getRelative(BlockFace.DOWN).getType() == Material.FIRE ||
|
if (block.getRelative(BlockFace.DOWN).getType() == Material.FIRE || block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
|
||||||
block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA ||
|
|| block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||||
block.getRelative(BlockFace.DOWN).getType() == Material.LAVA){
|
|
||||||
if (block.getData() != 0) {
|
if (block.getData() != 0) {
|
||||||
// will only remove when existing
|
// will only remove when existing
|
||||||
BCauldron.remove(block);
|
BCauldron.remove(block);
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ public class PlayerListener implements Listener{
|
|||||||
if (clickedBlock != null) {
|
if (clickedBlock != null) {
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
if (clickedBlock.getType() == Material.CAULDRON) {
|
if (clickedBlock.getType() == Material.CAULDRON) {
|
||||||
if(clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.FIRE ||
|
if (clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.FIRE || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
|
||||||
clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA ||
|
|| clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||||
clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.LAVA){
|
|
||||||
Material materialInHand = event.getMaterial();
|
Material materialInHand = event.getMaterial();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
|
|
||||||
//add ingredient to cauldron that meet the previous contitions
|
// add ingredient to cauldron that meet the previous
|
||||||
|
// contitions
|
||||||
if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
if (BIngredients.possibleIngredients.contains(materialInHand)) {
|
||||||
if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) {
|
if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) {
|
||||||
if (item.getAmount() > 1) {
|
if (item.getAmount() > 1) {
|
||||||
@@ -57,7 +57,8 @@ public class PlayerListener implements Listener{
|
|||||||
player.setItemInHand(new ItemStack(0));
|
player.setItemInHand(new ItemStack(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//reset cauldron when refilling to prevent unlimited source of potions
|
// reset cauldron when refilling to prevent
|
||||||
|
// unlimited source of potions
|
||||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||||
if (clickedBlock.getData() != 0) {
|
if (clickedBlock.getData() != 0) {
|
||||||
if (clickedBlock.getData() < 3) {
|
if (clickedBlock.getData() < 3) {
|
||||||
@@ -68,10 +69,8 @@ public class PlayerListener implements Listener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// access a barrel
|
// access a barrel
|
||||||
} else if (clickedBlock.getType() == Material.FENCE ||
|
} else if (clickedBlock.getType() == Material.FENCE || clickedBlock.getType() == Material.NETHER_FENCE || clickedBlock.getType() == Material.SIGN
|
||||||
clickedBlock.getType() == Material.NETHER_FENCE ||
|
|| clickedBlock.getType() == Material.WALL_SIGN) {
|
||||||
clickedBlock.getType() == Material.SIGN ||
|
|
||||||
clickedBlock.getType() == Material.WALL_SIGN){
|
|
||||||
Barrel barrel = Barrel.get(clickedBlock);
|
Barrel barrel = Barrel.get(clickedBlock);
|
||||||
if (barrel != null) {
|
if (barrel != null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@@ -89,9 +88,6 @@ public class PlayerListener implements Listener{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBrew(BrewEvent event) {
|
public void onBrew(BrewEvent event) {
|
||||||
int slot = 0;
|
int slot = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user