|
|
|
|
@ -0,0 +1,196 @@
|
|
|
|
|
package com.dunerealms.gui;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.*;
|
|
|
|
|
import net.kyori.adventure.key.Key;
|
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
|
|
|
import org.bukkit.*;
|
|
|
|
|
import org.bukkit.boss.*;
|
|
|
|
|
import org.bukkit.command.*;
|
|
|
|
|
import org.bukkit.entity.*;
|
|
|
|
|
import org.bukkit.event.*;
|
|
|
|
|
import org.bukkit.event.inventory.*;
|
|
|
|
|
import org.bukkit.event.player.*;
|
|
|
|
|
import org.bukkit.inventory.*;
|
|
|
|
|
import org.bukkit.persistence.PersistentDataType;
|
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.time.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
/** Lobby presentation only. Character authority and committed keys remain central. */
|
|
|
|
|
public final class DuneGUI extends JavaPlugin implements Listener,CommandExecutor {
|
|
|
|
|
private HouseBridge bridge;
|
|
|
|
|
private final Map<UUID,UUID> requests=new HashMap<>();
|
|
|
|
|
private final Map<UUID,JsonObject> records=new HashMap<>();
|
|
|
|
|
private BossBar departure;
|
|
|
|
|
private NamespacedKey registrar;
|
|
|
|
|
private PersonalSidebar sidebar;
|
|
|
|
|
private final Map<UUID,DragonController.Detached> detached=new HashMap<>();
|
|
|
|
|
private final Set<UUID> dragonWarnings=new HashSet<>();
|
|
|
|
|
private ExistingGuildService guild;
|
|
|
|
|
private final GuildBookings bookings=new GuildBookings();
|
|
|
|
|
private final Set<UUID> boarding=new HashSet<>();
|
|
|
|
|
private long lastDepartureNotice=-1;
|
|
|
|
|
static final int[] CENTRES={10,13,16,29,33};
|
|
|
|
|
static final String[] IDS={"atreides","harkonnen","corrino","ordos","fremen"};
|
|
|
|
|
private static final Set<String> HOUSE_IDS=Set.of(IDS);
|
|
|
|
|
private static final class Screen implements InventoryHolder {
|
|
|
|
|
final UUID owner;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();Inventory inventory;
|
|
|
|
|
Screen(Player player){owner=player.getUniqueId();gate=new GuiSession(owner);}
|
|
|
|
|
public Inventory getInventory(){return inventory;}
|
|
|
|
|
}
|
|
|
|
|
@Override public void onEnable(){
|
|
|
|
|
bridge=new HouseBridge(new File(getDataFolder().getParentFile(),"DuneEss/website-bridge.yml"));
|
|
|
|
|
registrar=new NamespacedKey(this,"house_registrar");
|
|
|
|
|
sidebar=new PersonalSidebar(this);
|
|
|
|
|
for(String command:List.of("house","mentat","drgui","drscoreboard","guildtravel"))Objects.requireNonNull(getCommand(command)).setExecutor(this);
|
|
|
|
|
try{guild=new ExistingGuildService((p,world)->openGuild(p,world));getLogger().info("Spacing Guild lobby entry connected to current House keys and quarter-hour boarding.");}catch(ReflectiveOperationException|RuntimeException unavailable){getLogger().warning("Spacing Guild travel consumer unavailable; no journeys can be booked.");}
|
|
|
|
|
getServer().getPluginManager().registerEvents(this,this);
|
|
|
|
|
departure=Bukkit.createBossBar("Spacing Guild · next Imperial departure",BarColor.YELLOW,BarStyle.SOLID);
|
|
|
|
|
Bukkit.getScheduler().runTaskTimer(this,this::tick,20L,20L);
|
|
|
|
|
Bukkit.getScheduler().runTaskLater(this,this::ensureRegistrar,40L);
|
|
|
|
|
Bukkit.getScheduler().runTaskTimer(this,()->{for(Player p:Bukkit.getOnlinePlayers())if(lobby(p)&&sidebar.enabled(p))refreshSidebar(p);},80L,600L);
|
|
|
|
|
getLogger().info("House selector and Mentat screens enabled; central J.A.R.V.I.S. bridge; no Core/Lobby replacement.");
|
|
|
|
|
}
|
|
|
|
|
@Override public void onDisable(){requests.clear();records.clear();bookings.clear();boarding.clear();if(guild!=null)guild.close();GuiSession.clear();if(sidebar!=null)sidebar.clear();for(var controller:detached.values())try{controller.restore();}catch(ReflectiveOperationException ignored){}detached.clear();if(departure!=null)departure.removeAll();for(Player p:Bukkit.getOnlinePlayers())if(p.getOpenInventory().getTopInventory().getHolder() instanceof Screen)p.closeInventory();}
|
|
|
|
|
private boolean lobby(Player p){return p.getWorld().getName().equals("guild_lobby");}
|
|
|
|
|
@Override public boolean onCommand(CommandSender sender,Command command,String label,String[] args){
|
|
|
|
|
if(!(sender instanceof Player p))return true;if(!lobby(p)){p.sendMessage("This service is available in the Spacing Guild lobby.");return true;}
|
|
|
|
|
if(command.getName().equals("drscoreboard")||args.length==1&&args[0].equalsIgnoreCase("scoreboard")){toggleSidebar(p);return true;}
|
|
|
|
|
if(command.getName().equals("guildtravel")||args.length==1&&args[0].equalsIgnoreCase("travel")){if(args.length==1&&args[0].equalsIgnoreCase("cancel")){cancelBooking(p);return true;}openGuild(p,null);return true;}
|
|
|
|
|
fetch(p,null,0,null,data->{if(command.getName().equals("mentat")&&selection(data)!=null)mentat(p,data);else select(p,data,null);});return true;
|
|
|
|
|
}
|
|
|
|
|
private void openGuild(Player p,String requested){fetch(p,null,0,null,data->{String house=selection(data);if(house==null){p.sendMessage("Choose and confirm your House before Guild passage.");select(p,data,null);return;}if(requested!=null&&!GuildRoutes.allowed(house,requested))p.sendMessage("Other House worlds are unavailable through this Guild passage.");travelMenu(p,data);});}
|
|
|
|
|
private static GuildBookings.Permit permit(JsonObject data){String house=selection(data);if(house==null||!data.has("keyId")||data.get("keyId").isJsonNull())return null;try{return new GuildBookings.Permit(house,UUID.fromString(data.get("keyId").getAsString()),data.get("version").getAsInt());}catch(RuntimeException invalid){return null;}}
|
|
|
|
|
private void travelMenu(Player p,JsonObject data){
|
|
|
|
|
String house=selection(data);var home=GuildRoutes.home(house);if(home==null){select(p,data,null);return;}
|
|
|
|
|
String quote;try{quote=guild==null?"Guild service unavailable":"Guild fare: "+guild.quote(p,home.world())+" DM from your game wallet. Paid at departure.";}catch(RuntimeException unavailable){quote="Guild fare unavailable.";}
|
|
|
|
|
var booked=bookings.get(p.getUniqueId());String detail=quote+"\nImperial departures every 15 minutes."+(booked==null?"":"\nYour passage is already booked.");
|
|
|
|
|
if(BedrockForms.isBedrock(p)){List<BedrockForms.Choice> choices=new ArrayList<>();for(var route:GuildRoutes.ALL){boolean allowed=route.house().equals(house);choices.add(new BedrockForms.Choice((allowed?"§6":"§8")+route.name()+(allowed?" · Your House":" · Unavailable"),allowed?detail:"Another House world",allowed?()->bookPassage(p,data):()->travelMenu(p,data),"https://www.dunerealms.com/assets/gui/guild-world-"+route.world().replace('_','-')+(allowed?"":"-locked")+"-v1.png"));}choices.add(new BedrockForms.Choice("Cancel booking","No fare has been charged",()->{cancelBooking(p);travelMenu(p,data);}));choices.add(new BedrockForms.Choice("Your Mentat","Return to your House adviser",()->mentat(p,data)));BedrockForms.show(this,p,"Spacing Guild · Imperial passage",detail,choices);return;}
|
|
|
|
|
int own=Arrays.asList(IDS).indexOf(house);Screen screen=screen(p,"Spacing Guild · Imperial passage",0xE330+own);
|
|
|
|
|
for(int i=0;i<GuildRoutes.ALL.size();i++){var route=GuildRoutes.ALL.get(i);boolean allowed=route.house().equals(house);var item=icon(p,route.name(),allowed?detail:"Unavailable · another House world","drgui_transparent",allowed?Material.ENDER_PEARL:Material.GRAY_DYE);int centre=CENTRES[i];for(int row=i<3?-1:0;row<=1;row++)for(int col=-1;col<=1;col++){int slot=centre+row*9+col;screen.inventory.setItem(slot,item.clone());if(allowed)screen.actions.put(slot,()->bookPassage(p,data));}}
|
|
|
|
|
button(screen,p,45,"Your Mentat","Return to your House adviser",Material.ARROW,()->mentat(p,data));screen.actions.put(46,screen.actions.get(45));
|
|
|
|
|
button(screen,p,49,"Cancel booking","No fare is taken for a cancelled booking",Material.BARRIER,()->{cancelBooking(p);travelMenu(p,data);});for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
|
|
|
|
if(guild!=null){button(screen,p,53,booked==null?"Book passage":"Review booked passage",detail,Material.EMERALD,()->bookPassage(p,data));screen.actions.put(52,screen.actions.get(53));}
|
|
|
|
|
p.openInventory(screen.inventory);expire(screen);
|
|
|
|
|
}
|
|
|
|
|
private void cancelBooking(Player p){boolean removed=bookings.cancel(p.getUniqueId());removed=boarding.remove(p.getUniqueId())||removed;p.sendMessage(removed?"Guild passage cancelled. No fare was charged.":"You have no pending Guild booking.");}
|
|
|
|
|
private void bookPassage(Player p,JsonObject shown){
|
|
|
|
|
if(boarding.contains(p.getUniqueId())){p.sendMessage("Guild boarding is already being confirmed.");return;}
|
|
|
|
|
var expected=permit(shown);if(expected==null){p.sendMessage("Confirm your current House key before booking passage.");select(p,shown,selection(shown));return;}
|
|
|
|
|
fetch(p,null,0,null,fresh->{var current=permit(fresh);if(current==null||!current.equals(expected)){p.sendMessage("Your House key changed. Review the current passage.");travelMenu(p,fresh);return;}
|
|
|
|
|
var home=GuildRoutes.home(current.house());try{if(guild==null)throw new IllegalStateException("Guild travel service unavailable.");int fare=guild.quote(p,home.world());if(!guild.affordable(p,fare))throw new IllegalStateException("Not enough Dunemarks in your game wallet for the Guild fare ("+fare+" DM).");
|
|
|
|
|
var booked=bookings.book(p.getUniqueId(),current,home.world(),fare,Instant.now().getEpochSecond());p.closeInventory();p.sendMessage(Component.text("Passage booked to "+home.name()+" for the next Imperial departure. Fare "+booked.fare()+" DM is checked and collected at boarding. No fare has been charged yet.",NamedTextColor.GOLD));
|
|
|
|
|
}catch(RuntimeException unavailable){p.sendMessage(Component.text(unavailable.getMessage(),NamedTextColor.RED));}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
private void board(GuildBookings.Booking booking){
|
|
|
|
|
Player p=Bukkit.getPlayer(booking.player());if(p==null||!p.isOnline()||!lobby(p)||guild==null||!boarding.add(booking.player()))return;
|
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(this,()->{JsonObject data=null;boolean online=false;try{data=bridge.request(booking.player(),null,0,null);online=bridge.worldOnline(booking.world());}catch(Exception unavailable){}JsonObject fresh=data;boolean destinationOnline=online;if(!isEnabled())return;
|
|
|
|
|
Bukkit.getScheduler().runTask(this,()->{if(!boarding.remove(booking.player()))return;if(!p.isOnline()||!lobby(p))return;
|
|
|
|
|
try{var current=fresh==null?null:permit(fresh);if(current==null||!booking.matches(current,guild.quote(p,booking.world()),Instant.now().getEpochSecond())||!destinationOnline||!guild.affordable(p,booking.fare())){p.sendMessage("Guild boarding could not be confirmed: your key, fare, funds or destination changed. No fare was taken; please rebook.");return;}
|
|
|
|
|
p.closeInventory();p.sendMessage(Component.text("Imperial boarding · "+GuildRoutes.home(current.house()).name(),NamedTextColor.GOLD));guild.requestDeparture(p,booking.world());
|
|
|
|
|
}catch(RuntimeException unavailable){p.sendMessage("The Guild could not request your departure. Reopen the passage menu.");}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
private void fetch(Player p,String house,int version,UUID requestId,Consumer<JsonObject> callback){
|
|
|
|
|
UUID owner=p.getUniqueId();if(requests.containsKey(owner)){p.sendMessage("The House register is processing your request.");return;}
|
|
|
|
|
UUID operation=UUID.randomUUID();requests.put(owner,operation);p.closeInventory();p.sendMessage(Component.text("Jarvis executing matrix",NamedTextColor.GOLD));
|
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(this,()->{
|
|
|
|
|
JsonObject result=null;String error=null;
|
|
|
|
|
try{result=bridge.request(owner,house,version,requestId);}catch(Exception unavailable){error=unavailable instanceof java.io.IOException?unavailable.getMessage():"The House register is unavailable. Please retry.";}
|
|
|
|
|
JsonObject received=result;String failure=error;if(!isEnabled())return;
|
|
|
|
|
Bukkit.getScheduler().runTask(this,()->{if(!operation.equals(requests.get(owner)))return;requests.remove(owner);if(!p.isOnline()||!lobby(p))return;
|
|
|
|
|
if(received==null){p.sendMessage(Component.text(failure,NamedTextColor.RED));return;}
|
|
|
|
|
records.put(owner,received);updateSidebar(p,received);callback.accept(received);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
private void refreshSidebar(Player p){
|
|
|
|
|
UUID owner=p.getUniqueId();if(requests.containsKey(owner))return;UUID operation=UUID.randomUUID();requests.put(owner,operation);
|
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(this,()->{JsonObject result=null;try{result=bridge.request(owner,null,0,null);}catch(Exception unavailable){}JsonObject received=result;if(!isEnabled())return;
|
|
|
|
|
Bukkit.getScheduler().runTask(this,()->{if(!operation.equals(requests.get(owner)))return;requests.remove(owner);if(!p.isOnline()||!lobby(p)||!sidebar.enabled(p))return;
|
|
|
|
|
if(received!=null){records.put(owner,received);updateSidebar(p,received);}else{records.remove(owner);sidebar.update(p,null,null);}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
private void updateSidebar(Player p,JsonObject data){String house=selection(data);sidebar.update(p,data,house==null?null:houseName(data,house));}
|
|
|
|
|
private void toggleSidebar(Player p){sidebar.toggle(p);p.sendMessage(Component.text(sidebar.enabled(p)?"Personal scoreboard enabled.":"Personal scoreboard hidden.",NamedTextColor.GOLD));if(sidebar.enabled(p)){JsonObject data=records.get(p.getUniqueId());if(data!=null)updateSidebar(p,data);refreshSidebar(p);}}
|
|
|
|
|
@EventHandler public void scoreboardCommand(PlayerCommandPreprocessEvent e){String command=e.getMessage().trim();if(command.equalsIgnoreCase("/scoreboard")&&lobby(e.getPlayer())){e.setCancelled(true);toggleSidebar(e.getPlayer());}}
|
|
|
|
|
@EventHandler public void join(PlayerJoinEvent e){Bukkit.getScheduler().runTaskLater(this,()->{if(e.getPlayer().isOnline()&&lobby(e.getPlayer())&&sidebar.enabled(e.getPlayer()))refreshSidebar(e.getPlayer());},40L);}
|
|
|
|
|
@EventHandler public void world(PlayerChangedWorldEvent e){bookings.cancel(e.getPlayer().getUniqueId());boarding.remove(e.getPlayer().getUniqueId());sidebar.hide(e.getPlayer());records.remove(e.getPlayer().getUniqueId());if(lobby(e.getPlayer())&&sidebar.enabled(e.getPlayer()))refreshSidebar(e.getPlayer());}
|
|
|
|
|
static String selection(JsonObject data){if(!data.has("selection")||data.get("selection").isJsonNull())return null;String value=data.get("selection").getAsString();return HOUSE_IDS.contains(value)?value:null;}
|
|
|
|
|
private String houseName(JsonObject data,String id){for(var entry:data.getAsJsonArray("choices")){var h=entry.getAsJsonObject();if(h.get("id").getAsString().equals(id))return h.get("name").getAsString();}throw new IllegalArgumentException("Unknown House");}
|
|
|
|
|
private void select(Player p,JsonObject data,String picked){
|
|
|
|
|
String current=selection(data),chosen=picked!=null?picked:current;
|
|
|
|
|
if(BedrockForms.isBedrock(p)){
|
|
|
|
|
List<BedrockForms.Choice> choices=new ArrayList<>();
|
|
|
|
|
for(var entry:data.getAsJsonArray("choices")){var house=entry.getAsJsonObject();String id=house.get("id").getAsString();if(!HOUSE_IDS.contains(id))continue;
|
|
|
|
|
choices.add(new BedrockForms.Choice(house.get("name").getAsString()+(id.equals(current)?" · Your House":""),"Review and confirm allegiance",()->confirmForm(p,data,id),"https://www.dunerealms.com/assets/seals/"+house.get("seal").getAsString()));
|
|
|
|
|
}
|
|
|
|
|
choices.add(new BedrockForms.Choice(sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Personal briefing display",()->{toggleSidebar(p);select(p,data,picked);}));
|
|
|
|
|
BedrockForms.show(this,p,"Choose your House","Declare your allegiance. Review a House before confirming.",choices);return;
|
|
|
|
|
}
|
|
|
|
|
Screen screen=screen(p,"Choose your House",0xE300+(chosen==null?0:Arrays.asList(IDS).indexOf(chosen)+1));
|
|
|
|
|
for(int i=0;i<IDS.length;i++){String id=IDS[i];int centre=CENTRES[i];boolean selected=id.equals(chosen);
|
|
|
|
|
var item=icon(p,houseName(data,id),selected?"Selected · confirm below":"Click to select this House","drgui_transparent",Material.PAPER);
|
|
|
|
|
for(int row=i<3?-1:0;row<=1;row++)for(int col=-1;col<=1;col++){int slot=centre+row*9+col;screen.inventory.setItem(slot,item.clone());screen.actions.put(slot,()->select(p,data,id));}
|
|
|
|
|
}
|
|
|
|
|
button(screen,p,45,"Close","Return to the lobby",Material.ARROW,p::closeInventory);
|
|
|
|
|
button(screen,p,49,sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Toggle your personal briefing",Material.LEVER,()->{toggleSidebar(p);select(p,data,chosen);});
|
|
|
|
|
for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
|
|
|
|
if(chosen!=null)button(screen,p,53,"Confirm "+houseName(data,chosen),"Write your confirmed House key",Material.LIME_DYE,()->confirm(p,data,chosen));
|
|
|
|
|
screen.actions.put(46,screen.actions.get(45));if(chosen!=null)screen.actions.put(52,screen.actions.get(53));
|
|
|
|
|
p.openInventory(screen.inventory);expire(screen);
|
|
|
|
|
}
|
|
|
|
|
private void confirmForm(Player p,JsonObject data,String id){BedrockForms.show(this,p,"Confirm House · "+houseName(data,id),"Confirm your allegiance to "+houseName(data,id)+". This initial selection does not grant an elected office.",List.of(new BedrockForms.Choice("Confirm House","Save through J.A.R.V.I.S.",()->confirm(p,data,id)),new BedrockForms.Choice("Back","Review all five Houses",()->select(p,data,id))));}
|
|
|
|
|
private void confirm(Player p,JsonObject data,String id){
|
|
|
|
|
if(id.equals(selection(data))&&data.has("keyId")&&!data.get("keyId").isJsonNull()){mentat(p,data);return;}
|
|
|
|
|
fetch(p,id,data.get("version").getAsInt(),UUID.randomUUID(),saved->{p.sendMessage(Component.text("House allegiance confirmed in J.A.R.V.I.S.",NamedTextColor.GREEN));mentat(p,saved);});
|
|
|
|
|
}
|
|
|
|
|
private void mentat(Player p,JsonObject data){
|
|
|
|
|
String house=selection(data);if(house==null){select(p,data,null);return;}
|
|
|
|
|
JsonObject mentor=data.getAsJsonObject("mentat");String name=mentor.get("name").getAsString();int index=Arrays.asList(IDS).indexOf(house);
|
|
|
|
|
if(BedrockForms.isBedrock(p)){BedrockForms.show(this,p,"Your Mentat · "+name,houseName(data,house)+"\nYour House briefing is ready.",List.of(new BedrockForms.Choice("Open Mentat Report","Open your website mission journal",()->report(p),"https://www.dunerealms.com/assets/gui/mentat-"+house+"-v1.png"),new BedrockForms.Choice(sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Personal briefing display",()->{toggleSidebar(p);mentat(p,data);}),new BedrockForms.Choice("Spacing Guild travel","Book passage to your House world",()->openGuild(p,null))));return;}
|
|
|
|
|
Screen screen=screen(p,"Your Mentat · "+name,0xE310+index);
|
|
|
|
|
screen.inventory.setItem(13,icon(p,name,houseName(data,house),"drgui_transparent",Material.PLAYER_HEAD));
|
|
|
|
|
button(screen,p,38,"Open Mentat Report","Personal level, Reputation and active quests",Material.WRITABLE_BOOK,()->report(p));
|
|
|
|
|
button(screen,p,42,"Spacing Guild travel","Book passage to your House world",Material.COMPASS,()->openGuild(p,null));
|
|
|
|
|
button(screen,p,45,"Your House",houseName(data,house),Material.ARROW,()->select(p,data,house));
|
|
|
|
|
button(screen,p,49,sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Toggle your personal briefing",Material.LEVER,()->{toggleSidebar(p);mentat(p,data);});for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49));
|
|
|
|
|
for(int slot:new int[]{37,39})screen.actions.put(slot,screen.actions.get(38));for(int slot:new int[]{41,43})screen.actions.put(slot,screen.actions.get(42));screen.actions.put(46,screen.actions.get(45));
|
|
|
|
|
p.openInventory(screen.inventory);expire(screen);
|
|
|
|
|
}
|
|
|
|
|
private void report(Player p){p.closeInventory();p.sendMessage(Component.text("Open your Mentat Report →",NamedTextColor.GOLD).clickEvent(net.kyori.adventure.text.event.ClickEvent.openUrl("https://clans.dunerealms.com/#quests/quests")));}
|
|
|
|
|
private Screen screen(Player p,String title,int glyph){Screen s=new Screen(p);Component heading=p.hasResourcePack()?Component.text(GuiArtwork.background(glyph),NamedTextColor.WHITE).font(Key.key("dunerealms:house_selector")):Component.text(title,NamedTextColor.GOLD);s.inventory=Bukkit.createInventory(s,54,heading);return s;}
|
|
|
|
|
private ItemStack icon(Player p,String title,String description,String model,Material fallback){ItemStack item=new ItemStack(p.hasResourcePack()?Material.PAPER:fallback);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(List.of(Component.text(description,NamedTextColor.GRAY)));if(p.hasResourcePack())meta.setItemModel(new NamespacedKey("dunerealms",model));item.setItemMeta(meta);return item;}
|
|
|
|
|
private void button(Screen s,Player p,int slot,String title,String description,Material material,Runnable action){s.inventory.setItem(slot,icon(p,title,description,"drgui_transparent",material));s.actions.put(slot,action);}
|
|
|
|
|
private void expire(Screen screen){Bukkit.getScheduler().runTaskLater(this,screen.gate::expire,2400L);}
|
|
|
|
|
@EventHandler public void click(InventoryClickEvent event){if(!(event.getView().getTopInventory().getHolder() instanceof Screen s))return;event.setCancelled(true);
|
|
|
|
|
if(!(event.getWhoClicked() instanceof Player p)||!p.getUniqueId().equals(s.owner)||event.getClickedInventory()!=s.inventory||event.getClick()!=ClickType.LEFT)return;
|
|
|
|
|
Runnable action=s.actions.get(event.getRawSlot());if(action==null||!s.gate.claim(p.getUniqueId()))return;
|
|
|
|
|
Bukkit.getScheduler().runTask(this,()->{if(p.isOnline()&&lobby(p)&&p.getOpenInventory().getTopInventory()==s.inventory)action.run();});
|
|
|
|
|
}
|
|
|
|
|
@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){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);
|
|
|
|
|
}
|
|
|
|
|
@EventHandler public void npc(PlayerInteractEntityEvent e){if(!e.getRightClicked().getPersistentDataContainer().has(registrar,PersistentDataType.BYTE))return;e.setCancelled(true);if(e.getHand()!=EquipmentSlot.HAND||!lobby(e.getPlayer()))return;fetch(e.getPlayer(),null,0,null,data->{if(selection(data)!=null)mentat(e.getPlayer(),data);else select(e.getPlayer(),data,null);});}
|
|
|
|
|
private void tick(){
|
|
|
|
|
long remaining=DepartureWindow.remaining(Instant.now().getEpochSecond());departure.setTitle("Spacing Guild · Imperial departure window in "+String.format(Locale.ROOT,"%02d:%02d",remaining/60,remaining%60));departure.setProgress(remaining/900.0);
|
|
|
|
|
long now=Instant.now().getEpochSecond();for(var booking:bookings.due(now))board(booking);
|
|
|
|
|
if((remaining==300||remaining==60||remaining==10)&&lastDepartureNotice!=now){lastDepartureNotice=now;for(Player p:Bukkit.getOnlinePlayers())if(lobby(p))p.sendMessage(Component.text("Spacing Guild · next Imperial transport in "+(remaining>=60?remaining/60+" minute(s).":remaining+" seconds."),NamedTextColor.GOLD));}
|
|
|
|
|
for(World world:Bukkit.getWorlds())if(world.getName().equals("guild_lobby")){var battle=world.getEnderDragonBattle();if(battle!=null){if(battle.getBossBar()!=null){battle.getBossBar().setVisible(false);battle.getBossBar().removeAll();}
|
|
|
|
|
if(!detached.containsKey(world.getUID()))try{Object handle=world.getClass().getMethod("getHandle").invoke(world);detached.put(world.getUID(),DragonController.detach(handle));getLogger().info("Lobby dragon controller detached; native bossbar disabled.");}catch(ReflectiveOperationException|RuntimeException unsupported){if(dragonWarnings.add(world.getUID()))getLogger().warning("Lobby dragon controller could not be detached; native bossbar fallback active.");}
|
|
|
|
|
}}
|
|
|
|
|
for(Player p:Bukkit.getOnlinePlayers())if(lobby(p)){if(!departure.getPlayers().contains(p))departure.addPlayer(p);}else departure.removePlayer(p);
|
|
|
|
|
}
|
|
|
|
|
}
|