-
Notifications
You must be signed in to change notification settings - Fork 2
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
toby7002
committed
Oct 20, 2023
1 parent
9d1f295
commit ea5d284
Showing
6 changed files
with
112 additions
and
17 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
48 changes: 48 additions & 0 deletions
48
src/thebigcrafter/omp/commands/subcommands/PurgeCommand.php
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,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of oh-my-pmmp. | ||
* (c) thebigcrafter <[email protected]> | ||
* This source file is subject to the GPL-3.0 license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace thebigcrafter\omp\commands\subcommands; | ||
|
||
use CortexPE\Commando\args\RawStringArgument; | ||
use CortexPE\Commando\BaseSubCommand; | ||
use pocketmine\command\CommandSender; | ||
use thebigcrafter\Fluorine\Fluorine; | ||
use thebigcrafter\Iodine\Iodine; | ||
use thebigcrafter\omp\OhMyPMMP; | ||
use thebigcrafter\omp\tasks\RemovePlugin; | ||
|
||
class PurgeCommand extends BaseSubCommand | ||
{ | ||
protected function prepare() : void | ||
{ | ||
$this->setPermission("oh-my-pmmp.purge"); | ||
|
||
$this->registerArgument(0, new RawStringArgument("name", false)); | ||
} | ||
|
||
public function onRun(CommandSender $sender, string $aliasUsed, array $args) : void | ||
{ | ||
$pluginName = $args["name"]; | ||
|
||
Iodine::async(function() use ($pluginName, $sender) { | ||
try { | ||
RemovePlugin::run($pluginName, true)->await(); | ||
|
||
$sender->sendMessage(OhMyPMMP::getLanguage()->translate("command.purge.successfully", ["name" => $pluginName])); | ||
return; | ||
} catch (\Exception $e) { | ||
$sender->sendMessage(OhMyPMMP::getLanguage()->translate("command.purge.failed", ["reason" => $e->getMessage()])); | ||
} | ||
})->await(); | ||
|
||
Fluorine::run(); | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of oh-my-pmmp. | ||
* (c) thebigcrafter <[email protected]> | ||
* This source file is subject to the GPL-3.0 license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace thebigcrafter\omp\tasks; | ||
|
||
use Symfony\Component\Filesystem\Exception\IOException; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Filesystem\Path; | ||
use thebigcrafter\Iodine\DeferredFuture; | ||
use thebigcrafter\Iodine\Future; | ||
use thebigcrafter\omp\OhMyPMMP; | ||
|
||
class RemovePlugin | ||
{ | ||
public static function run(string $pluginName, bool $wipeData = false) : Future { | ||
$deferred = new DeferredFuture(); | ||
$fs = new Filesystem(); | ||
$pluginPath = Path::join(OhMyPMMP::getInstance()->getServer()->getDataPath(), "plugins/$pluginName.phar"); | ||
$pluginDataPath = Path::join(OhMyPMMP::getInstance()->getServer()->getDataPath(), "plugin_data/$pluginName"); | ||
|
||
if(!$fs->exists($pluginPath)) { | ||
$deferred->error(new \Exception(OhMyPMMP::getLanguage()->translate("text.plugin.not.found", ["name" => $pluginName]))); | ||
} else { | ||
try { | ||
if($wipeData) { | ||
$fs->remove([$pluginPath, $pluginDataPath]); | ||
} else { | ||
$fs->remove($pluginPath); | ||
} | ||
$deferred->complete(true); | ||
} catch (IOException $e) { | ||
$deferred->error($e); | ||
} | ||
} | ||
|
||
return $deferred->getFuture(); | ||
} | ||
} |