mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-09 19:17:35 +01:00
More name matching for the create command
This commit is contained in:
parent
c4a9ce0ba8
commit
df004cc79c
@ -253,6 +253,16 @@ public class BreweryApi {
|
|||||||
return BRecipe.get(name);
|
return BRecipe.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a BRecipe by _one of_ its names.
|
||||||
|
* <p>May be any of the quality names, or the optional config id.
|
||||||
|
* <p>Returns null if recipe with that name does not exist
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static BRecipe getRecipeMatch(String name) {
|
||||||
|
return BRecipe.getMatching(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a New Recipe.
|
* Add a New Recipe.
|
||||||
* <p>Brews can be made out of this Recipe.
|
* <p>Brews can be made out of this Recipe.
|
||||||
|
@ -492,7 +492,7 @@ public class CommandListener implements CommandExecutor {
|
|||||||
BRecipe nonDistill = ingredients.getBestRecipe(brew.getWood(), brew.getAgeTime(), false);
|
BRecipe nonDistill = ingredients.getBestRecipe(brew.getWood(), brew.getAgeTime(), false);
|
||||||
P.p.log("&lWould prefer Recipe: " + (nonDistill == null ? "none" : nonDistill.getRecipeName()) + " and Distill-Recipe: " + (distill == null ? "none" : distill.getRecipeName()));
|
P.p.log("&lWould prefer Recipe: " + (nonDistill == null ? "none" : nonDistill.getRecipeName()) + " and Distill-Recipe: " + (distill == null ? "none" : distill.getRecipeName()));
|
||||||
} else {
|
} else {
|
||||||
BRecipe recipe = BRecipe.get(recipeName);
|
BRecipe recipe = BRecipe.getMatching(recipeName);
|
||||||
if (recipe == null) {
|
if (recipe == null) {
|
||||||
P.p.msg(player, "Could not find Recipe " + recipeName);
|
P.p.msg(player, "Could not find Recipe " + recipeName);
|
||||||
return;
|
return;
|
||||||
@ -665,19 +665,14 @@ public class CommandListener implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
name = args[1];
|
name = args[1];
|
||||||
}
|
}
|
||||||
|
name = name.replaceAll("\"", "");
|
||||||
|
|
||||||
if (player.getInventory().firstEmpty() == -1) {
|
if (player.getInventory().firstEmpty() == -1) {
|
||||||
p.msg(sender, p.languageReader.get("CMD_Copy_Error", "1"));
|
p.msg(sender, p.languageReader.get("CMD_Copy_Error", "1"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BRecipe recipe = null;
|
BRecipe recipe = BRecipe.getMatching(name);
|
||||||
for (BRecipe r : BRecipe.getAllRecipes()) {
|
|
||||||
if (r.hasName(name)) {
|
|
||||||
recipe = r;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (recipe != null) {
|
if (recipe != null) {
|
||||||
ItemStack item = recipe.create(quality);
|
ItemStack item = recipe.create(quality);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
|
@ -32,6 +32,7 @@ public class BRecipe {
|
|||||||
// info
|
// info
|
||||||
private String[] name;
|
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
|
private boolean saveInData; // If this recipe should be saved in data and loaded again when the server restarts. Applicable to non-config recipes
|
||||||
|
private String optionalID; // ID that might be given by the config
|
||||||
|
|
||||||
// brewing
|
// brewing
|
||||||
private List<RecipeItem> ingredients = new ArrayList<>(); // Items and amounts
|
private List<RecipeItem> ingredients = new ArrayList<>(); // Items and amounts
|
||||||
@ -85,6 +86,7 @@ public class BRecipe {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, String recipeId) {
|
public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, String recipeId) {
|
||||||
BRecipe recipe = new BRecipe();
|
BRecipe recipe = new BRecipe();
|
||||||
|
recipe.optionalID = recipeId;
|
||||||
String nameList = configSectionRecipes.getString(recipeId + ".name");
|
String nameList = configSectionRecipes.getString(recipeId + ".name");
|
||||||
if (nameList != null) {
|
if (nameList != null) {
|
||||||
String[] name = nameList.split("/");
|
String[] name = nameList.split("/");
|
||||||
@ -542,6 +544,11 @@ public class BRecipe {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getOptionalID() {
|
||||||
|
return optionalID;
|
||||||
|
}
|
||||||
|
|
||||||
public List<RecipeItem> getIngredients() {
|
public List<RecipeItem> getIngredients() {
|
||||||
return ingredients;
|
return ingredients;
|
||||||
}
|
}
|
||||||
@ -749,6 +756,34 @@ public class BRecipe {
|
|||||||
return recipes;
|
return recipes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the BRecipe that has the given name as one of its quality names.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static BRecipe getMatching(String name) {
|
||||||
|
BRecipe mainNameRecipe = get(name);
|
||||||
|
if (mainNameRecipe != null) {
|
||||||
|
return mainNameRecipe;
|
||||||
|
}
|
||||||
|
for (BRecipe recipe : recipes) {
|
||||||
|
if (recipe.getName(1).equalsIgnoreCase(name)) {
|
||||||
|
return recipe;
|
||||||
|
} else if (recipe.getName(10).equalsIgnoreCase(name)) {
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (BRecipe recipe : recipes) {
|
||||||
|
if (recipe.getOptionalID().equalsIgnoreCase(name)) {
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the BRecipe that has that name as its name
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
public static BRecipe get(String name) {
|
public static BRecipe get(String name) {
|
||||||
for (BRecipe recipe : recipes) {
|
for (BRecipe recipe : recipes) {
|
||||||
if (recipe.getRecipeName().equalsIgnoreCase(name)) {
|
if (recipe.getRecipeName().equalsIgnoreCase(name)) {
|
||||||
@ -865,7 +900,7 @@ public class BRecipe {
|
|||||||
* Add Commands that are executed by the player on drinking
|
* Add Commands that are executed by the player on drinking
|
||||||
*/
|
*/
|
||||||
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<>(cmds.length);
|
||||||
|
|
||||||
for (String cmd : cmds) {
|
for (String cmd : cmds) {
|
||||||
playercmds.add(StringParser.parseQuality(cmd, StringParser.ParseType.CMD));
|
playercmds.add(StringParser.parseQuality(cmd, StringParser.ParseType.CMD));
|
||||||
@ -882,7 +917,7 @@ public class BRecipe {
|
|||||||
* Add Commands that are executed by the server on drinking
|
* Add Commands that are executed by the server on drinking
|
||||||
*/
|
*/
|
||||||
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<>(cmds.length);
|
||||||
|
|
||||||
for (String cmd : cmds) {
|
for (String cmd : cmds) {
|
||||||
servercmds.add(StringParser.parseQuality(cmd, StringParser.ParseType.CMD));
|
servercmds.add(StringParser.parseQuality(cmd, StringParser.ParseType.CMD));
|
||||||
@ -911,6 +946,14 @@ public class BRecipe {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Optional ID of this recipe
|
||||||
|
*/
|
||||||
|
public Builder setID(String id) {
|
||||||
|
recipe.optionalID = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Custom Model Data for each Quality
|
* Add Custom Model Data for each Quality
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user