Route Guild contacts to the passage menu and display native Cookbook recipes
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled

This commit is contained in:
unimatrixgit 2026-12-04 20:26:51 +01:00
commit 343084a60e

View file

@ -67,14 +67,57 @@ final class OrganisationMenus implements Listener {
}
private void cookbookRecipe(Player player,CookbookCatalog.Recipe recipe){
var panel=panel(player,"Cookbook · "+recipe.name(),false);
panel.description=recipe.grade()+"\n"+recipe.ingredients()+"\n"+recipe.details();
put(panel,22,recipe.name(),panel.description,recipe.material(),null);
var icon=panel.inventory.getItem(22);
var meta=icon.getItemMeta();
meta.setItemModel(new NamespacedKey("dunerealms","crafting/"+recipe.id()));
icon.setItemMeta(meta);
panel.inventory.setItem(22,icon);
put(panel,45,"Back","Cookbook",Material.ARROW,()->cookbook(player));close(panel,player);show(player,panel);
var nativeRecipe=Bukkit.getRecipe(recipe.key());
if(nativeRecipe instanceof org.bukkit.inventory.ShapedRecipe shaped){
var shape=shaped.getShape();
var ingredients=shaped.getChoiceMap();
for(int row=0;row<shape.length;row++){
for(int col=0;col<shape[row].length();col++){
var choice=ingredients.get(shape[row].charAt(col));
if(choice!=null)recipeIngredient(panel,10+row*9+col,recipe,choice);
}
}
}else if(nativeRecipe instanceof org.bukkit.inventory.ShapelessRecipe shapeless){
var ingredients=shapeless.getChoiceList();
for(int i=0;i<ingredients.size();i++)recipeIngredient(panel,10+i/3*9+i%3,recipe,ingredients.get(i));
}else{
put(panel,22,"Recipe unavailable","This server has not registered this recipe.",Material.BARRIER,null);
}
if(nativeRecipe!=null){
put(panel,23,"Produces",recipe.details(),Material.ARROW,null);
put(panel,25,recipe.name(),recipe.grade()+" · "+nativeRecipe.getResult().getAmount()+" per craft",recipe.material(),null);
var icon=panel.inventory.getItem(25);
var meta=icon.getItemMeta();
meta.setItemModel(new NamespacedKey("dunerealms","crafting/"+recipe.id()));
icon.setItemMeta(meta);
icon.setAmount(nativeRecipe.getResult().getAmount());
panel.inventory.setItem(25,icon);
}
put(panel,45,"Back","Cookbook",Material.ARROW,()->cookbook(player));close(panel,player);
// Keep the native row and column positions, including repeated ingredients.
player.openInventory(panel.inventory);
Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);
}
private void recipeIngredient(Panel panel,int slot,CookbookCatalog.Recipe recipe,org.bukkit.inventory.RecipeChoice choice){
Material material=choice.getItemStack().getType();
String name=material.name().replace('_',' ').toLowerCase(Locale.ROOT);
String detail="1 per slot";
if(material==Material.ORANGE_DYE){
name="Raw Melange Spice";
detail="Use genuine raw Melange Spice.";
}else if(material==Material.COAL&&recipe.id().equals("spice_tender")){
name="Spice Coal";
}else if(choice instanceof org.bukkit.inventory.RecipeChoice.MaterialChoice alternatives&&alternatives.getChoices().contains(Material.CHARCOAL)){
name="Coal or Charcoal";
}
put(panel,slot,name,detail,material,null);
if(name.equals("Spice Coal")){
var icon=panel.inventory.getItem(slot);
var meta=icon.getItemMeta();
meta.setItemModel(new NamespacedKey("dunerealms","crafting/spice_coal"));
icon.setItemMeta(meta);
panel.inventory.setItem(slot,icon);
}
}
private void start(Player p,JsonObject data){
var panel=panel(p,"Your organisations",false);put(panel,19,"Clan","Your clan and Home Block",Material.GREEN_BANNER,()->choose(p,data,"clans"));put(panel,22,"Company","Your companies and Home Blocks",Material.CYAN_BANNER,()->choose(p,data,"companies"));put(panel,25,"POL","Your current political offices",Material.PURPLE_BANNER,()->choose(p,data,"offices"));close(panel,p);show(p,panel);