@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if (event.getInventory().getHolder() instanceof ShapedRecipeHolder) {
ShapedRecipeHolder holder = (ShapedRecipeHolder) event.getInventory().getHolder();
if (holder != this) return;
Inventory inventory = event.getInventory();
if (InventoryUtils.isEmpty(inventory)) {
holder.callbackPlayer.sendMessage(ChatColor.RED + "Do you seriously want to create a recipe without ingredients?");
return;
}
ShapedRecipes nmsRecipe = holder.toRecipe();
CRShapedRecipe<ShapedRecipes> shapedRecipe = new CRShapedRecipe<>(nmsRecipe);
List<List<String>> recipeIngredients = shapedRecipe.getIngredients().stream()
.map((CRChoiceIngredient ingr) -> ingr.getChoices().stream()
.map(InventoryUtils::getItemName).collect(Collectors.toList()))
.collect(Collectors.toList());
String recipeString = recipeIngredients + "" +
ChatColor.RESET + " -> " +
InventoryUtils.getItemName(shapedRecipe.getResult());
boolean success = holder.plugin.getCraftingManager().addRecipe(holder.key, nmsRecipe, shapedRecipe);
if (success) {
holder.callbackPlayer.sendMessage(String.format("%sAdded shaped recipe: %s%s%s!",
ChatColor.GREEN, ChatColor.WHITE, recipeString, ChatColor.WHITE));
plugin.saveCraftingRecipeFile("shaped", shapedRecipe);
} else {
holder.callbackPlayer.sendMessage(ChatColor.RED + "Couldn't create a shaped recipe. Possibly a duplicate key.");
}
HandlerList.unregisterAll(holder);
}
}
ShapedAdder.java 文件源码
java
阅读 42
收藏 0
点赞 0
评论 0
项目:CustomRecipes
作者:
评论列表
文章目录