Formatting

Signed-off-by: Grafe <flingelfrank@hotmail.com>
This commit is contained in:
Grafe
2013-05-03 16:08:05 +02:00
parent 3bae71872e
commit 873b54f532
11 changed files with 800 additions and 843 deletions
+6 -7
View File
@@ -35,18 +35,15 @@ public class BCauldron {
bcauldrons.add(this);
}
public void onUpdate() {
// Check if fire still alive
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.getRelative(BlockFace.DOWN).getType() == Material.FIRE || block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
|| block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
// add a minute to cooking time
state++;
}
}
// add an ingredient to the cauldron
public void add(Material ingredient) {
ingredients.add(ingredient);
@@ -78,7 +75,8 @@ public class BCauldron {
if (bcauldron.block.equals(block)) {
ItemStack potion = bcauldron.ingredients.cook(bcauldron.state);
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()
giveItem(player, 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) {
P.p.getServer().getScheduler().runTaskLater(P.p, new Runnable() {
public void run() {
+19 -18
View File
@@ -13,8 +13,6 @@ import org.bukkit.inventory.meta.PotionMeta;
import com.dre.brewery.BRecipe;
import com.dre.brewery.Brew;
public class BIngredients {
public static ArrayList<Material> possibleIngredients = new ArrayList<Material>();
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
@@ -50,7 +48,8 @@ public class BIngredients {
ItemStack potion = new ItemStack(Material.POTION);
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;
String cookedName = null;
BRecipe cookRecipe = getCookRecipe();
@@ -99,7 +98,6 @@ public class BIngredients {
return potion;
}
// returns amount of ingredients
private int getIngredientsCount() {
int count = 0;
@@ -109,7 +107,8 @@ public class BIngredients {
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) {
float quality = 0;
int ingredientQuality = 0;
@@ -122,7 +121,8 @@ public class BIngredients {
cookingQuality = getCookingQuality(recipe);
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()) {
// needs riping in barrel
ageQuality = getAgeQuality(recipe, time);
@@ -148,7 +148,8 @@ public class BIngredients {
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() {
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
@@ -161,7 +162,8 @@ public class BIngredients {
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() {
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
@@ -174,7 +176,8 @@ public class BIngredients {
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) {
BRecipe bestRecipe = getBestRecipe(wood, time);
@@ -186,7 +189,8 @@ public class BIngredients {
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) {
float quality = 10;
int count = 0;
@@ -200,7 +204,8 @@ public class BIngredients {
if (recipe.amountOf(ingredient) == 0) {
// this ingredient doesnt belong into the recipe
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;
}
badStuff++;
@@ -216,9 +221,9 @@ public class BIngredients {
// calculate the quality
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) {
return Math.round(quality);
}
@@ -277,8 +282,4 @@ public class BIngredients {
}
}
}
+6 -5
View File
@@ -12,7 +12,10 @@ import org.bukkit.configuration.ConfigurationSection;
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<String, BPlayer> players = new HashMap<String, BPlayer>();// Players
// name
// and
// BPlayer
private int quality = 0;// = quality of drunkeness * drunkeness
private int drunkeness = 0;// = amount of drunkeness
@@ -29,7 +32,6 @@ public class BPlayer {
players.put(name, this);
}
public static BPlayer get(String name) {
if (!players.isEmpty()) {
if (players.containsKey(name)) {
@@ -80,7 +82,8 @@ public class BPlayer {
if (entity.isOnGround()) {
time--;
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.setZ(Math.random() - 0.5);
player.setVelocity(push);
@@ -121,7 +124,6 @@ public class BPlayer {
}
}
// getter
public int getDrunkeness() {
return drunkeness;
@@ -131,5 +133,4 @@ public class BPlayer {
return Math.round(quality / drunkeness);
}
}
+7 -9
View File
@@ -7,17 +7,19 @@ import java.util.HashMap;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.Material;
public class BRecipe {
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 distillruns;// runs through the brewer
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 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
public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
@@ -43,9 +45,8 @@ public class BRecipe {
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) {
int allowedCountDiff = Math.round((float) ((11.0 - difficulty) * (count / 10.0)));
@@ -117,8 +118,6 @@ public class BRecipe {
return false;
}
// Getter
// how many of a specific ingredient in the recipe
@@ -182,5 +181,4 @@ public class BRecipe {
return alcohol;
}
}
+7 -5
View File
@@ -13,7 +13,8 @@ public class 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 Inventory inventory;
private float time;
@@ -165,7 +166,8 @@ private float time;
// create section only when items in inventory
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);
}
@@ -266,8 +268,7 @@ private float time;
int y = -2;
while (y <= 1) {
// Fence and Netherfence
if(block.getRelative(0,y,0).getTypeId() == 85 ||
block.getRelative(0,y,0).getTypeId() == 113){
if (block.getRelative(0, y, 0).getTypeId() == 85 || block.getRelative(0, y, 0).getTypeId() == 113) {
return (block.getRelative(0, y, 0));
}
y++;
@@ -275,7 +276,8 @@ private float time;
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
public static Block getBrokenBlock(Block spigot) {
spigot = getSpigotOfSign(spigot);
+9 -38
View File
@@ -67,20 +67,17 @@ public class Brew {
}
// returns a Brew by ItemStack
/*public static Brew get(ItemStack item){
if(item.getTypeId() == 373){
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
return get(potionMeta);
}
return null;
}*/
/*
* public static Brew get(ItemStack item){ if(item.getTypeId() == 373){
* PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); return
* get(potionMeta); } return null; }
*/
// returns UID of custom Potion item
public static int getUID(ItemStack item) {
return getUID((PotionMeta) item.getItemMeta());
}
// returns UID of custom Potion meta
public static int getUID(PotionMeta potionMeta) {
if (potionMeta.hasCustomEffect(PotionEffectType.REGENERATION)) {
@@ -100,7 +97,6 @@ public class Brew {
potions.remove(getUID(item));
}
// generate an UID
public static int generateUID() {
int uid = -2;
@@ -125,10 +121,7 @@ public class Brew {
// calculate quality from all of the factors
float quality = (
ingredients.getIngredientQuality(recipe) +
ingredients.getCookingQuality(recipe) +
ingredients.getWoodQuality(recipe,wood) +
ingredients.getAgeQuality(recipe,ageTime));
ingredients.getIngredientQuality(recipe) + ingredients.getCookingQuality(recipe) + ingredients.getWoodQuality(recipe, wood) + ingredients.getAgeQuality(recipe, ageTime));
quality /= 4;
return (int) Math.round(quality);
@@ -143,12 +136,8 @@ public class Brew {
return alcohol;
}
// Distilling section ---------------
// distill all custom potions in the brewer
public static void distillAll(BrewerInventory inv, Integer[] contents) {
int slot = 0;
@@ -171,7 +160,8 @@ public class Brew {
brew.quality = brew.calcQuality(recipe, (byte) 0);
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality);
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) {
ArrayList<String> lore = new ArrayList<String>();
lore.add(brew.distillRuns + " fach Destilliert");
@@ -195,12 +185,8 @@ public class Brew {
slotItem.setItemMeta(potionMeta);
}
// Ageing Section ------------------
public static void age(ItemStack item, float time, byte wood) {
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
Brew brew = get(potionMeta);
@@ -248,22 +234,8 @@ public class Brew {
}
}
public static enum PotionColor {
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);
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);
private final int colorId;
@@ -281,5 +253,4 @@ public class Brew {
}
}
}
+9 -20
View File
@@ -29,7 +29,6 @@ public class P extends JavaPlugin{
public PlayerListener playerListener;
public EntityListener entityListener;
@Override
public void onEnable() {
p = this;
@@ -47,14 +46,12 @@ public class P extends JavaPlugin{
p.getServer().getPluginManager().registerEvents(entityListener, p);
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 1200, 1200);
this.log(this.getDescription().getName() + " enabled!");
}
@Override
public void onDisable() {
// Disable listeners
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);
}
public void readConfig() {
File file = new File(p.getDataFolder(), "config.yml");
@@ -110,7 +106,6 @@ public class P extends JavaPlugin{
// load all Data
public void readData() {
File file = new File(p.getDataFolder(), "data.yml");
if (file.exists()) {
@@ -121,9 +116,8 @@ public class P extends JavaPlugin{
if (section != null) {
// All sections have the UID as name
for (String uid : section.getKeys(false)) {
new Brew(
parseInt(uid), loadIngredients(section.getConfigurationSection(uid+".ingredients")),
section.getInt(uid+".quality",0), section.getInt(uid+".distillRuns",0), (float)section.getDouble(uid+".ageTime",0.0), section.getInt(uid+".alcohol",0));
new Brew(parseInt(uid), loadIngredients(section.getConfigurationSection(uid + ".ingredients")), 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) {
String[] splitted = block.split("/");
if (splitted.length == 4) {
new BCauldron(
getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]),parseInt(splitted[2]),parseInt(splitted[3])),
new BCauldron(getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]), parseInt(splitted[2]), parseInt(splitted[3])),
loadIngredients(section.getConfigurationSection(cauldron + ".ingredients")), section.getInt(cauldron + ".state", 1));
} else {
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
@@ -160,17 +153,16 @@ public class P extends JavaPlugin{
// load itemStacks from invSection
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
if (invSection != null) {
//Map<String,ItemStack> inventory = section.getValues(barrel+"inv");
new Barrel(
getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]),parseInt(splitted[2]),parseInt(splitted[3])),
invSection.getValues(true), (float)section.getDouble(barrel+".time",0.0));
// Map<String,ItemStack> inventory =
// section.getValues(barrel+"inv");
new Barrel(getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]), parseInt(splitted[2]), parseInt(splitted[3])), invSection.getValues(true),
(float) section.getDouble(barrel + ".time", 0.0));
} else {
// errorLog("Inventory of "+section.getCurrentPath()+"."+barrel+" in data.yml is missing");
// Barrel has no inventory
new Barrel(
getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]),parseInt(splitted[2]),parseInt(splitted[3])),
(float)section.getDouble(barrel+".time",0.0));
new Barrel(getServer().getWorld(splitted[0]).getBlockAt(parseInt(splitted[1]), parseInt(splitted[2]), parseInt(splitted[3])), (float) section.getDouble(barrel
+ ".time", 0.0));
}
} else {
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
@@ -195,7 +187,6 @@ public class P extends JavaPlugin{
}
}
// loads BIngredients from ingredient section
public BIngredients loadIngredients(ConfigurationSection config) {
if (config != null) {
@@ -253,8 +244,6 @@ public class P extends JavaPlugin{
return NumberUtils.toInt(string, 0);
}
public class BreweryRunnable implements Runnable {
public BreweryRunnable() {
+4 -3
View File
@@ -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 :(
public static String distort(String words, String from, String to, String[] pre, boolean match, int percent) {
if (from.equalsIgnoreCase("-end")) {
@@ -102,7 +103,8 @@ public class Words {
}
if (words.contains(from)) {
//some characters (*,?) disturb split() which then throws PatternSyntaxException
// some characters (*,?) disturb split() which then throws
// PatternSyntaxException
try {
if (pre == null && percent == 100) {
// 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();
// 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.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);
@@ -31,14 +31,14 @@ 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){
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();
//add ingredient to cauldron that meet the previous contitions
// add ingredient to cauldron that meet the previous
// contitions
if (BIngredients.possibleIngredients.contains(materialInHand)) {
if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) {
if (item.getAmount() > 1) {
@@ -57,7 +57,8 @@ public class PlayerListener implements Listener{
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) {
if (clickedBlock.getData() != 0) {
if (clickedBlock.getData() < 3) {
@@ -68,10 +69,8 @@ public class PlayerListener implements Listener{
}
}
// access a barrel
} else if (clickedBlock.getType() == Material.FENCE ||
clickedBlock.getType() == Material.NETHER_FENCE ||
clickedBlock.getType() == Material.SIGN ||
clickedBlock.getType() == Material.WALL_SIGN){
} 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);
@@ -89,9 +88,6 @@ public class PlayerListener implements Listener{
}
@EventHandler(priority = EventPriority.HIGH)
public void onBrew(BrewEvent event) {
int slot = 0;