Guard the Navigator release against deployed plugin runtimes
This commit is contained in:
parent
4da7c00ffe
commit
9baca377a7
5 changed files with 402 additions and 39 deletions
|
|
@ -13,7 +13,7 @@ final class CanvasProvider implements FullscreenProvider {
|
|||
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()));if(SuppliedDocument.summary(card).size()>1)actions.put(1000+card.slot(),()->open(player,screen,select,close,card.slot()));}
|
||||
Map<Integer,Runnable> actions=new HashMap<>();for(Card card:screen.cards()){if(!card.enabled())continue;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;}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,8 @@ package com.dunerealms.menus;
|
|||
import java.util.List;
|
||||
|
||||
/** One clickable thing on a menu, in renderer-neutral form (used for Bedrock forms and fullscreen). */
|
||||
public record Card(int slot, String title, List<String> lore, String material) {}
|
||||
public record Card(int slot, String title, List<String> lore, String material, boolean enabled) {
|
||||
public Card(int slot, String title, List<String> lore, String material) {
|
||||
this(slot, title, lore, material, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ public final class DuneMenusPlugin extends JavaPlugin implements TabExecutor {
|
|||
public void openSharedMenu(Player player, String title, org.bukkit.inventory.Inventory model, Map<Integer,Runnable> actions) {
|
||||
if (!getServer().isPrimaryThread() || !player.isOnline() || !player.hasPermission("dunemenus.use")) return;
|
||||
String lower=title.toLowerCase(java.util.Locale.ROOT);
|
||||
String section=lower.contains("travel")||lower.contains("guild")?"travel":lower.contains("exchange")?"exchange":lower.contains("spice")?"spice":lower.contains("quest")?"missions":"hub";
|
||||
String section=lower.contains("smuggler")?"smuggler":lower.contains("travel")||lower.contains("guild")?"travel":lower.contains("exchange")?"exchange":lower.contains("spice")?"spice":lower.contains("quest")?"missions":"hub";
|
||||
new ServiceMenu(this,player,section,title,"",model,actions).open();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,11 +149,19 @@ abstract class Menu implements InventoryHolder {
|
|||
|
||||
private List<Card> snapshot() {
|
||||
List<Card> out = new ArrayList<>();
|
||||
if (routeCards()) {
|
||||
for (int slot = 0; slot < inv.getSize(); slot++) {
|
||||
ItemStack it = inv.getItem(slot);
|
||||
if (disabledRoute(it) && !buttons.containsKey(slot) && !plain(it).isBlank())
|
||||
out.add(new Card(slot, plain(it), loreOf(it), "gray_dye", false));
|
||||
}
|
||||
}
|
||||
for (int slot : buttons.keySet()) {
|
||||
ItemStack it = inv.getItem(slot);
|
||||
if (it == null || plain(it).isBlank()) continue;
|
||||
out.add(new Card(slot, plain(it), loreOf(it), it.getType().name().toLowerCase()));
|
||||
}
|
||||
if (routeCards()) out.sort(java.util.Comparator.comparingInt(Card::slot));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +169,7 @@ abstract class Menu implements InventoryHolder {
|
|||
List<String> out = new ArrayList<>();
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
ItemStack it = inv.getItem(i);
|
||||
if (it == null || buttons.containsKey(i) || it.getType().name().endsWith("_PANE")) continue;
|
||||
if (it == null || buttons.containsKey(i) || it.getType().name().endsWith("_PANE") || routeCards() && disabledRoute(it)) continue;
|
||||
String n = plain(it);
|
||||
if (n.isBlank()) continue;
|
||||
List<String> lore = loreOf(it).stream().filter(s -> !s.isBlank()).toList();
|
||||
|
|
@ -170,6 +178,9 @@ abstract class Menu implements InventoryHolder {
|
|||
return out;
|
||||
}
|
||||
|
||||
private boolean routeCards() { return id().equals("travel") || id().equals("smuggler"); }
|
||||
private static boolean disabledRoute(ItemStack item) { return item != null && item.getType()==Material.GRAY_DYE; }
|
||||
|
||||
private void present() {
|
||||
long shown = ++presentation;
|
||||
var world = player.getWorld().getUID();
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue

Staff