Effects, Hangover, Fixes

This commit is contained in:
Sn0wStorm 2013-05-28 16:25:06 +02:00
parent 5c82b08028
commit 84e37ec676
11 changed files with 553 additions and 235 deletions

View File

@ -1,22 +1,36 @@
# config für Brewery.jar
# Ob der Spieler beim nächsten Einloggen nach starker Trunkenheit am nächsten morgen Zuhause "aufwacht" (Ein home Plugin muss installiert sein!)
enableHome: true
# Art des Nachhause-teleports:
# bed= Spieler wird zu seinem Spawn Bett teleportiert
# SamplePlugin = installiertes home plugin. Unterstützt: ManagerXL. Wenn dies nicht geht:
# 'cmd: home' = /home wird vom spieler ausgelöst. Es sollte kein Verzögerungs, etc. plugin installiert sein!
# 'cmd: spawn' = /spawn wird vom spieler ausgelöst
homeType: 'cmd: home'
# Ob der Spieler nach etwas kürzerem Ausloggen an einem zufälligen Ort "aufwacht" (diese müssen durch /setwake von einem Admin festgelegt werden)
# Der Spieler wacht nur an einem Ort auf, der sich in seiner jetzigen Welt befindet.
# Work in Progress!
enableWake: true
# Ob der Spieler sich bei großer Trunkenheit teilweise nicht einloggen kann und kurz warten muss, da sein Charakter nicht reagiert
enableLoginDisallow: true
# Ob der Spieler sich übertrinken kann und dann in Ohnmacht fällt (gekickt wird)
enableKickOnOverdrink: true
# name: versch. Namen für schlecht/mittel/gut
# ingredients: material/Anzahl
# ingredients: Auflistung von material/Anzahl
# cookingtime: Zeit in Echtminuten die die Zutaten kochen müssen
# distillruns: Wie oft destilliert werden muss 0-10 (0=ohne Destillieren)
# wood: Holz des Fasses 0=alle Holzsorten 1=Birch 2=Oak 3=Jungle 4=Pine
# age: Zeit in Minecraft-Tagen, die das Getränk im Fass reifen muss 0= kein reifen
# color: Farbe des Getränks nach destillieren/reifen
# color: Farbe des Getränks nach destillieren/reifen. DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY
# difficulty: 1-10 Genauigkeit der Einhaltung der Vorgaben (1 = ungenau/einfach 10 = sehr genau/schwer)
# alcohol: Alkoholgehalt 0-100 in absoluter Menge bei perfektem Getränk (wird dem Spieler hinzugefügt, bei 100 = tot)
#cooked: Auflistung ALLER möglichen Zutaten und die daraus entstehenden Tranknamen: (leer für undef.)
#words: Wörter und Buchstaben die bei Trunkenheit ersetzt werden sollen (besondere: -start = an den anfang, -end = ans ende, -random = zufällige position, -space anstatt leerzeichen)
#to: in welches wort es ersetzt werden soll
#pre: Wörter und Buchstaben vor dem gesuchten wort
#match: true = eines der "pre"-Wörter muss vor dem gesuchten Wort stehen, false = keines der "pre" Wörter darf vor dem gesuchten stehen
#alcohol: 1-100 trunkenheit ab der die Wörter ersetzt werden
#percentage: Wahrscheinlichkeit des Ersetzen eines Wortes in Prozent
# effect: Besonderer Trank-Effekt beim Trinken / Dauer in sek. Die Dauer wird bestehenden, gleichen Effekten hinzugefügt. Siehe: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html
recipes:
1:
@ -75,8 +89,9 @@ recipes:
COLOR: ORANGE
difficulty: 4
alcohol: 12
effect: WATER_BREATHING/150
6:
name: Leichter Rum/Goldener Rum/Perfekter Rum
name: Bitterer Rum/Würziger Rum/Goldener Rum
ingredients:
- SUGAR_CANE/14
cookingtime: 5
@ -86,6 +101,7 @@ recipes:
color: DARK_RED
difficulty: 6
alcohol: 30
effect: FIRE_RESISTANCE/100
7:
name: Abgeranzter Vodka/Vodka/Russischer Vodka
ingredients:
@ -96,6 +112,7 @@ recipes:
color: BRIGHT_GREY
difficulty: 4
alcohol: 20
effect: WEAKNESS/15
8:
name: minderwertiger Absinth/Absinth/Starker Absinth
ingredients:
@ -105,6 +122,7 @@ recipes:
color: GREEN
difficulty: 8
alcohol: 45
effect: POISON/10
9:
name: Kartoffelsuppe
ingredients:
@ -113,139 +131,157 @@ recipes:
cookingtime: 3
color: PINK
difficulty: 1
effect: HEAL
#cooked: ALLE möglichen Zutaten und die nach dem Gähren daraus entstehenden Tranknamen: (leer für undefiniert)
cooked:
WHEAT: Getreideferment
SUGAR_CANE: Zuckersud
APPLE: Apfelmost
POTATO_ITEM: Kartoffelmaische
LONG_GRASS: Kräuterbrühe
RED_MUSHROOM:
#words: Wörter und Buchstaben die bei Trunkenheit ersetzt werden sollen
#replace: zu ersetzendes Wort oder Buchstabe. (Besondere: "-space": ersetzt ein Leerzeichen, "-random": Eine zufällige Position, "-start": Ganz am Anfang, "-end": Ganz ans Ende.)
#to: in welches Wort es ersetzt werden soll.
#pre: Wörter und Buchstaben vor dem gesuchten Wort (durch "," getrennt)
#match: true = eines der "pre"-Wörter muss vor dem gesuchten Wort stehen, false = keines der "pre" Wörter darf vor dem gesuchten stehen
#alcohol: 1-100 trunkenheit ab der die Wörter ersetzt werden
#percentage: Wahrscheinlichkeit des Ersetzen eines Wortes in Prozent
words:
- replace: ch
to: sch
pre: u,s,o,a
match: false
alcohol: 10
percentage: 70
- replace: ch
to: sch
pre: u,s,o,a
match: false
alcohol: 10
percentage: 70
- replace: h
to: hh
pre: sch,h,t
match: false
percentage: 60
alcohol: 20
- replace: h
to: hh
pre: sch,h,t
match: false
percentage: 60
alcohol: 20
- replace: u
to: uuh
percentage: 20
- replace: u
to: uuh
percentage: 20
- replace: das
to: dass
percentage: 10
alcohol: 40
- replace: das
to: dass
percentage: 10
alcohol: 40
- replace: '!'
to: '!!'
pre: '!'
match: false
percentage: 90
- replace: '!'
to: '!!'
pre: '!'
match: false
percentage: 90
- replace: '!!'
to: '!!!111!!einself!1!'
pre: '!'
match: false
percentage: 20
alcohol: 70
- replace: '!!'
to: '!!!111!!!einself!1!'
pre: '!'
match: false
percentage: 20
alcohol: 70
- replace: betrunken
to: brhetriunkhn
pre: bist,seid
match: false
percentage: 70
alcohol: 65
- replace: betrunken
to: brhetriunkhn
pre: bist,seid
match: false
percentage: 70
alcohol: 65
- replace: laufen
to: lnhfeeehn
pre: kannst,kannst noch,kannst nicht
match: false
percentage: 80
alcohol: 85
- replace: laufen
to: lnhfeeehn
pre: kannst,kannst noch,kannst nicht
match: false
percentage: 80
alcohol: 85
- replace: gehen
to: hgheehn
pre: kannst,kannst noch,kannst nicht
match: false
percentage: 80
alcohol: 85
- replace: gehen
to: hgheehn
pre: kannst,kannst noch,kannst nicht
match: false
percentage: 80
alcohol: 85
- replace: -space
to: ''
pre: h,g,w
match: true
alcohol: 10
- replace: -space
to: ''
pre: h,g,w
match: true
alcohol: 10
- replace: -space
to: ''
percentage: 50
alcohol: 35
- replace: -space
to: ''
percentage: 50
alcohol: 35
- replace: -space
to: ''
percentage: 10
- replace: -space
to: ''
percentage: 10
- replace: -start
to: dssho
percentage: 15
alcohol: 50
- replace: -start
to: dssho
percentage: 15
alcohol: 50
- replace: -start
to: hhng
percentage: 10
alcohol: 50
- replace: -start
to: hhng
percentage: 10
alcohol: 50
- replace: -random
to: lrg
percentage: 10
- replace: -random
to: lrg
percentage: 10
- replace: -random
to: lu
percentage: 60
alcohol: 40
- replace: -random
to: lu
percentage: 60
alcohol: 40
- replace: -random
to: blub
percentage: 60
alcohol: 70
- replace: -random
to: blub
percentage: 60
alcohol: 70
- replace: -random
to: lerg
percentage: 40
alcohol: 75
- replace: -random
to: lerg
percentage: 40
alcohol: 75
- replace: -random
to: grulg
percentage: 50
alcohol: 80
- replace: -random
to: grulg
percentage: 50
alcohol: 80
- replace: -random
to: ''
percentage: 30
- replace: -random
to: ''
percentage: 30
- replace: -random
to: ''
percentage: 50
alcohol: 50
- replace: -random
to: ''
percentage: 50
alcohol: 50
- replace: -random
to: ''
percentage: 50
alcohol: 70
- replace: -random
to: ''
percentage: 50
alcohol: 70
- replace: -end
to: '!'
percentage: 30
alcohol: 30
- replace: -end
to: '!'
percentage: 30
alcohol: 30
- replace: -end
to: ' *hicks*'
percentage: 70
alcohol: 30
- replace: -end
to: ' *hicks*'
percentage: 70
alcohol: 30

View File

@ -1,5 +1,5 @@
name: Brewery
version: 0.2
version: 0.3
main: com.dre.brewery.P
authors: [Frank Baumann]
softdepend: [Vault]

View File

@ -115,17 +115,19 @@ public class BCauldron {
}
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
int id = 0;
for (BCauldron cauldron : bcauldrons) {
// cauldrons are sorted in worldUUID.randomId
String prefix = cauldron.block.getWorld().getUID().toString() + "." + id;
if (!bcauldrons.isEmpty()) {
int id = 0;
for (BCauldron cauldron : bcauldrons) {
// cauldrons are sorted in worldUUID.randomId
String prefix = cauldron.block.getWorld().getUID().toString() + "." + id;
config.set(prefix + ".block", cauldron.block.getX() + "/" + cauldron.block.getY() + "/" + cauldron.block.getZ());
if (cauldron.state != 1) {
config.set(prefix + ".state", cauldron.state);
config.set(prefix + ".block", cauldron.block.getX() + "/" + cauldron.block.getY() + "/" + cauldron.block.getZ());
if (cauldron.state != 1) {
config.set(prefix + ".state", cauldron.state);
}
cauldron.ingredients.save(config.createSection(prefix + ".ingredients"));
id++;
}
cauldron.ingredients.save(config.createSection(prefix + ".ingredients"));
id++;
}
// copy cauldrons that are not loaded
if (oldData != null){

View File

@ -48,8 +48,7 @@ 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();
@ -60,7 +59,7 @@ public class BIngredients {
// Potion is best with cooking only, can still be destilled, etc.
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe)) / 2.0);
P.p.log("cooked potion has Quality: " + quality);
new Brew(uid, quality, cookRecipe.getAlcohol(), new BIngredients(ingredients, cookedTime));
new Brew(uid, quality, cookRecipe, new BIngredients(ingredients, cookedTime));
cookedName = cookRecipe.getName(quality);
potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));
@ -69,7 +68,7 @@ public class BIngredients {
// new base potion
new Brew(uid, new BIngredients(ingredients, cookedTime));
if (state == 0) {// TESTING sonst 1
if (state == 0) {// TODO sonst 1
cookedName = "Schlammiger Sud";
potion.setDurability(Brew.PotionColor.BLUE.getColorId(false));
} else {
@ -107,6 +106,16 @@ public class BIngredients {
return count;
}
//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;
}
// best recipe for current state of potion, STILL not always returns the
// correct one...
public BRecipe getBestRecipe(byte wood, float time) {
@ -169,7 +178,7 @@ public class BIngredients {
// Check if best recipe needs to be destilled
if (bestRecipe != null) {
if (bestRecipe.getDistillRuns() != 0) {
if (bestRecipe.needsDistilling()) {
return bestRecipe;
}
}

View File

@ -7,6 +7,8 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.entity.Player;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import org.bukkit.Location;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.configuration.ConfigurationSection;
import com.dre.brewery.Brew;
@ -16,6 +18,8 @@ public class BPlayer {
private int quality = 0;// = quality of drunkeness * drunkeness
private int drunkeness = 0;// = amount of drunkeness
private boolean passedOut = false;// if kicked because of drunkeness
private int offlineDrunk = 0;// drunkeness when gone offline
private Vector push = new Vector(0, 0, 0);
private int time = 20;
@ -23,9 +27,11 @@ public class BPlayer {
}
// reading from file
public BPlayer(String name, int quality, int drunkeness) {
public BPlayer(String name, int quality, int drunkeness, int offlineDrunk, Boolean passedOut) {
this.quality = quality;
this.drunkeness = drunkeness;
this.offlineDrunk = offlineDrunk;
this.passedOut = passedOut;
players.put(name, this);
}
@ -38,18 +44,54 @@ public class BPlayer {
return null;
}
public String getPlayerName() {
for (Map.Entry<String,BPlayer> entry : players.entrySet()) {
if (entry.getValue() == this) {
return entry.getKey();
}
}
return null;
}
public Player getPlayer() {
return org.bukkit.Bukkit.getPlayer(getPlayerName());
}
public static Player getPlayer(String name) {
return org.bukkit.Bukkit.getPlayer(name);
}
// returns true if drinking was successful
public static boolean drink(int uid, String name) {
public static boolean drink(int uid, Player player) {
Brew brew = Brew.get(uid);
if (brew != null) {
BPlayer bPlayer = get(name);
BPlayer bPlayer = get(player.getName());
if (bPlayer == null) {
bPlayer = new BPlayer();
players.put(name, bPlayer);
players.put(player.getName(), bPlayer);
}
bPlayer.drunkeness += brew.getAlcohol();
bPlayer.quality += brew.getQuality() * brew.getAlcohol();
P.p.log(name + " ist nun " + bPlayer.drunkeness + "% betrunken, mit einer Qualität von " + bPlayer.getQuality());
bPlayer.drunkeness += brew.calcAlcohol();
bPlayer.quality += brew.getQuality() * brew.calcAlcohol();
if (bPlayer.drunkeness <= 100) {
if (brew.getEffect() != null) {
int duration = (brew.getEffectDur() / 8) * brew.getQuality() * 20;
int amplifier = brew.getQuality() / 3;
PotionEffectType type = PotionEffectType.getByName(brew.getEffect());
type.createEffect(duration, amplifier).apply(player);
}
} else {
if (P.p.getConfig().getBoolean("enableKickOnOverdrink", false)) {
bPlayer.passOut(player);
} else {
bPlayer.quality = bPlayer.getQuality() * 100;
bPlayer.drunkeness = 100;
P.p.msg(player, "Du kannst einfach nicht mehr trinken und spuckst es wieder aus!");
}
}
P.p.log(player.getName() + " ist nun " + bPlayer.drunkeness + "% betrunken, mit einer Qualität von " + bPlayer.getQuality());
return true;
}
return false;
@ -98,14 +140,130 @@ public class BPlayer {
}
}
public void passOut(Player player) {
player.kickPlayer("Du hast zu viel getrunken und bist in Ohnmacht gefallen!");
offlineDrunk = drunkeness;
passedOut = true;
}
// can the player login or is he too drunk
public int canJoin() {
if (drunkeness <= 30) {
return 0;
}
if (P.p.getConfig().getBoolean("enableLoginDisallow", false) == false) {
if (drunkeness <= 100) {
return 0;
} else {
return 3;
}
}
if (drunkeness <= 50) {
if ((Math.random() > 0.3 && !passedOut) || Math.random() > 0.5) {
return 0;
} else {
return 1;
}
}
if (drunkeness <= 70) {
if(!passedOut) {
if (Math.random() > 0.5) {
return 0;
} else {
return 1;
}
}
}
if (drunkeness <= 100) {
if (!passedOut) {
if (Math.random() > 0.8) {
return 0;
} else {
return 2;
}
}
}
return 3;
}
// player joins
public void join(final Player player) {
if (offlineDrunk == 0) {
return;
}
// delayed login event as the player is not fully accessible pre login
P.p.getServer().getScheduler().runTaskLater(P.p, new Runnable() {
public void run() {
login(player);
}
}, 1L);
}
// he is having a hangover
public void login(final Player player) {
if (drunkeness < 10) {
if (offlineDrunk > 60) {
if (P.p.getConfig().getBoolean("enableHome", false)) {
goHome(player);
}
}
} else if (offlineDrunk - drunkeness >= 20) {
// do some random teleport later
}
hangoverEffects(player);
// wird der spieler noch gebraucht?
players.remove(player.getName());
offlineDrunk = 0;
}
public void goHome(final Player player) {
String homeType = P.p.getConfig().getString("homeType", null);
if (homeType != null) {
Location home = null;
if (homeType.equalsIgnoreCase("bed")) {
home = player.getBedSpawnLocation();
} else if (homeType.equalsIgnoreCase("ManagerXL")) {
if (com.dre.managerxl.MPlayer.get(player.getName()) != null) {
home = com.dre.managerxl.MPlayer.get(player.getName()).getHome();
}
} else if (homeType.startsWith("cmd: ")) {
player.performCommand(homeType.substring(5));
} else if (homeType.startsWith("cmd:")) {
player.performCommand(homeType.substring(4));
} else {
P.p.errorLog("'homeType: " + homeType + "' unknown!");
}
if (home != null) {
player.teleport(home);
}
}
}
public void hangoverEffects(final Player player) {
int duration = offlineDrunk * 50 * getHangoverQuality();
int amplifier = getHangoverQuality() / 3;
PotionEffectType.getByName("SLOW").createEffect(duration, amplifier).apply(player);
PotionEffectType.getByName("HUNGER").createEffect(duration, amplifier).apply(player);
}
// decreasing drunkeness over time
public static void onUpdate() {
if (!players.isEmpty()) {
int soberPerMin = 2;
for (String name : players.keySet()) {
BPlayer bplayer = players.get(name);
bplayer.quality -= bplayer.getQuality();
bplayer.drunkeness -= 2;
if (bplayer.drunkeness <= 0) {
bplayer.quality -= bplayer.getQuality() * soberPerMin;
bplayer.drunkeness -= soberPerMin;
if (bplayer.drunkeness > 0) {
if (bplayer.offlineDrunk == 0) {
if (getPlayer(name) == null) {// working offline check?
bplayer.offlineDrunk = bplayer.drunkeness;
}
}
} else if (bplayer.drunkeness <= (-1) * bplayer.offlineDrunk) {
players.remove(name);
}
}
@ -114,11 +272,15 @@ public class BPlayer {
// save all data
public static void save(ConfigurationSection config) {
if (!players.isEmpty()) {
for (String name : players.keySet()) {
ConfigurationSection section = config.createSection(name);
section.set("quality", players.get(name).quality);
section.set("drunk", players.get(name).drunkeness);
for (String name : players.keySet()) {
ConfigurationSection section = config.createSection(name);
section.set("quality", players.get(name).quality);
section.set("drunk", players.get(name).drunkeness);
if (players.get(name).offlineDrunk != 0) {
section.set("offDrunk", players.get(name).offlineDrunk);
}
if (players.get(name).passedOut) {
section.set("passedOut", players.get(name).passedOut);
}
}
}
@ -132,4 +294,13 @@ public class BPlayer {
return Math.round(quality / drunkeness);
}
// opposite of quality
public int getHangoverQuality() {
return -getQuality() + 10;
}
public int getHangoverProgress() {
return offlineDrunk + drunkeness;
}
}

View File

@ -10,17 +10,16 @@ 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 alcohol;// Vol% of alcohol in perfect potion
private int difficulty;// difficulty to brew the potion, how exact the instruction has to be followed
private int alcohol;// Alcohol in perfect potion
private String effect;// Special Effect
private int effectDur;// Duration of the special effect
public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
String[] name = configSectionRecipes.getString(recipeId + ".name").split("/");
@ -43,10 +42,18 @@ public class BRecipe {
this.color = configSectionRecipes.getString(recipeId + ".color");
this.difficulty = configSectionRecipes.getInt(recipeId + ".difficulty");
this.alcohol = configSectionRecipes.getInt(recipeId + ".alcohol");
String effectString = configSectionRecipes.getString(recipeId + ".effect");
if (effectString != null) {
String[] effectSplit = effectString.split("/");
this.effect = effectSplit[0];
if (effectSplit.length > 1) {
this.effectDur = P.p.parseInt(effectSplit[1]);
}
}
}
// 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)));
@ -93,9 +100,9 @@ public class BRecipe {
public boolean needsDistilling() {
if (distillruns == 0) {
return true;
return false;
}
return false;
return true;
}
public boolean needsToAge() {
@ -118,6 +125,7 @@ public class BRecipe {
return false;
}
// Getter
// how many of a specific ingredient in the recipe
@ -181,4 +189,12 @@ public class BRecipe {
return alcohol;
}
public String getEffect() {
return effect;
}
public int getEffectDur() {
return effectDur;
}
}

View File

@ -152,39 +152,38 @@ public class Barrel {
// Saves all data
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
int id = 0;
for (Barrel barrel : barrels) {
// barrels are sorted in worldUUID.randomId
String prefix = barrel.spigot.getWorld().getUID().toString() + "." + id;
// block: x/y/z
config.set(prefix + ".spigot", barrel.spigot.getX() + "/" + barrel.spigot.getY() + "/" + barrel.spigot.getZ());
if (!barrels.isEmpty()) {
int id = 0;
for (Barrel barrel : barrels) {
// barrels are sorted in worldUUID.randomId
String prefix = barrel.spigot.getWorld().getUID().toString() + "." + id;
// block: x/y/z
config.set(prefix + ".spigot", barrel.spigot.getX() + "/" + barrel.spigot.getY() + "/" + barrel.spigot.getZ());
// not saving the inventory if there is none, or it is empty
if (barrel.inventory != null) {
int slot = 0;
ItemStack item = null;
ConfigurationSection invConfig = null;
while (slot < barrel.inventory.getSize()) {
item = barrel.inventory.getItem(slot);
if (item != null) {
if (invConfig == null) {
if (barrel.time != 0) {
//time is only needed when there are items in inventory
config.set(prefix + ".time", barrel.time);
if (barrel.inventory != null) {
int slot = 0;
ItemStack item = null;
ConfigurationSection invConfig = null;
while (slot < barrel.inventory.getSize()) {
item = barrel.inventory.getItem(slot);
if (item != null) {
if (invConfig == null) {
if (barrel.time != 0) {
config.set(prefix + ".time", barrel.time);
}
invConfig = config.createSection(prefix + ".inv");
}
// create section only when items in inventory
invConfig = config.createSection(prefix + ".inv");
// ItemStacks are configurationSerializeable, makes them
// really easy to save
invConfig.set(slot + "", item);
}
// ItemStacks are configurationSerializeable, makes them
// really easy to save
invConfig.set(slot + "", item);
slot++;
}
slot++;
}
}
id++;
id++;
}
}
// also save barrels that are not loaded
if (oldData != null){

View File

@ -3,6 +3,7 @@ package com.dre.brewery;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
@ -23,7 +24,7 @@ public class Brew {
private int quality;
private int distillRuns;
private float ageTime;
private int alcohol;
private BRecipe currentRecipe;
public Brew(int uid, BIngredients ingredients) {
this.ingredients = ingredients;
@ -31,20 +32,20 @@ public class Brew {
}
// quality already set
public Brew(int uid, int quality, int alcohol, BIngredients ingredients) {
public Brew(int uid, int quality, BRecipe recipe, BIngredients ingredients) {
this.ingredients = ingredients;
this.quality = quality;
this.alcohol = calcAlcohol(alcohol);
this.currentRecipe = recipe;
potions.put(uid, this);
}
// loading from file
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, int alcohol) {
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, String recipe) {
this.ingredients = ingredients;
this.quality = quality;
this.distillRuns = distillRuns;
this.ageTime = ageTime;
this.alcohol = alcohol;
this.currentRecipe = BIngredients.getRecipeByName(recipe);
potions.put(uid, this);
}
@ -92,7 +93,7 @@ public class Brew {
return 0;
}
// remove potion from map (drinking, despawning, should be more!)
// remove potion from file (drinking, despawning, should be more!)
public static void remove(ItemStack item) {
potions.remove(getUID(item));
}
@ -107,15 +108,16 @@ public class Brew {
}
// calculate alcohol from recipe
public int calcAlcohol(int alc) {
if (distillRuns == 0) {
distillRuns = 1;
public int calcAlcohol() {
if (currentRecipe != null) {
int alc = currentRecipe.getAlcohol();
alc *= ((float) quality / 10.0);
if (distillRuns > 1) {
alc *= (float) distillRuns / 2.0;
}
return alc;
}
alc *= ((float) quality / 10.0);
if (distillRuns > 1) {
alc *= (float) distillRuns / 2.0;
}
return alc;
return 0;
}
// calculating quality
@ -136,9 +138,19 @@ public class Brew {
return quality;
}
// return prev calculated alcohol
public int getAlcohol() {
return alcohol;
// return special effect
public String getEffect() {
if (currentRecipe != null) {
return currentRecipe.getEffect();
}
return null;
}
public int getEffectDur() {
if (currentRecipe != null) {
return currentRecipe.getEffectDur();
}
return 0;
}
// Distilling section ---------------
@ -165,19 +177,18 @@ 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>();
List<String> lore = new ArrayList<String>();
lore.add(brew.distillRuns + " fach Destilliert");
potionMeta.setLore(lore);
}
brew.alcohol = brew.calcAlcohol(recipe.getAlcohol());
brew.currentRecipe = recipe;
potionMeta.setDisplayName(recipe.getName(brew.quality));
// if the potion should be further distillable
if (recipe.getDistillRuns() > 1) {
if (recipe.getDistillRuns() > 1 && brew.distillRuns <= 5) {
slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(true));
} else {
slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
@ -204,9 +215,37 @@ public class Brew {
if (!recipe.needsDistilling() || brew.distillRuns > 0) {
brew.quality = brew.calcQuality(recipe, wood);
brew.alcohol = brew.calcAlcohol(recipe.getAlcohol());
brew.currentRecipe = recipe;
P.p.log("Final " + recipe.getName(5) + " has Quality: " + brew.quality);
if (brew.ageTime >= 2) {
List<String> lore;
String newLore;
int index = 0;
if (brew.ageTime < 201) {
newLore = (int) Math.floor(brew.ageTime) + " Jahre Fassgereift";
} else {
newLore = "Hunderte Jahre Fassgereift";
}
if (potionMeta.hasLore()) {
lore = potionMeta.getLore();
while (index < lore.size()) {
String existingLore = lore.get(index);
if (existingLore.contains("Jahre Fassgereift")) {
lore.set(index, newLore);
break;
}
index++;
}
} else {
lore = new ArrayList<String>();
lore.add(newLore);
}
potionMeta.setLore(lore);
}
potionMeta.setDisplayName(recipe.getName(brew.quality));
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
item.setItemMeta(potionMeta);
@ -231,8 +270,8 @@ public class Brew {
if (brew.ageTime != 0) {
idConfig.set("ageTime", brew.ageTime);
}
if (brew.alcohol != 0) {
idConfig.set("alcohol", brew.alcohol);
if (brew.currentRecipe != null) {
idConfig.set("recipe", brew.currentRecipe.getName(5));
}
// save the ingredients
brew.ingredients.save(idConfig.createSection("ingredients"));
@ -240,7 +279,18 @@ 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;

View File

@ -21,6 +21,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import java.io.IOException;
public class P extends JavaPlugin {
@ -105,8 +106,8 @@ public class P extends JavaPlugin {
configSection = config.getConfigurationSection("cooked");
if (configSection != null) {
for (String ingredient : configSection.getKeys(false)) {
BIngredients.cookedNames.put(Material.getMaterial(ingredient.toUpperCase()), (configSection.getString(ingredient)));
BIngredients.possibleIngredients.add(Material.getMaterial(ingredient.toUpperCase()));
BIngredients.cookedNames.put(Material.matchMaterial(ingredient), (configSection.getString(ingredient)));
BIngredients.possibleIngredients.add(Material.matchMaterial(ingredient));
}
}
@ -126,8 +127,13 @@ 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));
BIngredients ingredients = loadIngredients(section.getConfigurationSection(uid + ".ingredients"));
int quality = section.getInt(uid + ".quality", 0);
int distillRuns = section.getInt(uid + ".distillRuns", 0);
float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
String recipe = section.getString(uid + ".recipe", null);
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, recipe);
}
}
@ -136,7 +142,12 @@ public class P extends JavaPlugin {
if (section != null) {
// keys have players name
for (String name : section.getKeys(false)) {
new BPlayer(name, section.getInt(name + ".quality"), section.getInt(name + ".drunk"));
int quality = section.getInt(name + ".quality");
int drunk = section.getInt(name + ".drunk");
int offDrunk = section.getInt(name + ".offDrunk", 0);
boolean passedOut = section.getBoolean(name + ".passedOut", false);
new BPlayer(name, quality, drunk, offDrunk, passedOut);
}
}
@ -184,8 +195,11 @@ public class P extends JavaPlugin {
if (block != null) {
String[] splitted = block.split("/");
if (splitted.length == 3) {
new BCauldron(getServer().getWorld(UUID.fromString(uuid)).getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2])),
loadIngredients(section.getConfigurationSection(cauldron + ".ingredients")), section.getInt(cauldron + ".state", 1));
Block worldBlock = getServer().getWorld(UUID.fromString(uuid)).getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
BIngredients ingredients = loadIngredients(section.getConfigurationSection(cauldron + ".ingredients"));
int state = section.getInt(cauldron + ".state", 1);
new BCauldron(worldBlock, ingredients, state);
} else {
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
}
@ -206,15 +220,13 @@ public class P extends JavaPlugin {
if (splitted.length == 3) {
// load itemStacks from invSection
ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
Block block = getServer().getWorld(UUID.fromString(uuid)).getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
float time = (float) section.getDouble(barrel + ".time", 0.0);
if (invSection != null) {
new Barrel(getServer().getWorld(UUID.fromString(uuid)).getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2])),
invSection.getValues(true), (float) section.getDouble(barrel + ".time", 0.0));
new Barrel(block, invSection.getValues(true), time);
} else {
// Barrel has no inventory
new Barrel(getServer().getWorld(UUID.fromString(uuid)).getBlockAt(parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2])),
(float) section.getDouble(barrel + ".time", 0.0));
new Barrel(block, time);
}
} else {
errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
@ -248,11 +260,11 @@ public class P extends JavaPlugin {
if (!Brew.potions.isEmpty()) {
Brew.save(configFile.createSection("Brew"));
}
if (!BCauldron.bcauldrons.isEmpty()) {
if (!BCauldron.bcauldrons.isEmpty() || oldData.contains("BCauldron")) {
BCauldron.save(configFile.createSection("BCauldron"), oldData.getConfigurationSection("BCauldron"));
}
if (!Barrel.barrels.isEmpty()) {
if (!Barrel.barrels.isEmpty() || oldData.contains("Barrel")) {
Barrel.save(configFile.createSection("Barrel"), oldData.getConfigurationSection("Barrel"));
}

View File

@ -68,9 +68,9 @@ public class Words {
}
if (!words.isEmpty()) {
String message = event.getMessage();
for (Words w : words) {
if (w.alcohol <= bPlayer.getDrunkeness()) {
message = distort(message, w.from, w.to, w.pre, w.match, w.percentage);
for (Words word : words) {
if (word.alcohol <= bPlayer.getDrunkeness()) {
message = word.distort(message);
}
}
event.setMessage(message);
@ -81,7 +81,7 @@ public class Words {
// 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) {
public String distort(String words) {
if (from.equalsIgnoreCase("-end")) {
from = words;
to = words + to;
@ -106,7 +106,7 @@ public class Words {
// some characters (*,?) disturb split() which then throws
// PatternSyntaxException
try {
if (pre == null && percent == 100) {
if (pre == null && percentage == 100) {
// All occurences of "from" need to be replaced
return words.replaceAll(from, to);
}
@ -129,7 +129,7 @@ public class Words {
newWords = newWords + part;
// check if the part ends with correct string
if (doesPreMatch(part, pre, match) && Math.random() * 100.0 <= percent) {
if (doesPreMatch(part) && Math.random() * 100.0 <= percentage) {
// add replacement
newWords = newWords + to;
} else {
@ -155,7 +155,7 @@ public class Words {
return words;
}
public static boolean doesPreMatch(String part, String[] pre, boolean match) {
public boolean doesPreMatch(String part) {
boolean isBefore = !match;
if (pre != null) {
for (String pr : pre) {

View File

@ -5,6 +5,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -93,7 +94,7 @@ public class PlayerListener implements Listener {
if (item != null) {
if (item.getType() == Material.POTION) {
if (item.hasItemMeta()) {
if (BPlayer.drink(Brew.getUID(item), event.getPlayer().getName())) {
if (BPlayer.drink(Brew.getUID(item), event.getPlayer())) {
if (event.getPlayer().getGameMode() != org.bukkit.GameMode.CREATIVE) {
Brew.remove(item);
}
@ -118,4 +119,26 @@ public class PlayerListener implements Listener {
Words.playerChat(event);
}
}
// player joins while passed out
@EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(PlayerLoginEvent event) {
final Player player = event.getPlayer();
BPlayer bplayer = BPlayer.get(player.getName());
if (bplayer != null) {
switch (bplayer.canJoin()) {
case 0:
bplayer.join(player);
return;
case 1:
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Dein Charakter ist angetrunken und reagiert nicht. Versuch es noch einmal!");
return;
case 2:
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Dein Charakter ist betrunken und reagiert nicht. Versuch es in ein paar Minuten noch einmal!");
return;
case 3:
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Dein Charakter ist sturzbesoffen und ohne Besinnung. Versuch es morgen noch einmal!");
}
}
}
}