Route Guild contacts to the passage menu and display native Cookbook recipes
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled
This commit is contained in:
parent
a85bd084a8
commit
343084a60e
5 changed files with 88 additions and 12 deletions
|
|
@ -175,7 +175,11 @@ public final class DuneLobby extends JavaPlugin implements Listener, CommandExec
|
||||||
String role=e.getRightClicked().getPersistentDataContainer().get(roleKey,PersistentDataType.STRING);
|
String role=e.getRightClicked().getPersistentDataContainer().get(roleKey,PersistentDataType.STRING);
|
||||||
if(role==null) return; e.setCancelled(true); if(e.getHand()!=EquipmentSlot.HAND) return;
|
if(role==null) return; e.setCancelled(true); if(e.getHand()!=EquipmentSlot.HAND) return;
|
||||||
switch(role) {
|
switch(role) {
|
||||||
case "liaison" -> { if(Bukkit.getPluginCommand("duneess")!=null) e.getPlayer().performCommand("duneess travel"); else departure(e.getPlayer(),"arrakis"); }
|
case "liaison" -> {
|
||||||
|
if (!e.getPlayer().performCommand("dunerealmsgui:guildtravel")) {
|
||||||
|
e.getPlayer().sendMessage("The Spacing Guild menu is unavailable.");
|
||||||
|
}
|
||||||
|
}
|
||||||
case "exchange" -> { if(Bukkit.getPluginCommand("dune")!=null) e.getPlayer().performCommand("dune exchange"); else e.getPlayer().sendMessage(ChatColor.GOLD+"Koopkring market integration requires DuneCore on this backend."); }
|
case "exchange" -> { if(Bukkit.getPluginCommand("dune")!=null) e.getPlayer().performCommand("dune exchange"); else e.getPlayer().sendMessage(ChatColor.GOLD+"Koopkring market integration requires DuneCore on this backend."); }
|
||||||
case "water","spice" -> trade(e.getPlayer(),role);
|
case "water","spice" -> trade(e.getPlayer(),role);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,10 @@ public final class DuneNPC extends JavaPlugin implements Listener, CommandExecut
|
||||||
@EventHandler public void navigator(PlayerInteractEntityEvent event) {
|
@EventHandler public void navigator(PlayerInteractEntityEvent event) {
|
||||||
if (!event.getRightClicked().getPersistentDataContainer().has(guildKey, PersistentDataType.BYTE)) return;
|
if (!event.getRightClicked().getPersistentDataContainer().has(guildKey, PersistentDataType.BYTE)) return;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (event.getHand() == EquipmentSlot.HAND) Bukkit.dispatchCommand(event.getPlayer(), "duneess travel");
|
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||||
|
if (!event.getPlayer().performCommand("dunerealmsgui:guildtravel")) {
|
||||||
|
event.getPlayer().sendMessage("The Spacing Guild menu is unavailable.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (!(sender instanceof Player player)) { sender.sendMessage("Run this command in-game."); return true; }
|
if (!(sender instanceof Player player)) { sender.sendMessage("Run this command in-game."); return true; }
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,19 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
final class CookbookCatalog {
|
final class CookbookCatalog {
|
||||||
private static final List<String> ROMAN = List.of("0", "I", "II", "III", "IV", "V");
|
private static final List<String> ROMAN = List.of("0", "I", "II", "III", "IV", "V");
|
||||||
|
|
||||||
record Recipe(String id, String name, Material material, int mark, String quality, String ingredients, String details) {
|
record Recipe(String id, String name, Material material, int mark, String quality, String ingredients, String details) {
|
||||||
String grade() { return quality + " · MK " + ROMAN.get(mark); }
|
NamespacedKey key() {
|
||||||
|
if (id.equals("spice_tender")) return new NamespacedKey("minecarttrains", "fuel_cart");
|
||||||
|
if (id.equals("spice_coal")) return new NamespacedKey("dunerealms", id);
|
||||||
|
return new NamespacedKey("dunerealms", "spice_cooker_" + material.name().toLowerCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
String grade() { return quality + " · MK " + ROMAN.get(mark); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private CookbookCatalog() {}
|
private CookbookCatalog() {}
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,27 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
||||||
var data=item.getItemMeta().getPersistentDataContainer();for(var key:data.getKeys())if(data.has(key,PersistentDataType.STRING)&&"menu_opener".equals(data.get(key,PersistentDataType.STRING))){inventory.setItem(slot,null);break;}
|
var data=item.getItemMeta().getPersistentDataContainer();for(var key:data.getKeys())if(data.has(key,PersistentDataType.STRING)&&"menu_opener".equals(data.get(key,PersistentDataType.STRING))){inventory.setItem(slot,null);break;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void openGuild(Player p,String requested){if(!lobby(p)){try{bridge.returnGuild(p);}catch(Exception unavailable){p.sendMessage("The Guild could not confirm your return. Please retry.");}return;}fetch(p,null,0,null,data->{String house=selection(data);if(house==null){p.sendMessage("Choose and confirm your House before Guild passage.");select(p,data,null);return;}travelMenu(p,data);});}
|
private void openGuild(Player p,String requested){if(!lobby(p)){guildReturnMenu(p);return;}fetch(p,null,0,null,data->{String house=selection(data);if(house==null){p.sendMessage("Choose and confirm your House before Guild passage.");select(p,data,null);return;}travelMenu(p,data);});}
|
||||||
|
private void guildReturnMenu(Player player){
|
||||||
|
String title="Spacing Guild · Return passage";
|
||||||
|
String detail="Return to the Guild Lobby to book onward passage.";
|
||||||
|
Runnable returnToLobby=()->{
|
||||||
|
player.closeInventory();
|
||||||
|
try{bridge.returnGuild(player);}
|
||||||
|
catch(Exception failure){player.sendMessage("The Guild could not confirm your return. Please retry.");}
|
||||||
|
};
|
||||||
|
if(BedrockForms.isBedrock(player)){
|
||||||
|
BedrockForms.show(this,player,title,detail,List.of(new BedrockForms.Choice("Return to Guild Lobby",detail,returnToLobby)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Screen panel=new Screen(player);
|
||||||
|
panel.inventory=Bukkit.createInventory(panel,54,Component.text(title,NamedTextColor.GOLD));
|
||||||
|
panel.inventory.setItem(22,icon(player,"Return to Guild Lobby",detail,"drgui_transparent",Material.COMPASS));
|
||||||
|
panel.actions.put(22,returnToLobby);
|
||||||
|
if(MCGUIMenus.show(player,title,detail,panel.inventory,panel.actions,panel.gate))return;
|
||||||
|
player.openInventory(panel.inventory);
|
||||||
|
expire(panel);
|
||||||
|
}
|
||||||
private static GuildBookings.Permit permit(JsonObject data){String house=selection(data);if(house==null||!data.has("keyId")||data.get("keyId").isJsonNull())return null;try{return new GuildBookings.Permit(house,UUID.fromString(data.get("keyId").getAsString()),data.get("version").getAsInt());}catch(RuntimeException invalid){return null;}}
|
private static GuildBookings.Permit permit(JsonObject data){String house=selection(data);if(house==null||!data.has("keyId")||data.get("keyId").isJsonNull())return null;try{return new GuildBookings.Permit(house,UUID.fromString(data.get("keyId").getAsString()),data.get("version").getAsInt());}catch(RuntimeException invalid){return null;}}
|
||||||
private void travelMenu(Player p,JsonObject data){var q=new JsonObject();q.addProperty("action","quote");guildRequest(p,q,quote->{data.add("guildQuote",quote);renderTravelMenu(p,data);});}
|
private void travelMenu(Player p,JsonObject data){var q=new JsonObject();q.addProperty("action","quote");guildRequest(p,q,quote->{data.add("guildQuote",quote);renderTravelMenu(p,data);});}
|
||||||
private void guildRequest(Player p,JsonObject input,Consumer<JsonObject> done){UUID id=p.getUniqueId(),world=p.getWorld().getUID();if(!boarding.add(id)){p.sendMessage("J.A.R.V.I.S. is processing your passage.");return;}Bukkit.getScheduler().runTaskAsynchronously(this,()->{JsonObject result=null;String failure=null;try{result=bridge.guild(id,input);}catch(Exception e){failure=e.getMessage();}var response=result;String message=failure;if(!isEnabled())return;Bukkit.getScheduler().runTask(this,()->{if(!boarding.remove(id)||!p.isOnline()||!p.getWorld().getUID().equals(world))return;if(response==null){p.sendMessage(message==null?"The central Guild service is unavailable.":message);return;}done.accept(response);});});}
|
private void guildRequest(Player p,JsonObject input,Consumer<JsonObject> done){UUID id=p.getUniqueId(),world=p.getWorld().getUID();if(!boarding.add(id)){p.sendMessage("J.A.R.V.I.S. is processing your passage.");return;}Bukkit.getScheduler().runTaskAsynchronously(this,()->{JsonObject result=null;String failure=null;try{result=bridge.guild(id,input);}catch(Exception e){failure=e.getMessage();}var response=result;String message=failure;if(!isEnabled())return;Bukkit.getScheduler().runTask(this,()->{if(!boarding.remove(id)||!p.isOnline()||!p.getWorld().getUID().equals(world))return;if(response==null){p.sendMessage(message==null?"The central Guild service is unavailable.":message);return;}done.accept(response);});});}
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,57 @@ final class OrganisationMenus implements Listener {
|
||||||
}
|
}
|
||||||
private void cookbookRecipe(Player player,CookbookCatalog.Recipe recipe){
|
private void cookbookRecipe(Player player,CookbookCatalog.Recipe recipe){
|
||||||
var panel=panel(player,"Cookbook · "+recipe.name(),false);
|
var panel=panel(player,"Cookbook · "+recipe.name(),false);
|
||||||
panel.description=recipe.grade()+"\n"+recipe.ingredients()+"\n"+recipe.details();
|
var nativeRecipe=Bukkit.getRecipe(recipe.key());
|
||||||
put(panel,22,recipe.name(),panel.description,recipe.material(),null);
|
if(nativeRecipe instanceof org.bukkit.inventory.ShapedRecipe shaped){
|
||||||
var icon=panel.inventory.getItem(22);
|
var shape=shaped.getShape();
|
||||||
var meta=icon.getItemMeta();
|
var ingredients=shaped.getChoiceMap();
|
||||||
meta.setItemModel(new NamespacedKey("dunerealms","crafting/"+recipe.id()));
|
for(int row=0;row<shape.length;row++){
|
||||||
icon.setItemMeta(meta);
|
for(int col=0;col<shape[row].length();col++){
|
||||||
panel.inventory.setItem(22,icon);
|
var choice=ingredients.get(shape[row].charAt(col));
|
||||||
put(panel,45,"Back","Cookbook",Material.ARROW,()->cookbook(player));close(panel,player);show(player,panel);
|
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){
|
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);
|
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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue

Staff