Keep listing prices visible and focus long item details without purchase side effects

This commit is contained in:
unimatrixgit 2026-11-29 11:20:30 +01:00
commit fbc7c2bfd5
2 changed files with 26 additions and 15 deletions

View file

@ -7,13 +7,14 @@ final class CanvasProvider implements FullscreenProvider {
private final DuneMenusPlugin plugin;
private final MenuArt art;private boolean prepared;
CanvasProvider(DuneMenusPlugin plugin){this.plugin=plugin;this.art=new MenuArt(plugin);var services=plugin.getServer().getPluginManager().getPlugin("DunerealmsGUI");if(services!=null)try{art.prepare(services.getDataFolder().toPath().resolve("mcgui"));prepared=true;}catch(Exception failure){plugin.getLogger().warning("Menu artwork preparation failed: "+failure.getClass().getSimpleName());}}
public boolean open(Player player,Screen screen,IntConsumer select,Runnable close){
public boolean open(Player player,Screen screen,IntConsumer select,Runnable close){return open(player,screen,select,close,-1);}
private boolean open(Player player,Screen screen,IntConsumer select,Runnable close,int selected){
var services=plugin.getServer().getPluginManager().getPlugin("DunerealmsGUI");
if(services==null||!services.isEnabled())return false;
Map<Integer,String> images=new HashMap<>();
try{if(prepared)for(Card card:screen.cards()){var inventory=screen.contents();if(card.slot()>=0&&card.slot()<inventory.length){String image=art.image(inventory[card.slot()]);if(!image.isEmpty())images.put(card.slot(),image);}}}catch(Exception failure){plugin.getLogger().warning("Menu artwork unavailable: "+failure.getClass().getSimpleName());}
Map<Integer,Runnable> actions=new HashMap<>();for(Card card:screen.cards())actions.put(card.slot(),()->select.accept(card.slot()));
try{return Boolean.TRUE.equals(services.getClass().getMethod("presentSuppliedMenu",Player.class,String.class,String.class,Map.class,Runnable.class).invoke(services,player,screen.title(),SuppliedDocument.html(screen.id(),screen.title(),screen.subtitle(),screen.cards(),screen.info(),images),actions,close));}
Map<Integer,Runnable> actions=new HashMap<>();for(Card card:screen.cards()){actions.put(card.slot(),()->select.accept(card.slot()));if(SuppliedDocument.summary(card).size()>1)actions.put(1000+card.slot(),()->open(player,screen,select,close,card.slot()));}
try{return Boolean.TRUE.equals(services.getClass().getMethod("presentSuppliedMenu",Player.class,String.class,String.class,Map.class,Runnable.class).invoke(services,player,screen.title(),SuppliedDocument.html(screen.id(),screen.title(),screen.subtitle(),screen.cards(),screen.info(),images,selected),actions,close));}
catch(ReflectiveOperationException failure){plugin.getLogger().warning("Menu canvas unavailable: "+failure.getClass().getSimpleName());return false;}
}
}

File diff suppressed because one or more lines are too long