forked from unimatrix/web
Add opt-in organisation, Exchange and House fullscreen styles
This commit is contained in:
parent
e8452c887f
commit
5f58251ee3
1 changed files with 303 additions and 90 deletions
|
|
@ -0,0 +1,48 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/** Bridges the existing menu document and its server-side callbacks to an opt-in renderer. */
|
||||
final class NativeMenus {
|
||||
private NativeMenus() {}
|
||||
|
||||
static boolean show(JavaPlugin plugin, Player player, String setting, String title, String description,
|
||||
Inventory inventory, Map<Integer,Runnable> actions, GuiSession gate,
|
||||
DecisionsViewTransport.Style style, MenuDocument.Branding branding) {
|
||||
if (!plugin.getConfig().getStringList(setting).contains(player.getUniqueId().toString())) return false;
|
||||
var transport = Bukkit.getServicesManager().load(DecisionsViewTransport.class);
|
||||
if (transport == null) return false;
|
||||
var cards = MCGUIMenus.cards(inventory, actions).stream().map(card ->
|
||||
new DecisionsViewTransport.Card(card.slot(), card.title(), card.lore(), card.action(), card.material())).toList();
|
||||
var identity = branding == null ? null :
|
||||
new DecisionsViewTransport.Identity(branding.logo(), branding.mentat(), branding.portrait());
|
||||
var document = new DecisionsViewTransport.Document(title, description, cards, style, identity);
|
||||
Map<Integer,Runnable> visibleActions = new HashMap<>();
|
||||
for (var card : cards) if (card.actionable()) visibleActions.put(card.slot(), actions.get(card.slot()));
|
||||
var callbacks = Map.copyOf(visibleActions);
|
||||
player.closeInventory();
|
||||
var world = player.getWorld().getUID();
|
||||
try {
|
||||
if (!transport.open(player, document, slot -> {
|
||||
if (!Bukkit.isPrimaryThread()) return;
|
||||
if (!player.isOnline() || !world.equals(player.getWorld().getUID())) {
|
||||
gate.expire();
|
||||
return;
|
||||
}
|
||||
var action = gate.claimAction(player.getUniqueId(), callbacks.get(slot));
|
||||
gate.expire();
|
||||
if (action != null) action.run();
|
||||
}, gate::expire)) return false;
|
||||
} catch (RuntimeException | LinkageError failure) {
|
||||
plugin.getLogger().warning("Development fullscreen view unavailable: " + failure.getClass().getSimpleName());
|
||||
return false;
|
||||
}
|
||||
gate.markFormVisible(world);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff