Put PocketMine resource packs on an S3 bucket. Players pull them from the public URL instead of your server.
PocketMine serves resource packs from the gameserver. On join it streams the zip in chunks. S3RP uploads those packs to some S3 bucket instead of using your server's bandwidth.
You'll notice download speed gains when packs are large, or new joins are many, or you frequently update your packs, or some amalgamation of these factors. This is most likely an overkill if you have a tiny pack and a quiet server.
Cloudflare R2 provides generous free limits for our use case. Follow the steps below to setup:
- From your Cloudflare dashboard, visit R2 Object Storage (under Storage & databases)
- Click Create Bucket. Give your bucket a name, then click Create bucket.
- Select your bucket. In your bucket's Settings, copy your S3 API.
- Set this as your
s3-bucket-endpointin pluginconfig.yml
- Set this as your
- Enable Public Development URL and copy the value.
- Set this as your
public-urlin pluginconfig.yml - Alternatively, you can configure Custom Domains which is what Cloudflare recommends for production usage.
- Set this as your
- Go back to R2 Object Storage page, select Manage API Tokens
- Select Create User API token.
- Set permission to Object Read & Write - S3RP auto-uploads packs to S3 so we need write permission.
- Under Specify bucket(s), select Apply to specific buckets only and select the bucket you just created.
- Click Create User API Token.
- Copy your Access Key ID.
- Set this as your
s3-access-key-idin pluginconfig.yml
- Set this as your
- Copy your Secret Access Key.
- Set this as your
s3-access-key-secretin pluginconfig.yml
- Set this as your
Done. Restart your server. S3RP will upload your server resource packs to Cloudflare R2 to serve your players.
Edit resource-packs in your config.yml. For example, if your server's resource_packs/resource_packs.yml looks like:
resource_stack:
- Deadpool.zip
- CapeResourcePack.zip
- BetterVanilla.mcpackAnd you want to host only BetterVanilla.mcpack, you would use this configuration:
resource-packs:
- BetterVanilla.mcpackRegister them with PocketMine first, then with S3RP. Use registerAndWait() / unregister() APIs to serve your resouce pack from CDN.
// first, register your pack to server's manager
$manager = $server->getResourcePackManager();
$stack = $manager->getResourceStack();
$stack[] = $my_resource_pack;
$manager->setResourceStack($stack);
// then let S3RP serve your pack from CDN
/** @var \cosmicpe\s3rp\Loader $plugin */
$plugin = $server->getPluginManager()->getPlugin("S3RP");
$plugin->registerAndWait($my_resource_pack);Cloudflare services are heavily throttled in Russia and China. You can cancel ResourcePackServeCdnEvent event to serve certain players the old fashion way (i.e., using your pocketmine server's bandwidth).
public function handleResourcePackServeCdn(ResourcePackServeCdnEvent $event) : void{
if($event->player->getUsername() === "Steve"){
$event->cancel();
}
}S3RP uploads. If you do not need that, you may want to go with something simpler like presentkim-pm/ResourcePackCdn. S3RP is not ideal if you already serve resource packs with nginx or any static host.