-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) 2024 AIPTU | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/AIPTU/Smaccer | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace aiptu\smaccer\command\argument; | ||
|
||
use CortexPE\Commando\args\StringEnumArgument; | ||
use pocketmine\command\CommandSender; | ||
|
||
class ReloadTypeArgument extends StringEnumArgument { | ||
public const CONFIG = 'config'; | ||
public const EMOTES = 'emotes'; | ||
|
||
protected const VALUES = [ | ||
'config' => self::CONFIG, | ||
'emotes' => self::EMOTES, | ||
]; | ||
|
||
public function getTypeName() : string { | ||
return 'reload'; | ||
} | ||
|
||
public function getEnumName() : string { | ||
return 'reloadType'; | ||
} | ||
|
||
public function parse(string $argument, CommandSender $sender) : string { | ||
return (string) $this->getValue($argument); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) 2024 AIPTU | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/AIPTU/Smaccer | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace aiptu\smaccer\command\subcommand; | ||
|
||
use aiptu\smaccer\Smaccer; | ||
use aiptu\smaccer\utils\Permissions; | ||
use CortexPE\Commando\BaseSubCommand; | ||
use pocketmine\command\CommandSender; | ||
use pocketmine\plugin\PluginBase; | ||
use pocketmine\utils\TextFormat; | ||
use function implode; | ||
use function sprintf; | ||
|
||
class AboutSubCommand extends BaseSubCommand { | ||
/** @param list<string> $aliases */ | ||
public function __construct( | ||
PluginBase $plugin, | ||
string $name, | ||
string $description = '', | ||
array $aliases = [] | ||
) { | ||
parent::__construct($plugin, $name, $description, $aliases); | ||
} | ||
|
||
public function onRun(CommandSender $sender, string $aliasUsed, array $args) : void { | ||
/** @var Smaccer $plugin */ | ||
$plugin = $this->plugin; | ||
|
||
$info = [ | ||
'Name' => $plugin->getFullName(), | ||
'Plugin API Version(s)' => implode(', ', $plugin->getDescription()->getCompatibleApis()), | ||
'Author(s)' => implode(', ', $plugin->getDescription()->getAuthors()), | ||
]; | ||
|
||
$sender->sendMessage(TextFormat::GREEN . 'Plugin Information:'); | ||
foreach ($info as $label => $value) { | ||
$this->sendFormattedMessage($sender, $label, $value); | ||
} | ||
} | ||
|
||
private function sendFormattedMessage(CommandSender $sender, string $label, string $value) : void { | ||
$sender->sendMessage(sprintf( | ||
'%s| %s | %s |', | ||
TextFormat::GREEN, | ||
TextFormat::WHITE . $label, | ||
TextFormat::GREEN . $value . TextFormat::RESET | ||
)); | ||
} | ||
|
||
public function prepare() : void { | ||
$this->setPermission(Permissions::COMMAND_ABOUT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) 2024 AIPTU | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/AIPTU/Smaccer | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace aiptu\smaccer\command\subcommand; | ||
|
||
use aiptu\smaccer\command\argument\ReloadTypeArgument; | ||
use aiptu\smaccer\Smaccer; | ||
use aiptu\smaccer\tasks\LoadEmotesTask; | ||
use aiptu\smaccer\utils\EmoteUtils; | ||
use aiptu\smaccer\utils\Permissions; | ||
use CortexPE\Commando\BaseSubCommand; | ||
use pocketmine\command\CommandSender; | ||
use pocketmine\plugin\PluginBase; | ||
use pocketmine\utils\TextFormat; | ||
|
||
class ReloadSubCommand extends BaseSubCommand { | ||
/** @param list<string> $aliases */ | ||
public function __construct( | ||
PluginBase $plugin, | ||
string $name, | ||
string $description = '', | ||
array $aliases = [] | ||
) { | ||
parent::__construct($plugin, $name, $description, $aliases); | ||
} | ||
|
||
public function onRun(CommandSender $sender, string $aliasUsed, array $args) : void { | ||
/** @var Smaccer $plugin */ | ||
$plugin = $this->plugin; | ||
|
||
$reloadType = $args['reloadType']; | ||
|
||
switch ($reloadType) { | ||
case ReloadTypeArgument::CONFIG: | ||
$plugin->reloadConfig(); | ||
$sender->sendMessage(TextFormat::GREEN . 'Configuration reloaded successfully.'); | ||
break; | ||
case ReloadTypeArgument::EMOTES: | ||
$plugin->getServer()->getAsyncPool()->submitTask(new LoadEmotesTask(EmoteUtils::getEmoteCachePath())); | ||
$sender->sendMessage(TextFormat::GREEN . 'Emotes reloaded successfully.'); | ||
break; | ||
default: | ||
$sender->sendMessage(TextFormat::RED . 'Invalid reload type specified.'); | ||
break; | ||
} | ||
} | ||
|
||
public function prepare() : void { | ||
$this->setPermissions([ | ||
Permissions::COMMAND_RELOAD_CONFIG, | ||
Permissions::COMMAND_RELOAD_EMOTES, | ||
]); | ||
|
||
$this->registerArgument(0, new ReloadTypeArgument('reloadType')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters