Skip to content

Instantly share code, notes, and snippets.

@jasonw4331
Last active June 11, 2020 11:58
Show Gist options
  • Save jasonw4331/3f46cba319f99bc1d7d1fd8747e46cf8 to your computer and use it in GitHub Desktop.
Save jasonw4331/3f46cba319f99bc1d7d1fd8747e46cf8 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
/**
* @name DownloadableResources
* @main jasonwynn10\DownloadableResources\Main
* @version 0.1.0
* @api 3.0.0
* @description A plugin script which automatically downloads and adds resource packs according to links in the config
* @author jasonwynn10
*/
namespace jasonwynn10\DownloadableResources {
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\item\Item;
use pocketmine\level\Position;
use pocketmine\plugin\PluginBase;
use pocketmine\resourcepacks\ZippedResourcePack;
use pocketmine\scheduler\Task;
use pocketmine\Server;
use pocketmine\utils\Internet;
class Main extends PluginBase {
public function onLoad() {
/** @var array $urlList */
$urlList = $this->getConfig()->getAll();
foreach($urlList as $name => $urlString) {
$manager = $this->getServer()->getResourcePackManager();
$resourcePackFolder = $manager->getPath();
if(!file_exists($resourcePackFolder.$name.".mcpack")) {
$packData = Internet::getURL($urlString, 3);
file_put_contents($resourcePackFolder.$name.".mcpack", $packData);
}
}
}
public function onEnable() {
$manager = $this->getServer()->getResourcePackManager();
$resourcePackFolder = $manager->getPath();
$packNames = $this->getConfig()->getAll(true);
foreach($packNames as $name) {
$pack = new ZippedResourcePack($resourcePackFolder.$name.".mcpack");
$reflection = new \ReflectionClass($manager);
$property = $reflection->getProperty("resourcePacks");
$property->setAccessible(true);
$currentResourcePacks = $property->getValue($manager);
$currentResourcePacks[] = $pack;
$property->setValue($manager, $currentResourcePacks);
$property = $reflection->getProperty("uuidList");
$property->setAccessible(true);
$currentUUIDPacks = $property->getValue($manager);
$currentUUIDPacks[strtolower($pack->getPackId())] = $pack;
$property->setValue($manager, $currentUUIDPacks);
}
}
}
}
@Wertzui123
Copy link

What does this?

@DerDevHD
Copy link

For me it looks like it downloads and installs resource-packs on the server.
(Sorry for late answer lol)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment