diff --git a/resources/config/v13/de/config.yml b/resources/config/v13/de/config.yml index 686080d..e8821a8 100644 --- a/resources/config/v13/de/config.yml +++ b/resources/config/v13/de/config.yml @@ -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 diff --git a/resources/config/v13/en/config.yml b/resources/config/v13/en/config.yml index fdd0ed9..4da7fce 100644 --- a/resources/config/v13/en/config.yml +++ b/resources/config/v13/en/config.yml @@ -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 diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index cb73347..77e0d16 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -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 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); diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 54a68f6..d1c2d4e 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -524,7 +524,7 @@ public class P extends JavaPlugin { BConfig.reloader = null; } - public P getInstance() { + public static P getInstance() { return p; } diff --git a/src/com/dre/brewery/recipe/BRecipe.java b/src/com/dre/brewery/recipe/BRecipe.java index 6c620f1..00ac4b1 100644 --- a/src/com/dre/brewery/recipe/BRecipe.java +++ b/src/com/dre/brewery/recipe/BRecipe.java @@ -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 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 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> lore; // Custom Lore on the Potion. The int is for Quality Lore, 0 = any, 1,2,3 = Bad,Middle,Good + + // drinking private List 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 playercmds; // Commands executed as the player when drinking + private List 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 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 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 effectStringList = configSectionRecipes.getStringList(recipeId + ".effects"); if (effectStringList != null) { for (String effectString : effectStringList) { @@ -245,13 +282,7 @@ public class BRecipe { @Nullable public static List> loadLore(ConfigurationSection cfg, String path) { - List 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 load = BUtil.loadCfgStringList(cfg, path); if (load != null) { List> 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 getIngredients() { return ingredients; } @@ -548,6 +595,22 @@ public class BRecipe { return list; } + public List getPlayercmds() { + return playercmds; + } + + public List getServercmds() { + return servercmds; + } + + public String getDrinkMsg() { + return drinkMsg; + } + + public String getDrinkTitle() { + return drinkTitle; + } + public List 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; diff --git a/src/com/dre/brewery/recipe/RecipeItem.java b/src/com/dre/brewery/recipe/RecipeItem.java index 6ff6d67..9f1b216 100644 --- a/src/com/dre/brewery/recipe/RecipeItem.java +++ b/src/com/dre/brewery/recipe/RecipeItem.java @@ -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 names; List lore; - List 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 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 { diff --git a/src/com/dre/brewery/utility/BUtil.java b/src/com/dre/brewery/utility/BUtil.java index 8ba4ee5..9ce5ad2 100644 --- a/src/com/dre/brewery/utility/BUtil.java +++ b/src/com/dre/brewery/utility/BUtil.java @@ -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 loadCfgStringList(ConfigurationSection cfg, String path) { + if (cfg.isString(path)) { + List 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 list = cfg.getStringList(path); + if (!list.isEmpty()) { + return list.get(0); + } + } + return null; + } + /* **************************************** */ /* ********* ********* */ /* ********* String Utils ********* */