Skip to content
9 changes: 6 additions & 3 deletions examples/resourceexample/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: ResourceExample
version: 1.0.0
main: pjz9n\resourceexample\Main
api: 3.0.0
api: 4.0.0
commands:
resourceexample:
aliases:
- re
description: Manage ResourcePack
permission: resourceexample.command.resourceexample
permissions:
resourceexample.command.resourceexample:
default: true
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace pjz9n\resourceexample;

use pocketmine\form\Form;
use pocketmine\Player;
use pocketmine\player\Player;

class ExampleForm implements Form
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use pjz9n\resourcepacktools\ResourcePack;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\player\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat;

Expand Down
2 changes: 1 addition & 1 deletion resourcepacktools/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: ResourcePackToolsPlugin
version: 2.2.0
main: pjz9n\resourcepacktools\Main
api: 3.0.0
api: 4.0.0
commands:
resourcepack:
description: Manage ResourcePack
Expand Down
1 change: 1 addition & 0 deletions resourcepacktools/resources/locale/eng.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ command.validate.onlynumeric = Only numeric can be used as arguments.
resourcepack.notfound = ResourcePack does not exist.
resourcepack.register.success = The ResourcePack ({%0}) was registered successfully.
resourcepack.unregister.success = The ResourcePack ({%0}) was unregistered successfully.
resourcepack.unknown = "not supported."
1 change: 1 addition & 0 deletions resourcepacktools/resources/locale/jpn.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ command.validate.onlynumeric = 引数には数字のみ使用できます。
resourcepack.notfound = リソースパックが存在しません。
resourcepack.register.success = リソースパック ({%0}) の登録に成功しました。
resourcepack.unregister.success = リソースパック ({%0}) の登録解除に成功しました。
resourcepack.unknown = 非対応
32 changes: 19 additions & 13 deletions resourcepacktools/src/pjz9n/resourcepacktools/Main.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Copyright (c) 2020 PJZ9n.
*
Expand All @@ -25,29 +24,27 @@

use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\lang\BaseLang;
use pocketmine\lang\Language;
use pocketmine\plugin\PluginBase;
use pocketmine\resourcepacks\ResourcePack as PMResourcePack;
use pocketmine\resourcepacks\ResourcePackException;
use pocketmine\resourcepacks\ZippedResourcePack;
use pocketmine\utils\TextFormat;
use pocketmine\resourcepacks\ResourcePack as PMResourcePack;

class Main extends PluginBase
{
/** @var BaseLang */
private $lang;
class Main extends PluginBase {
/** @var Language */
private Language $lang;

public function onEnable(): void
{
public function onEnable(): void {
$this->saveDefaultConfig();
$configLang = (string)$this->getConfig()->get("lang", "def");
$lang = $configLang === "def" ? $this->getServer()->getLanguage()->getLang() : $configLang;
$localePath = $this->getFile() . "resources/locale/";
$this->lang = new BaseLang($lang, $localePath, "eng");
$this->lang = new Language($lang, $localePath, "eng");
$this->getLogger()->info($this->lang->translateString("language.selected", [$this->lang->getName()]));
}

public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool
{
public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool {
switch ($command) {//$command->__toString()
case "resourcepack":
if (!isset($args[0])) return false;
Expand Down Expand Up @@ -116,7 +113,12 @@ public function onCommand(CommandSender $sender, Command $command, string $label
//pack mode
$list = [];
foreach (ResourcePack::getPackList() as $index => $pack) {
if($pack instanceof ZippedResourcePack){
$list[] = (string)$index . " => " . $pack->getPath();

}else{
$list[] = (string)$index . " => " . $this->lang->translateString("resourcepack.unknown");
}
}
if (count($list) < 1) {
$sender->sendMessage(
Expand All @@ -132,7 +134,11 @@ public function onCommand(CommandSender $sender, Command $command, string $label
//uuid mode
$list = [];
foreach (ResourcePack::getUuidList() as $uuid => $pack) {
$list[] = (string)$uuid . " => " . $pack->getPath();
if($pack instanceof ZippedResourcePack) {
$list[] = (string)$uuid . " => " . $pack->getPath();
}else{
$list[] = (string)$uuid . " => ". $this->lang->translateString("resourcepack.unknown");
}
}
if (count($list) < 1) {
$sender->sendMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,28 @@

use pjz9n\resourcepacktools\manifest\Manifest;
use pocketmine\plugin\Plugin;
use pocketmine\plugin\PluginBase;
use ZipArchive;

class ResourcePackGenerator
{
/** @var Plugin */
private $plugin;
/** @var PluginBase */
private PluginBase $plugin;

/** @var Manifest */
private $manifest;
private Manifest $manifest;

/** @var string|null PluginResourceRelativePath */
private $packIcon;
private ?string $packIcon;

/** @var string[] ResourcePackPath => PluginResourceRelativePath */
private $files;
private array $files;

/**
* @param Plugin $plugin
* @param PluginBase $plugin
* @param Manifest $manifest
*/
public function __construct(Plugin $plugin, Manifest $manifest)
public function __construct(PluginBase $plugin, Manifest $manifest)
{
$this->plugin = $plugin;
$this->manifest = $manifest;
Expand Down Expand Up @@ -121,9 +122,9 @@ public function generate(string $generateFilePath, bool $overwrite = true): void
}

/**
* @return Plugin
* @return PluginBase
*/
protected function getPlugin(): Plugin
protected function getPlugin(): PluginBase
{
return $this->plugin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@
use pjz9n\resourcepacktools\manifest\Manifest;
use pjz9n\resourcepacktools\manifest\Module;
use pjz9n\resourcepacktools\manifest\Version;
use pocketmine\plugin\Plugin;
use pocketmine\utils\UUID;
use pocketmine\plugin\PluginBase;
use Ramsey\Uuid\Uuid;

class SimpleResourcePack extends ResourcePackGenerator
{
/**
* @param Plugin $plugin
* @param PluginBase $plugin
* @param Version $version
*/
public function __construct(Plugin $plugin, Version $version)
public function __construct(PluginBase $plugin, Version $version)
{
//TODO: Can header and module versions be different?
$manifest = new Manifest(
new Header(
"Auto generated by ResourcePackTools.",
$plugin->getName() . " ResourcePack.",
UUID::fromData($plugin->getName(), "header")->toString(),
Uuid::fromBytes(md5($plugin->getName() . "header", true))->toString(),
$version
),
[
new Module(
"Auto generated by ResourcePackTools.",
Module::TYPE_RESOURCES,
UUID::fromData($plugin->getName(), "module")->toString(),
Uuid::fromBytes(md5($plugin->getName() . "module", true))->toString(),
$version
),
]
Expand Down
2 changes: 1 addition & 1 deletion resourcepacktools/virion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ResourcePackTools
version: 2.2.0
antigen: pjz9n\resourcepacktools
api: 3.0.0
api: 4.0.0