forked from unimatrix/web
Coordinate common and material pack ownership through Velocity
This commit is contained in:
parent
085e99d905
commit
62638f4957
3 changed files with 238 additions and 9 deletions
|
|
@ -46,6 +46,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
private ExistingGuildService guild;
|
||||
private final GuildBookings bookings=new GuildBookings();
|
||||
private final Set<UUID> boarding=new HashSet<>();
|
||||
private ProxyPackBridge proxyPacks;
|
||||
private final Set<UUID> guiPackLoaded=new HashSet<>();
|
||||
private final Map<UUID,NetworkArtworkPolicy.Pack> offeredGuiPacks=new HashMap<>();
|
||||
private NetworkArtworkPolicy.Pack guiPack(Player player){
|
||||
|
|
@ -74,7 +75,8 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
registrar=new NamespacedKey(this,"house_registrar");
|
||||
modernMenus=new MCGUIMenus(this);
|
||||
ecologyArtwork=new EcologyArtwork(this);
|
||||
new PlanetTexturePacks(this);
|
||||
proxyPacks=new ProxyPackBridge(this,this::receiveProxyArtworkStatus);
|
||||
new PlanetTexturePacks(this,proxyPacks);
|
||||
|
||||
sidebar=new PersonalSidebar(this);nameplates=new PublicNameplates(this);
|
||||
for(String command:List.of("start","spice","sellall","exchange","house","mentat","drgui","drscoreboard","guildtravel","clan","company","polgui"))Objects.requireNonNull(getCommand(command)).setExecutor(this);
|
||||
|
|
@ -265,6 +267,11 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
private void offerGuiPack(Player p){offerGuiPack(p,true);}
|
||||
private void offerGuiPack(Player p,boolean force){
|
||||
if(!p.isOnline()||BedrockForms.isBedrock(p))return;
|
||||
if(proxyPacks.ownsCommon()){
|
||||
proxyPacks.requestStatus(p);
|
||||
if(lobby(p)){MCGUIMenus.offerPack(p);ecologyArtwork.offer(p);}
|
||||
return;
|
||||
}
|
||||
var pack=guiPack(p);
|
||||
if(!force&&pack.equals(offeredGuiPacks.get(p.getUniqueId())))return;
|
||||
guiPackLoaded.remove(p.getUniqueId());
|
||||
|
|
@ -281,8 +288,12 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto
|
|||
giveCodex(p,false);
|
||||
if(sidebar.enabled(p))refreshSidebar(p);
|
||||
},40L);}
|
||||
private void receiveProxyArtworkStatus(Player player,boolean loaded){
|
||||
if(loaded)guiPackLoaded.add(player.getUniqueId());
|
||||
else guiPackLoaded.remove(player.getUniqueId());
|
||||
}
|
||||
@EventHandler public void packStatus(PlayerResourcePackStatusEvent e){
|
||||
if(!NetworkArtworkPolicy.PACK_ID.equals(e.getID()))return;
|
||||
if(proxyPacks.ownsCommon()||!NetworkArtworkPolicy.PACK_ID.equals(e.getID()))return;
|
||||
getLogger().info("GUI pack status for "+e.getPlayer().getName()+": "+e.getStatus());
|
||||
if(e.getStatus()==PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED){guiPackLoaded.add(e.getPlayer().getUniqueId());e.getPlayer().sendMessage(Component.text("DuneRealms artwork loaded. Reopen your menu.",NamedTextColor.GREEN));return;}
|
||||
guiPackLoaded.remove(e.getPlayer().getUniqueId());
|
||||
|
|
|
|||
|
|
@ -23,14 +23,16 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
final class PlanetTexturePacks implements Listener {
|
||||
static final UUID PACK_ID=PlanetMaterialPolicy.PACK_ID;
|
||||
private final JavaPlugin plugin;
|
||||
private final ProxyPackBridge proxy;
|
||||
private final Map<String,Pack> packs=new HashMap<>();
|
||||
private final Map<String,String> worlds=new HashMap<>();
|
||||
private final Map<UUID,String> offered=new HashMap<>();
|
||||
private final boolean enabled;
|
||||
record Pack(String url,String hash,String name){}
|
||||
|
||||
PlanetTexturePacks(JavaPlugin plugin){
|
||||
PlanetTexturePacks(JavaPlugin plugin,ProxyPackBridge proxy){
|
||||
this.plugin=plugin;
|
||||
this.proxy=proxy;
|
||||
File file=new File(plugin.getDataFolder(),"planet-textures.yml");
|
||||
if(!file.exists())plugin.saveResource("planet-textures.yml",false);
|
||||
var config=YamlConfiguration.loadConfiguration(file);
|
||||
|
|
@ -64,21 +66,48 @@ final class PlanetTexturePacks implements Listener {
|
|||
}
|
||||
}catch(IllegalArgumentException invalid){valid=false;plugin.getLogger().warning("Planet material packs disabled: invalid planet-textures.yml");}
|
||||
enabled=valid&&config.getBoolean("enabled",false);
|
||||
proxy.onOverlayDirective(this::applyProxyDirective);
|
||||
Bukkit.getPluginManager().registerEvents(this,plugin);
|
||||
Bukkit.getScheduler().runTaskLater(plugin,()->Bukkit.getOnlinePlayers().forEach(this::offer),40L);
|
||||
}
|
||||
|
||||
private void offer(Player player){
|
||||
if(!player.isOnline()||BedrockForms.isBedrock(player))return;
|
||||
String profile=enabled?PlanetMaterialPolicy.profile(player.getWorld().getName(),worlds):null;
|
||||
String profile=profile(player);
|
||||
if(proxy.deduplicatesOverlays()){
|
||||
proxy.send(player,"overlay-request\t"+pin(profile));
|
||||
return;
|
||||
}
|
||||
String desired=profile==null?"none":profile;
|
||||
if(desired.equals(offered.get(player.getUniqueId())))return;
|
||||
apply(player,profile);
|
||||
offered.put(player.getUniqueId(),desired);
|
||||
}
|
||||
|
||||
private String profile(Player player){
|
||||
return enabled?PlanetMaterialPolicy.profile(player.getWorld().getName(),worlds):null;
|
||||
}
|
||||
|
||||
private String pin(String profile){
|
||||
if(profile==null)return "-";
|
||||
Pack pack=packs.get(profile);
|
||||
return profile+"\t"+pack.url()+"\t"+pack.hash();
|
||||
}
|
||||
|
||||
private void applyProxyDirective(Player player,String requested){
|
||||
if(!player.isOnline()||BedrockForms.isBedrock(player))return;
|
||||
String profile=profile(player);
|
||||
if(!pin(profile).equals(requested))return;
|
||||
apply(player,profile);
|
||||
proxy.send(player,"overlay-applied\t"+requested);
|
||||
}
|
||||
|
||||
private void apply(Player player,String profile){
|
||||
player.removeResourcePack(PACK_ID);
|
||||
if(profile!=null){
|
||||
Pack pack=packs.get(profile);
|
||||
player.addResourcePack(PACK_ID,pack.url(),HexFormat.of().parseHex(pack.hash()),"DuneRealms · "+pack.name()+" materials",false);
|
||||
}
|
||||
offered.put(player.getUniqueId(),desired);
|
||||
}
|
||||
@EventHandler public void join(PlayerJoinEvent event){
|
||||
Player player=event.getPlayer();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.BiConsumer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
final class ProxyPackBridge {
|
||||
static final String CHANNEL = "dunerealms:pack_control";
|
||||
private final JavaPlugin plugin;
|
||||
private final boolean common;
|
||||
private final boolean overlays;
|
||||
private BiConsumer<Player,String> overlayDirective;
|
||||
|
||||
ProxyPackBridge(JavaPlugin plugin, BiConsumer<Player,Boolean> artworkStatus) {
|
||||
this.plugin = plugin;
|
||||
common = plugin.getConfig().getBoolean("development.proxy-owns-common-pack", false);
|
||||
overlays = plugin.getConfig().getBoolean("development.proxy-deduplicates-material-packs", false);
|
||||
if (!common && !overlays) return;
|
||||
var messenger = plugin.getServer().getMessenger();
|
||||
messenger.registerOutgoingPluginChannel(plugin, CHANNEL);
|
||||
messenger.registerIncomingPluginChannel(plugin, CHANNEL, (channel, player, bytes) -> {
|
||||
if (bytes.length > 256) return;
|
||||
String message = new String(bytes, StandardCharsets.US_ASCII);
|
||||
if (common && message.equals("common-loaded")) artworkStatus.accept(player, true);
|
||||
else if (common && message.equals("common-unavailable")) artworkStatus.accept(player, false);
|
||||
else if (overlays && message.startsWith("apply ") && overlayDirective != null)
|
||||
overlayDirective.accept(player, message.substring(6));
|
||||
});
|
||||
}
|
||||
|
||||
boolean ownsCommon() { return common; }
|
||||
boolean deduplicatesOverlays() { return overlays; }
|
||||
void onOverlayDirective(BiConsumer<Player,String> receiver) { overlayDirective = receiver; }
|
||||
void requestStatus(Player player) { send(player, "common-status"); }
|
||||
|
||||
void send(Player player, String message) {
|
||||
player.sendPluginMessage(plugin, CHANNEL, message.getBytes(StandardCharsets.US_ASCII));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff