From dda1c6fb0af32a6559f7a4b6c5578d12e5a202c3 Mon Sep 17 00:00:00 2001 From: Sebi Date: Fri, 8 May 2020 15:48:36 +0200 Subject: [PATCH] Fix git omitting half of the changes --- src/com/dre/brewery/recipe/BRecipe.java | 45 +++---------- src/com/dre/brewery/utility/StringParser.java | 66 ++++++++++++------- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/com/dre/brewery/recipe/BRecipe.java b/src/com/dre/brewery/recipe/BRecipe.java index d17639d..d76ea0b 100644 --- a/src/com/dre/brewery/recipe/BRecipe.java +++ b/src/com/dre/brewery/recipe/BRecipe.java @@ -128,36 +128,10 @@ public class BRecipe { return null; } - // parsers can be created inline: - StringParser loreParser = new StringParser() { - @Override - public Object parse(String line) { - line = P.p.color(line); - int plus = 0; - if (line.startsWith("+++")) { - plus = 3; - line = line.substring(3); - } else if (line.startsWith("++")) { - plus = 2; - line = line.substring(2); - } else if (line.startsWith("+")) { - plus = 1; - line = line.substring(1); - } - if (line.startsWith(" ")) { - line = line.substring(1); - } - if (!line.startsWith("§")) { - line = "§9" + line; - } - return new Tuple<>(plus, line); - } - }; - recipe.lore = loadQualityStringList(configSectionRecipes, recipeId + ".lore", loreParser); + recipe.lore = loadQualityStringList(configSectionRecipes, recipeId + ".lore", StringParser.loreParser); - // or parsers can be predefined in the interface itself: - recipe.servercmds = loadQualityStringList(configSectionRecipes, recipeId + ".servercommands", StringParser.cmdParser()); - recipe.playercmds = loadQualityStringList(configSectionRecipes, recipeId + ".playercommands", StringParser.cmdParser()); + recipe.servercmds = loadQualityStringList(configSectionRecipes, recipeId + ".servercommands", StringParser.cmdParser); + recipe.playercmds = loadQualityStringList(configSectionRecipes, recipeId + ".playercommands", StringParser.cmdParser); recipe.drinkMsg = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinkmessage")); recipe.drinkTitle = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinktitle")); @@ -318,13 +292,14 @@ public class BRecipe { } /** - * Load a list of strings from a ConfigurationSection and parse preceded pluses. + * Load a list of strings from a ConfigurationSection and parse it accordingly using a parser. */ @Nullable public static List> loadQualityStringList(ConfigurationSection cfg, String path, StringParser p) { List load = BUtil.loadCfgStringList(cfg, path); if (load != null) { List> list = new ArrayList<>(load.size()); + // create fallback parser, so passing null will convert the String to a Touple without furter processing. if (p == null){ p = new StringParser() { @Override @@ -453,12 +428,12 @@ public class BRecipe { public void applyDrinkFeatures(Player player, int quality) { if (playercmds != null && !playercmds.isEmpty()) { - for (String cmd : playercmds) { + for (String cmd : getPlayercmdsForQuality(quality)) { player.performCommand(BUtil.applyPlaceholders(cmd, player.getName(), quality)); } } if (servercmds != null && !servercmds.isEmpty()) { - for (String cmd : servercmds) { + for (String cmd : getServercmdsForQuality(quality)) { P.p.getServer().dispatchCommand(P.p.getServer().getConsoleSender(), BUtil.applyPlaceholders(cmd, player.getName(), quality)); } } @@ -905,9 +880,8 @@ public class BRecipe { public Builder addPlayerCmds(String... cmds) { ArrayList> playercmds = new ArrayList>(cmds.length); - StringParser p = StringParser.cmdParser(); for (String cmd : cmds) { - playercmds.add((Tuple) p.parse(cmd)); + playercmds.add((Tuple) StringParser.cmdParser.parse(cmd)); } if (recipe.playercmds == null) { recipe.playercmds = playercmds; @@ -923,9 +897,8 @@ public class BRecipe { public Builder addServerCmds(String... cmds) { ArrayList> servercmds = new ArrayList>(cmds.length); - StringParser p = StringParser.cmdParser(); for (String cmd : cmds) { - servercmds.add((Tuple) p.parse(cmd)); + servercmds.add((Tuple) StringParser.cmdParser.parse(cmd)); } if (recipe.servercmds == null) { recipe.servercmds = servercmds; diff --git a/src/com/dre/brewery/utility/StringParser.java b/src/com/dre/brewery/utility/StringParser.java index 62f36f5..e37b285 100644 --- a/src/com/dre/brewery/utility/StringParser.java +++ b/src/com/dre/brewery/utility/StringParser.java @@ -6,28 +6,50 @@ public interface StringParser { public Object parse(String line); - public static StringParser cmdParser() { - return new StringParser() { - @Override - public Object parse(String line) { - line = P.p.color(line); - int plus = 0; - if (line.startsWith("+++")) { - plus = 3; - line = line.substring(3); - } else if (line.startsWith("++")) { - plus = 2; - line = line.substring(2); - } else if (line.startsWith("+")) { - plus = 1; - line = line.substring(1); - } - if (line.startsWith("/")) { - line = line.substring(1); - } - return new Tuple<>(plus, line); + public static StringParser cmdParser = new StringParser() { + @Override + public Object parse(String line) { + line = P.p.color(line); + int plus = 0; + if (line.startsWith("+++")) { + plus = 3; + line = line.substring(3); + } else if (line.startsWith("++")) { + plus = 2; + line = line.substring(2); + } else if (line.startsWith("+")) { + plus = 1; + line = line.substring(1); } - }; - } + if (line.startsWith("/")) { + line = line.substring(1); + } + return new Tuple(plus, line); + } + }; + public static StringParser loreParser = new StringParser() { + @Override + public Object parse(String line) { + line = P.p.color(line); + int plus = 0; + if (line.startsWith("+++")) { + plus = 3; + line = line.substring(3); + } else if (line.startsWith("++")) { + plus = 2; + line = line.substring(2); + } else if (line.startsWith("+")) { + plus = 1; + line = line.substring(1); + } + if (line.startsWith(" ")) { + line = line.substring(1); + } + if (!line.startsWith("§")) { + line = "§9" + line; + } + return new Tuple(plus, line); + } + }; }