forked from unimatrix/web
Offer the central pack once per Velocity connection
This commit is contained in:
parent
0ef7cf3bf3
commit
9682f3c911
4 changed files with 89 additions and 0 deletions
14
network/proxy/central-pack/build.gradle.kts
Normal file
14
network/proxy/central-pack/build.gradle.kts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
plugins { java }
|
||||
group = "com.dunerealms"
|
||||
version = "1.0.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
dependencies {
|
||||
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
|
||||
}
|
||||
java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) }
|
||||
tasks.withType<JavaCompile> { options.encoding = "UTF-8" }
|
||||
4
network/proxy/central-pack/pack.properties.example
Normal file
4
network/proxy/central-pack/pack.properties.example
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Set both fields from the central pack release manifest after publishing the ZIP.
|
||||
# Keep disabled until the backend world overlays are replaced.
|
||||
url=
|
||||
sha1=
|
||||
1
network/proxy/central-pack/settings.gradle.kts
Normal file
1
network/proxy/central-pack/settings.gradle.kts
Normal file
|
|
@ -0,0 +1 @@
|
|||
rootProject.name = "DuneCentralPack"
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.dunerealms.proxy;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.player.ResourcePackInfo;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@Plugin(id = "dunecentralpack", name = "DuneRealms Central Pack", version = "1.0.0")
|
||||
public final class CentralPackPlugin {
|
||||
private static final UUID PACK_ID=UUID.fromString("a7b5ab7d-d8d8-5b51-b016-71a5f4c00008");
|
||||
private final ProxyServer proxy;
|
||||
private final Logger logger;
|
||||
private final Path directory;
|
||||
private final Map<UUID,Player> offered=new ConcurrentHashMap<>();
|
||||
private volatile ResourcePackInfo pack;
|
||||
|
||||
@Inject
|
||||
public CentralPackPlugin(ProxyServer proxy, Logger logger, @DataDirectory Path directory){
|
||||
this.proxy=proxy;
|
||||
this.logger=logger;
|
||||
this.directory=directory;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void initialize(ProxyInitializeEvent event){
|
||||
Path settings=directory.resolve("pack.properties");
|
||||
if(!Files.isRegularFile(settings))return;
|
||||
var properties=new Properties();
|
||||
try(var source=Files.newBufferedReader(settings)){
|
||||
properties.load(source);
|
||||
String url=properties.getProperty("url",""),hash=properties.getProperty("sha1","");
|
||||
if(!url.matches("https://www\\.dunerealms\\.com/downloads/DuneRealms-Central-v[1-9][0-9]*\\.zip")||!hash.matches("[a-f0-9]{40}")){
|
||||
throw new IllegalArgumentException("Expected a versioned DuneRealms pack URL and SHA-1");
|
||||
}
|
||||
pack=proxy.createResourcePackBuilder(url).setId(PACK_ID).setHash(HexFormat.of().parseHex(hash)).build();
|
||||
}catch(IOException|IllegalArgumentException failure){
|
||||
logger.error("Central resource pack is disabled: {}",failure.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void firstBackend(ServerPostConnectEvent event){
|
||||
ResourcePackInfo current=pack;
|
||||
Player player=event.getPlayer();
|
||||
if(current!=null&&player.isActive()&&offered.put(player.getUniqueId(),player)!=player){
|
||||
player.sendResourcePackOffer(current);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void disconnected(DisconnectEvent event){
|
||||
Player player=event.getPlayer();
|
||||
offered.remove(player.getUniqueId(),player);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff