mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-25 12:05:16 +01:00
Added Messages and Commands when drinking
This commit is contained in:
parent
d0198c9f04
commit
fa2a4974d8
@ -207,6 +207,10 @@ cauldron:
|
||||
# alcohol: Alkoholgehalt 0-100 in absoluter Menge bei perfektem Getränk (wird dem Spieler hinzugefügt, bei 100 = tot)
|
||||
# lore: Auflistung von zusätzlichem Text auf dem fertigen Trank. (Farbcodes möglich: z.b. &6)
|
||||
# Lore nur für bestimmte Qualität möglich mit + Schlecht, ++ Mittel, +++ Gut, vorne anhängen.
|
||||
# servercommands: Liste von Befehlen ausgeführt vom Server wenn der Trank getrunken wird
|
||||
# playercommands: Liste von Befehlen ausgeführt vom Spieler wenn der Trank getrunken wird
|
||||
# drinkmessage: Nachricht im Chat beim trinken des Trankes
|
||||
# drinktitle: Nachricht als Titel auf dem Bildschirm an den Spieler beim trinken des Trankes
|
||||
# effects: Auflistung Effekt/Level/Dauer Besonderere Trank-Effekte beim Trinken, Dauer in sek.
|
||||
# Mögliche Effekte: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html
|
||||
# Minimale und Maximale Level/Dauer können durch "-" festgelegt werden, Bsp: 'SPEED/1-2/30-40' = Level 1 und 30 sek minimal, Level 2 und 40 sek maximal
|
||||
@ -223,7 +227,7 @@ recipes:
|
||||
- Bedrock/1
|
||||
- Brewery:Weißbier/2
|
||||
# - ExoticGarden:Grape/3
|
||||
- bsp-item/1
|
||||
- bsp-item/4
|
||||
cookingtime: 3
|
||||
distillruns: 2
|
||||
distilltime: 60
|
||||
@ -239,6 +243,12 @@ recipes:
|
||||
- + Riecht eklig
|
||||
- ++ Riecht ganz ok
|
||||
- +++ Riecht richtig gut
|
||||
servercommands:
|
||||
- weather clear
|
||||
playercommands:
|
||||
- homes
|
||||
drinkmessage: Schmeckt toll
|
||||
drinktitle: Wärmt dich von innen
|
||||
effects:
|
||||
- FIRE_RESISTANCE/20
|
||||
- HEAL/1
|
||||
|
@ -208,6 +208,10 @@ cauldron:
|
||||
# alcohol: Absolute amount of alcohol 0-100 in a perfect potion (will be added directly to the player, where 100 means fainting)
|
||||
# lore: List of additional text on the finished brew. (Formatting codes possible: such as &6)
|
||||
# Specific lore for quality possible, using + bad, ++ normal, ++ good, added to the front of the line.
|
||||
# servercommands: List of Commands executed by the Server when drinking the brew
|
||||
# playercommands: List of Commands executed by the Player when drinking the brew
|
||||
# drinkmessage: Chat-message to the Player when drinking the Brew
|
||||
# drinktitle: Title on Screen to the Player when drinking the Brew
|
||||
# effects: List of effect/level/duration Special potion-effect when drinking, duration in sek.
|
||||
# Possible Effects: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html
|
||||
# Level or Duration ranges may be specified with a "-", ex. 'SPEED/1-2/30-40' = lvl 1 and 30 sec at worst and lvl 2 and 40 sec at best
|
||||
@ -224,6 +228,7 @@ recipes:
|
||||
- Bedrock/1
|
||||
- Brewery:Wheatbeer/2
|
||||
# - ExoticGarden:Grape/3
|
||||
- ex-item/4
|
||||
cookingtime: 3
|
||||
distillruns: 2
|
||||
distilltime: 60
|
||||
@ -239,6 +244,12 @@ recipes:
|
||||
- + Smells disgusting
|
||||
- ++ Smells alright
|
||||
- +++ Smells really good
|
||||
servercommands:
|
||||
- weather clear
|
||||
playercommands:
|
||||
- homes
|
||||
drinkmessage: Tastes good
|
||||
drinktitle: Warms you from inside
|
||||
effects:
|
||||
- FIRE_RESISTANCE/20
|
||||
- HEAL/1
|
||||
|
@ -153,6 +153,10 @@ public class BPlayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (brew.hasRecipe()) {
|
||||
brew.getCurrentRecipe().applyDrinkFeatures(player);
|
||||
}
|
||||
|
||||
int brewAlc = drinkEvent.getAddedAlcohol();
|
||||
int quality = drinkEvent.getQuality();
|
||||
List<PotionEffect> effects = getBrewEffects(brew.getEffects(), quality);
|
||||
@ -173,7 +177,7 @@ public class BPlayer {
|
||||
bPlayer.quality += brewAlc;
|
||||
}
|
||||
applyEffects(effects, player, PlayerEffectEvent.EffectType.DRINK);
|
||||
applyEffects(getQualityEffects(drinkEvent.getQuality(), brewAlc), player, PlayerEffectEvent.EffectType.QUALITY);
|
||||
applyEffects(getQualityEffects(quality, brewAlc), player, PlayerEffectEvent.EffectType.QUALITY);
|
||||
|
||||
if (bPlayer.drunkeness > 100) {
|
||||
bPlayer.drinkCap(player);
|
||||
|
@ -524,7 +524,7 @@ public class P extends JavaPlugin {
|
||||
BConfig.reloader = null;
|
||||
}
|
||||
|
||||
public P getInstance() {
|
||||
public static P getInstance() {
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,13 @@ import com.dre.brewery.BIngredients;
|
||||
import com.dre.brewery.Brew;
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import com.dre.brewery.utility.Tuple;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -16,25 +18,37 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class BRecipe {
|
||||
|
||||
private static List<BRecipe> recipes = new ArrayList<>();
|
||||
public static int numConfigRecipes; // The number of recipes in the list that are from config
|
||||
|
||||
// info
|
||||
private String[] name;
|
||||
private boolean saveInData; // If this recipe should be saved in data and loaded again when the server restarts. Applicable to non-config recipes
|
||||
|
||||
// brewing
|
||||
private List<RecipeItem> ingredients = new ArrayList<>(); // Items and amounts
|
||||
private int difficulty; // difficulty to brew the potion, how exact the instruction has to be followed
|
||||
private int cookingTime; // time to cook in cauldron
|
||||
private byte distillruns; // runs through the brewer
|
||||
private int distillTime; // time for one distill run in seconds
|
||||
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 PotionColor color; // color of the destilled/finished potion
|
||||
private int difficulty; // difficulty to brew the potion, how exact the instruction has to be followed
|
||||
|
||||
// outcome
|
||||
private PotionColor color; // color of the distilled/finished potion
|
||||
private int alcohol; // Alcohol in perfect potion
|
||||
private List<Tuple<Integer, String>> lore; // Custom Lore on the Potion. The int is for Quality Lore, 0 = any, 1,2,3 = Bad,Middle,Good
|
||||
|
||||
// drinking
|
||||
private List<BEffect> effects = new ArrayList<>(); // Special Effects when drinking
|
||||
private boolean saveInData; // If this recipe should be saved in data and loaded again when the server restarts. Applicable to non-config recipes
|
||||
private List<String> playercmds; // Commands executed as the player when drinking
|
||||
private List<String> servercmds; // Commands executed as the server when drinking
|
||||
private String drinkMsg; // Message when drinking
|
||||
private String drinkTitle; // Title to show when drinking
|
||||
|
||||
private BRecipe() {
|
||||
}
|
||||
@ -111,6 +125,29 @@ public class BRecipe {
|
||||
|
||||
recipe.lore = loadLore(configSectionRecipes, recipeId + ".lore");
|
||||
|
||||
recipe.servercmds = BUtil.loadCfgStringList(configSectionRecipes, recipeId + ".servercommands");
|
||||
recipe.playercmds = BUtil.loadCfgStringList(configSectionRecipes, recipeId + ".playercommands");
|
||||
|
||||
if (recipe.servercmds != null && !recipe.servercmds.isEmpty()) {
|
||||
for (ListIterator<String> iter = recipe.servercmds.listIterator(); iter.hasNext(); ) {
|
||||
String cmd = iter.next();
|
||||
if (cmd.startsWith("/")) {
|
||||
iter.set(cmd.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (recipe.playercmds != null && !recipe.playercmds.isEmpty()) {
|
||||
for (ListIterator<String> iter = recipe.playercmds.listIterator(); iter.hasNext(); ) {
|
||||
String cmd = iter.next();
|
||||
if (cmd.startsWith("/")) {
|
||||
iter.set(cmd.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recipe.drinkMsg = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinkmessage"));
|
||||
recipe.drinkTitle = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinktitle"));
|
||||
|
||||
List<String> effectStringList = configSectionRecipes.getStringList(recipeId + ".effects");
|
||||
if (effectStringList != null) {
|
||||
for (String effectString : effectStringList) {
|
||||
@ -245,13 +282,7 @@ public class BRecipe {
|
||||
|
||||
@Nullable
|
||||
public static List<Tuple<Integer, String>> loadLore(ConfigurationSection cfg, String path) {
|
||||
List<String> load = null;
|
||||
if (cfg.isString(path)) {
|
||||
load = new ArrayList<>(1);
|
||||
load.add(cfg.getString(path));
|
||||
} else if (cfg.isList(path)) {
|
||||
load = cfg.getStringList(path);
|
||||
}
|
||||
List<String> load = BUtil.loadCfgStringList(cfg, path);
|
||||
if (load != null) {
|
||||
List<Tuple<Integer, String>> lore = new ArrayList<>(load.size());
|
||||
for (String line : load) {
|
||||
@ -380,6 +411,25 @@ public class BRecipe {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void applyDrinkFeatures(Player player) {
|
||||
if (playercmds != null && !playercmds.isEmpty()) {
|
||||
for (String cmd : playercmds) {
|
||||
player.performCommand(cmd.replaceAll("%player_name%", player.getName()));
|
||||
}
|
||||
}
|
||||
if (servercmds != null && !servercmds.isEmpty()) {
|
||||
for (String cmd : servercmds) {
|
||||
P.p.getServer().dispatchCommand(P.p.getServer().getConsoleSender(), cmd.replaceAll("%player_name%", player.getName()));
|
||||
}
|
||||
}
|
||||
if (drinkMsg != null) {
|
||||
player.sendMessage(drinkMsg.replaceAll("%player_name%", player.getName()));
|
||||
}
|
||||
if (drinkTitle != null) {
|
||||
player.sendTitle("", drinkTitle.replaceAll("%player_name%", player.getName()), 10, 90, 30);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Potion from this Recipe with best values. Quality can be set, but will reset to 10 if put in a barrel
|
||||
*
|
||||
@ -478,9 +528,6 @@ public class BRecipe {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Getters
|
||||
|
||||
public List<RecipeItem> getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
@ -548,6 +595,22 @@ public class BRecipe {
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<String> getPlayercmds() {
|
||||
return playercmds;
|
||||
}
|
||||
|
||||
public List<String> getServercmds() {
|
||||
return servercmds;
|
||||
}
|
||||
|
||||
public String getDrinkMsg() {
|
||||
return drinkMsg;
|
||||
}
|
||||
|
||||
public String getDrinkTitle() {
|
||||
return drinkTitle;
|
||||
}
|
||||
|
||||
public List<BEffect> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
@ -752,6 +815,44 @@ public class BRecipe {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Commands that are executed by the player on drinking
|
||||
*/
|
||||
public Builder addPlayerCmds(String... cmds) {
|
||||
if (recipe.playercmds == null) {
|
||||
recipe.playercmds = new ArrayList<>(cmds.length);
|
||||
}
|
||||
Collections.addAll(recipe.playercmds, cmds);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Commands that are executed by the server on drinking
|
||||
*/
|
||||
public Builder addServerCmds(String... cmds) {
|
||||
if (recipe.servercmds == null) {
|
||||
recipe.servercmds = new ArrayList<>(cmds.length);
|
||||
}
|
||||
Collections.addAll(recipe.servercmds, cmds);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Message that is sent to the player in chat when he drinks the brew
|
||||
*/
|
||||
public Builder drinkMsg(String msg) {
|
||||
recipe.drinkMsg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Message that is sent to the player as a small title when he drinks the brew
|
||||
*/
|
||||
public Builder drinkTitle(String title) {
|
||||
recipe.drinkTitle = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addEffects(BEffect... effects) {
|
||||
Collections.addAll(recipe.effects, effects);
|
||||
return this;
|
||||
|
@ -2,6 +2,7 @@ package com.dre.brewery.recipe;
|
||||
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -188,14 +189,7 @@ public abstract class RecipeItem implements Cloneable {
|
||||
List<String> names;
|
||||
List<String> lore;
|
||||
|
||||
List<String> load = null;
|
||||
String path = id + ".material";
|
||||
if (cfg.isString(path)) {
|
||||
load = new ArrayList<>(1);
|
||||
load.add(cfg.getString(path));
|
||||
} else if (cfg.isList(path)) {
|
||||
load = cfg.getStringList(path);
|
||||
}
|
||||
List<String> load = BUtil.loadCfgStringList(cfg, id + ".material");
|
||||
if (load != null && !load.isEmpty()) {
|
||||
if ((materials = loadMaterials(load)) == null) {
|
||||
return null;
|
||||
@ -204,14 +198,7 @@ public abstract class RecipeItem implements Cloneable {
|
||||
materials = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
load = null;
|
||||
path = id + ".name";
|
||||
if (cfg.isString(path)) {
|
||||
load = new ArrayList<>(1);
|
||||
load.add(cfg.getString(path));
|
||||
} else if (cfg.isList(path)) {
|
||||
load = cfg.getStringList(path);
|
||||
}
|
||||
load = BUtil.loadCfgStringList(cfg, id + ".name");
|
||||
if (load != null && !load.isEmpty()) {
|
||||
names = load.stream().map(l -> P.p.color(l)).collect(Collectors.toList());
|
||||
if (P.use1_13) {
|
||||
@ -222,14 +209,7 @@ public abstract class RecipeItem implements Cloneable {
|
||||
names = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
load = null;
|
||||
path = id + ".lore";
|
||||
if (cfg.isString(path)) {
|
||||
load = new ArrayList<>(1);
|
||||
load.add(cfg.getString(path));
|
||||
} else if (cfg.isList(path)) {
|
||||
load = cfg.getStringList(path);
|
||||
}
|
||||
load = BUtil.loadCfgStringList(cfg, id + ".lore");
|
||||
if (load != null && !load.isEmpty()) {
|
||||
lore = load.stream().map(l -> P.p.color(l)).collect(Collectors.toList());
|
||||
} else {
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@ -95,6 +96,37 @@ public class BUtil {
|
||||
effect.apply(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load A List of Strings from config. If found a single String, will convert to List
|
||||
*/
|
||||
@Nullable
|
||||
public static List<String> loadCfgStringList(ConfigurationSection cfg, String path) {
|
||||
if (cfg.isString(path)) {
|
||||
List<String> list = new ArrayList<>(1);
|
||||
list.add(cfg.getString(path));
|
||||
return list;
|
||||
} else if (cfg.isList(path)) {
|
||||
return cfg.getStringList(path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a String from config. If found a List, will return the first String
|
||||
*/
|
||||
@Nullable
|
||||
public static String loadCfgString(ConfigurationSection cfg, String path) {
|
||||
if (cfg.isString(path)) {
|
||||
return cfg.getString(path);
|
||||
} else if (cfg.isList(path)) {
|
||||
List<String> list = cfg.getStringList(path);
|
||||
if (!list.isEmpty()) {
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* **************************************** */
|
||||
/* ********* ********* */
|
||||
/* ********* String Utils ********* */
|
||||
|
Loading…
Reference in New Issue
Block a user