Use flat coordinated sand palettes and show first-menu Shift hint
This commit is contained in:
parent
a88a05fc17
commit
00130702b1
2 changed files with 393 additions and 50 deletions
|
|
@ -253,7 +253,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
}
|
||||
@EventHandler public void drag(InventoryDragEvent e){if(e.getView().getTopInventory().getHolder() instanceof Screen)e.setCancelled(true);}
|
||||
@EventHandler public void close(InventoryCloseEvent e){if(e.getInventory().getHolder() instanceof Screen s)s.gate.expire();}
|
||||
@EventHandler public void quit(PlayerQuitEvent e){guiPackLoaded.remove(e.getPlayer().getUniqueId());bookings.cancel(e.getPlayer().getUniqueId());boarding.remove(e.getPlayer().getUniqueId());requests.remove(e.getPlayer().getUniqueId());records.remove(e.getPlayer().getUniqueId());sidebar.hide(e.getPlayer());departure.removePlayer(e.getPlayer());}
|
||||
@EventHandler public void quit(PlayerQuitEvent e){MCGUIMenus.forget(e.getPlayer().getUniqueId());guiPackLoaded.remove(e.getPlayer().getUniqueId());bookings.cancel(e.getPlayer().getUniqueId());boarding.remove(e.getPlayer().getUniqueId());requests.remove(e.getPlayer().getUniqueId());records.remove(e.getPlayer().getUniqueId());sidebar.hide(e.getPlayer());departure.removePlayer(e.getPlayer());}
|
||||
private void ensureRegistrar(){World world=Bukkit.getWorld("guild_lobby");if(world==null)return;Location at=world.getSpawnLocation().clone().add(2,0,0);at.getChunk().load();
|
||||
for(Entity entity:world.getEntities())if(entity.getPersistentDataContainer().has(registrar,PersistentDataType.BYTE))return;
|
||||
Villager npc=world.spawn(at,Villager.class);npc.setAI(false);npc.setInvulnerable(true);npc.setPersistent(true);npc.setSilent(true);npc.setCollidable(false);npc.setProfession(Villager.Profession.LIBRARIAN);npc.customName(Component.text("House Registrar · Choose your House",NamedTextColor.GOLD));npc.setCustomNameVisible(true);npc.getPersistentDataContainer().set(registrar,PersistentDataType.BYTE,(byte)1);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ final class MCGUIMenus implements AutoCloseable {
|
|||
private static MCGUIMenus active;
|
||||
private final JavaPlugin plugin;
|
||||
private final Map<UUID,Session> sessions=new HashMap<>();
|
||||
private final Set<UUID> closeHints=new HashSet<>();
|
||||
private final ExecutorService drawings=Executors.newSingleThreadExecutor(r->{Thread t=new Thread(r,"DuneRealms-menu-render");t.setDaemon(true);return t;});
|
||||
private Plugin engine;private Object framework,loader,none;private Class<?> contentType,optionsType;private Object defaultOptions;
|
||||
private Method makeCanvas,openView,hasPack,pageOf,render,draw,hoverState;
|
||||
|
|
@ -47,6 +48,7 @@ final class MCGUIMenus implements AutoCloseable {
|
|||
static boolean show(Player p,String title,String description,Inventory inventory,Map<Integer,Runnable> actions,GuiSession gate){
|
||||
return active!=null&&active.present(p,title,description,inventory,actions,gate);
|
||||
}
|
||||
static void forget(UUID player){if(active!=null)active.closeHints.remove(player);}
|
||||
static void offerPack(Player p){if(active!=null&&!BedrockForms.isBedrock(p))active.sendPack(p);}
|
||||
private void sendPack(Player p){if(!p.getWorld().getName().equals("guild_lobby"))return;p.addResourcePack(packId,packUrl,packHash,"DuneRealms interactive menus",true);}
|
||||
private boolean present(Player p,String title,String description,Inventory inventory,Map<Integer,Runnable> actions,GuiSession suppliedGate){
|
||||
|
|
@ -81,7 +83,7 @@ final class MCGUIMenus implements AutoCloseable {
|
|||
String html=MenuDocument.html(title,description,player.getName(),cards,selected,base.getParent());Object page=pageOf.invoke(null,html,base,loader);
|
||||
Object paintState=none;Object document=page.getClass().getField("document").get(page);String selector=expected<=-100?"[data-pick=\""+(-100-expected)+"\"]":"[data-slot=\""+expected+"\"]";Object element=document.getClass().getMethod("selectFirst",String.class).invoke(document,selector);if(element!=null)paintState=hoverState.invoke(null,element,null);Object next=render.invoke(null,page,1536,896,1.5,offset,paintState);
|
||||
if(!alive)return;draw.invoke(canvas,next.getClass().getMethod("image").invoke(next),0,0);frame=next;
|
||||
Bukkit.getScheduler().runTask(plugin,()->{if(!current())return;if(view==null)try{Object proxy=Proxy.newProxyInstance(contentType.getClassLoader(),new Class<?>[]{contentType},this);view=openView.invoke(framework,player,proxy,defaultOptions);}catch(Exception e){finish();sessions.remove(player.getUniqueId());player.sendMessage("The menu could not open. Load the menu pack and reopen your Codex.");plugin.getLogger().warning("MC GUI view failed: "+e.getClass().getSimpleName());}});
|
||||
Bukkit.getScheduler().runTask(plugin,()->{if(!current())return;if(view==null)try{Object proxy=Proxy.newProxyInstance(contentType.getClassLoader(),new Class<?>[]{contentType},this);view=openView.invoke(framework,player,proxy,defaultOptions);if(closeHints.add(player.getUniqueId()))player.sendMessage("Press Shift to close this menu.");}catch(Exception e){finish();sessions.remove(player.getUniqueId());player.sendMessage("The menu could not open. Load the menu pack and reopen your Codex.");plugin.getLogger().warning("MC GUI view failed: "+e.getClass().getSimpleName());}});
|
||||
}catch(Exception|LinkageError e){if(alive){plugin.getLogger().log(java.util.logging.Level.WARNING,"MC GUI render failed",e);Bukkit.getScheduler().runTask(plugin,()->{if(current()){finish();sessions.remove(player.getUniqueId(),this);player.sendMessage("The new menu could not be drawn. Please retry /menu.");}});}}
|
||||
finally{queued.set(false);if(alive&&(expected!=hovered||selected!=picked||offset!=scroll))schedule();}
|
||||
});}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff