Skip to content

ResourcePackHost

Namespace Mc.Scripting.Content · Kind class (static)

public static class ResourcePackHost

A small built-in web server that hands out the resource packs plugins publish, so a plugin needs no web space of its own. It is off until it is configured (content.pack_host_port in Ramjet.toml, with pack_host_bind and the public pack_host_url) or started by code with ResourcePackHost.Start; it listens on 127.0.0.1 unless told otherwise, answers only GET / HEAD of /<sha1>.zip for packs that were published, and keeps nothing of the plugins that published them (a pack is removed when its plugin unloads).

Member Description
static string? BaseUrl { get; } The base URL the clients use (http://host:port), or null while the server is off.
static bool IsRunning { get; } Whether the server is listening.
static int Port { get; } The port the server listens on, 0 while it is off.
public static string? BaseUrl { get; }

The base URL the clients use (http://host:port), or null while the server is off.

public static bool IsRunning { get; }

Whether the server is listening.

public static int Port { get; }

The port the server listens on, 0 while it is off.

Member Description
static string Publish(ResourcePackFile pack) Publishes a pack and returns the URL it is downloadable from.
static string Start(string bind = "127.0.0.1", int port = 0, string? publicUrl = null) Starts the server (does nothing when it already runs).
static void Stop() Takes back the packs the calling plugin published, and stops the server when it was started by code (ResourcePackHost.Start) and no published pack of any plugin is left.
static void Unpublish(ResourcePackFile pack) Stops handing out a pack the calling plugin published (it stays available while another plugin publishes the same pack).
public static string Publish(ResourcePackFile pack)

Publishes a pack and returns the URL it is downloadable from. The pack stays available until the plugin that published it unloads (or ResourcePackHost.Unpublish).

Parameters

Name Type Description
pack ResourcePackFile The pack.

Returns string: The URL, http://host:port/<sha1>.zip.

Throws

  • System.InvalidOperationException: The server is off and not configured.
public static string Start(string bind = "127.0.0.1", int port = 0, string? publicUrl = null)

Starts the server (does nothing when it already runs).

Parameters

Name Type Description
bind string = "127.0.0.1" The address to listen on (default 127.0.0.1: this machine only; 0.0.0.0 for every interface, then give publicUrl).
port int = 0 The port, 0 for any free one.
publicUrl string? = null The base URL clients use to reach it (default http://<bind>:<port>).

Returns string: The base URL.

public static void Stop()

Takes back the packs the calling plugin published, and stops the server when it was started by code (ResourcePackHost.Start) and no published pack of any plugin is left. Packs of other plugins stay available; a server started by the configuration keeps running.

public static void Unpublish(ResourcePackFile pack)

Stops handing out a pack the calling plugin published (it stays available while another plugin publishes the same pack).

Parameters

Name Type Description
pack ResourcePackFile The pack.

ResourcePackFile