Fix git omitting half of the changes

This commit is contained in:
Sebi
2020-05-08 15:48:36 +02:00
parent aab880e437
commit dda1c6fb0a
2 changed files with 53 additions and 58 deletions
+9 -36
View File
@@ -128,36 +128,10 @@ public class BRecipe {
return null; return null;
} }
// parsers can be created inline: recipe.lore = loadQualityStringList(configSectionRecipes, recipeId + ".lore", StringParser.loreParser);
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);
// or parsers can be predefined in the interface itself: recipe.servercmds = loadQualityStringList(configSectionRecipes, recipeId + ".servercommands", StringParser.cmdParser);
recipe.servercmds = loadQualityStringList(configSectionRecipes, recipeId + ".servercommands", StringParser.cmdParser()); recipe.playercmds = loadQualityStringList(configSectionRecipes, recipeId + ".playercommands", StringParser.cmdParser);
recipe.playercmds = loadQualityStringList(configSectionRecipes, recipeId + ".playercommands", StringParser.cmdParser());
recipe.drinkMsg = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinkmessage")); recipe.drinkMsg = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinkmessage"));
recipe.drinkTitle = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinktitle")); 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 @Nullable
public static List<Tuple<Integer, String>> loadQualityStringList(ConfigurationSection cfg, String path, StringParser p) { public static List<Tuple<Integer, String>> loadQualityStringList(ConfigurationSection cfg, String path, StringParser p) {
List<String> load = BUtil.loadCfgStringList(cfg, path); List<String> load = BUtil.loadCfgStringList(cfg, path);
if (load != null) { if (load != null) {
List<Tuple<Integer, String>> list = new ArrayList<>(load.size()); List<Tuple<Integer, String>> list = new ArrayList<>(load.size());
// create fallback parser, so passing null will convert the String to a Touple without furter processing.
if (p == null){ if (p == null){
p = new StringParser() { p = new StringParser() {
@Override @Override
@@ -453,12 +428,12 @@ public class BRecipe {
public void applyDrinkFeatures(Player player, int quality) { public void applyDrinkFeatures(Player player, int quality) {
if (playercmds != null && !playercmds.isEmpty()) { if (playercmds != null && !playercmds.isEmpty()) {
for (String cmd : playercmds) { for (String cmd : getPlayercmdsForQuality(quality)) {
player.performCommand(BUtil.applyPlaceholders(cmd, player.getName(), quality)); player.performCommand(BUtil.applyPlaceholders(cmd, player.getName(), quality));
} }
} }
if (servercmds != null && !servercmds.isEmpty()) { 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)); 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) { public Builder addPlayerCmds(String... cmds) {
ArrayList<Tuple<Integer,String>> playercmds = new ArrayList<Tuple<Integer, String>>(cmds.length); ArrayList<Tuple<Integer,String>> playercmds = new ArrayList<Tuple<Integer, String>>(cmds.length);
StringParser p = StringParser.cmdParser();
for (String cmd : cmds) { for (String cmd : cmds) {
playercmds.add((Tuple<Integer, String>) p.parse(cmd)); playercmds.add((Tuple<Integer, String>) StringParser.cmdParser.parse(cmd));
} }
if (recipe.playercmds == null) { if (recipe.playercmds == null) {
recipe.playercmds = playercmds; recipe.playercmds = playercmds;
@@ -923,9 +897,8 @@ public class BRecipe {
public Builder addServerCmds(String... cmds) { public Builder addServerCmds(String... cmds) {
ArrayList<Tuple<Integer,String>> servercmds = new ArrayList<Tuple<Integer, String>>(cmds.length); ArrayList<Tuple<Integer,String>> servercmds = new ArrayList<Tuple<Integer, String>>(cmds.length);
StringParser p = StringParser.cmdParser();
for (String cmd : cmds) { for (String cmd : cmds) {
servercmds.add((Tuple<Integer, String>) p.parse(cmd)); servercmds.add((Tuple<Integer, String>) StringParser.cmdParser.parse(cmd));
} }
if (recipe.servercmds == null) { if (recipe.servercmds == null) {
recipe.servercmds = servercmds; recipe.servercmds = servercmds;
+26 -4
View File
@@ -6,8 +6,7 @@ public interface StringParser {
public Object parse(String line); public Object parse(String line);
public static StringParser cmdParser() { public static StringParser cmdParser = new StringParser() {
return new StringParser() {
@Override @Override
public Object parse(String line) { public Object parse(String line) {
line = P.p.color(line); line = P.p.color(line);
@@ -25,9 +24,32 @@ public interface StringParser {
if (line.startsWith("/")) { if (line.startsWith("/")) {
line = line.substring(1); line = line.substring(1);
} }
return new Tuple<>(plus, line); return new Tuple<Integer,String>(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<Integer,String>(plus, line);
}
};
} }