Search by

presentkim / resourcepack-register

PresentKim

Provides utils for registering resource packs for axolotl-pm/PocketMine-MP

Package info

github.com/presentkim-pm/resourcepack-register

pkg:composer/presentkim/resourcepack-register

Statistics

Installs: 227

Dependents: 1

Suggesters: 0

Stars: 3

Open Issues: 0

2.2.0 2026-12-01 21:00 UTC

This package is auto-updated.

Last update: 2026-12-01 21:01:29 UTC


README

Packagist CI Stars License


Logo

resourcepack-register

Register a resource pack from your plugin's resources, no zipping and no files for the server owner to copy.

Packagist ยท Changelog ยท Report a bug ยท Request a feature

protected function onEnable() : void{
    ResourcePackRegister::registerFromResource($this, "pack"); // resources/pack/manifest.json ...
}

๐ŸŒŸ Why resourcepack-register?

  • Plain folders : keep the pack as a folder in resources/, it is zipped when the plugin enables
  • Nothing left behind : by default the zip is loaded into memory and the temporary file is deleted at once
  • Stable hash : the archive is reproducible, so clients do not re-download an unchanged pack after every restart
  • No rebuild on restart : a zip kept in resource_packs/ is reused while the pack folder is unchanged
  • Minified : .json files (comments and trailing commas allowed) are minified, hidden files are skipped
  • Bound to your plugin : bindFromResource() removes the pack again when the plugin is disabled
  • Beyond resource packs : behavior packs, experiment toggles and CDN urls, added to the packets without undoing what other plugins added
  • Tested : on PHP 8.4 / 8.5 against the real ResourcePackManager

๐Ÿ“ฆ Installation

composer require presentkim/resourcepack-register
Requirement Version
Server axolotl-pm/PocketMine-MP (fork of PocketMine-MP 5)
PHP 8.4 or newer (with ext-zip)

The Poggit virion for the original PocketMine-MP 5.44 and older is kept on the legacy/pmmp-5.44 branch (no longer maintained).

๐Ÿš€ Quick start

Put the pack in your plugin's resources/ folder, with the manifest.json at the root of the pack folder:

resources/
โ””โ”€ pack/
   โ”œโ”€ manifest.json
   โ””โ”€ textures/...
use kim\present\register\resourcepack\ResourcePackRegister;

final class Main extends PluginBase{

    protected function onEnable() : void{
        // Unregistered automatically when the plugin is disabled
        ResourcePackRegister::bindFromResource($this, "pack");
    }
}

Register in onEnable(), before players join: the pack is sent to players that join afterwards. bindFromResource() throws ResourcePackException if the pack cannot be built.

๐Ÿ“š Examples

Keep the zip in resource_packs/ instead of the temp folder
ResourcePackRegister::registerFromResource($this, "pack", false);
// writes resource_packs/_resourcepack-register.<PluginName>.pack.zip

Use this when the zip should survive in resource_packs/, for example to inspect it, or for a large pack: the source files are hashed on every start, and the zip is only rebuilt when a file was added, removed or changed (the hash is kept in the zip comment). By default the archive is built in the system temporary folder and loaded into memory, so it is built again on every start.

Any directory, any ResourcePack
$pack = ResourcePackRegister::registerFromDirectory("/path/to/pack");

ResourcePackRegister::registerPack(new ZippedResourcePack("/path/to/pack.zip"));
Require the pack, give up when it cannot be built
protected function onEnable() : void{
    try{
        ResourcePackRegister::bindFromResource($this, "pack", required: true);
    }catch(ResourcePackException | \InvalidArgumentException $e){
        $this->getLogger()->error("Unable to register the resource pack: " . $e->getMessage());
        $this->getServer()->getPluginManager()->disablePlugin($this);
        return;
    }
}

required: true makes players accept the server's packs to join. It is not turned off when the plugin is disabled, because other plugins may need it too. Registering a pack whose UUID is already registered throws InvalidArgumentException. A pack you built yourself is bound with ResourcePackRegister::bind($this, $pack).

Turn on experiments
use kim\present\register\resourcepack\ExperimentFlags;

ExperimentFlags::enable($this, ExperimentFlags::CREATOR_CAMERAS);

The flags are added to StartGamePacket and ResourcePackStackPacket next to the ones already there, so plugins can each enable their own. They stop being sent when the plugin is disabled.

Send a behavior pack
use kim\present\register\resourcepack\BehaviorPackRegister;

$pack = new ZippedResourcePack($this->getDataFolder() . "behavior.zip");
BehaviorPackRegister::register($this, $pack, hasScripts: false);
ExperimentFlags::enable($this, ExperimentFlags::DATA_DRIVEN_ITEMS);

The server only sends resource packs. The behavior pack is listed with them as an add-on pack (as Bedrock 1.21.100+ expects) and its download requests are answered by the library. Any ResourcePack works, TempResourcePack included.

Download a pack from a CDN
use kim\present\register\resourcepack\CdnUrlRegister;

CdnUrlRegister::set($this, $pack->getPackId(), $pack->getPackVersion(), "https://cdn.example.com/pack.zip");

The url is filled in for the matching pack (same UUID and version), whichever plugin registered it, unless it already has one. Clients then download it from the CDN instead of from the server.

Unregister by hand
ResourcePackRegister::unregisterPack($pack->getPackId());

๐Ÿ“– API reference

Method Description
registerPack(ResourcePack $pack, ?ResourcePackManager $manager = null) : void Append a pack to the resource stack
unregisterPack(string $packId, ?ResourcePackManager $manager = null) : bool Remove a pack (and its encryption key), false if not registered
bind(Plugin $plugin, ResourcePack $pack, bool $required = false, ?ResourcePackManager $manager = null) : ResourcePack Register a pack until the plugin is disabled
bindFromResource(PluginBase $plugin, string $path, bool $required = false, bool $isTemp = true, ?ResourcePackManager $manager = null) : ResourcePack Build, register, and unregister when the plugin is disabled
registerFromResource(PluginBase $plugin, string $path, bool $isTemp = true, ?ResourcePackManager $manager = null) : ResourcePack Build and register the pack in the plugin's resource folder
registerFromDirectory(string $dir, bool $isTemp = true, string $outputName = "", ?ResourcePackManager $manager = null) : ResourcePack Build and register the pack in any directory
archiveDirectory(string $sourceDir, string $outputPath) : void Zip a pack directory (sorted, minified json, no hidden files)
archiveDirectoryIfChanged(string $sourceDir, string $outputPath) : bool Same, but keep $outputPath when it was built from the same files; true if it was (re)built
loadZippedPack(string $sourceDir, string $outputPath) : ZippedResourcePack Build (or reuse) the zip at a path of your choice and load it, without registering
TempResourcePack A ResourcePack read from a zip into memory

Failures while building a pack throw ResourcePackException.

Class Method Description
ExperimentFlags enable(Plugin $plugin, string ...$names) / disable(...) / getEnabled(Plugin) Experiment toggles sent to clients
BehaviorPackRegister register(Plugin $plugin, ResourcePack $pack, bool $hasScripts = false) / unregister(Plugin, string $packId) / get() / getAll() Behavior packs sent with the resource packs
CdnUrlRegister set(Plugin $plugin, string $packId, string $version, string $url) / remove() / get() / clear() CDN urls of listed packs

Everything bound to a plugin is removed when that plugin is disabled, and must be set up in onEnable() or later (a plugin that is not enabled throws LogicException).

๐Ÿงช Development

composer install --ignore-platform-req='ext-*'
composer test

๐Ÿ“„ License

Distributed under the MIT License. See LICENSE for more information.