Share and verify the menu click action gate

This commit is contained in:
unimatrixgit 2026-11-28 08:02:17 +01:00
commit 9b78a57168
2 changed files with 16 additions and 1 deletions

View file

@ -11,6 +11,7 @@ final class GuiSession {
private final AtomicBoolean used=new AtomicBoolean();
GuiSession(UUID owner){this.owner=owner;CURRENT.put(owner,this);}
boolean claim(UUID actor){return owner.equals(actor)&&System.nanoTime()<expires&&CURRENT.get(owner)==this&&used.compareAndSet(false,true)&&CURRENT.remove(owner,this);}
Runnable claimAction(UUID actor,Runnable action){return action!=null&&claim(actor)?action:null;}
private volatile UUID formWorld;
void markFormVisible(UUID world){formWorld=world;}
static boolean hasVisibleForm(UUID owner,UUID world){

View file

@ -111,7 +111,7 @@ final class MCGUIMenus implements AutoCloseable, Listener {
switch(method.getName()){
case "canvas":return alive?canvas:null;
case "pointer":{int next=slot((int)args[1],(int)args[2]);if(next!=hovered){hovered=next;schedule();}return null;}
case "click":{int slot=slot((int)args[1],(int)args[2]);if(!current())return null;if(slot<=-100){picked=-100-slot;scroll=0;schedule();return null;}if(slot==-1){finish();sessions.remove(player.getUniqueId());return null;}Runnable action=slot==-3?()->player.performCommand("menu"):actions.get(slot);if(action!=null&&gate.claim(player.getUniqueId())){finish();sessions.remove(player.getUniqueId());Bukkit.getScheduler().runTask(plugin,()->{if(player.isOnline()&&world.equals(player.getWorld().getUID()))action.run();});}return null;}
case "click":{int slot=slot((int)args[1],(int)args[2]);if(!current())return null;if(slot<=-100){picked=-100-slot;scroll=0;schedule();return null;}if(slot==-1){finish();sessions.remove(player.getUniqueId());return null;}Runnable action=gate.claimAction(player.getUniqueId(),slot==-3?()->player.performCommand("menu"):actions.get(slot));if(action!=null){finish();sessions.remove(player.getUniqueId());Bukkit.getScheduler().runTask(plugin,()->{if(player.isOnline()&&world.equals(player.getWorld().getUID()))action.run();});}return null;}
case "scroll":{Object f=frame;if(f!=null){double max=((Number)f.getClass().getMethod("maxScroll").invoke(f)).doubleValue();scroll=Math.max(0,Math.min(max,scroll+(int)args[3]*90));schedule();}return null;}
case "closed":alive=false;gate.expire();sessions.remove(player.getUniqueId(),this);return null;
case "toString":return "DuneRealms menu view";