From c5aa9be8840595a46f75dc9bb48d1a5ee43baa87 Mon Sep 17 00:00:00 2001 From: Aericio Date: Thu, 22 Nov 2018 21:49:35 -1000 Subject: [PATCH] Update to libFormAPI + v1.4.0 * Stop using deprecated methods * kill myself * update readme * use virion instead --- .poggit.yml | 3 + README.md | 3 + plugin.yml | 2 +- .../Commands/CustomEnchantCommand.php | 72 +++++++++---------- src/DaPigGuy/PiggyCustomEnchants/Main.php | 7 +- 5 files changed, 40 insertions(+), 47 deletions(-) diff --git a/.poggit.yml b/.poggit.yml index 0bbcb327..0b2f08e0 100644 --- a/.poggit.yml +++ b/.poggit.yml @@ -5,4 +5,7 @@ projects: PiggyCustomEnchants: path: "" icon: "resources/PCE_Icon.png" + libs: + - src: jojoe77777/FormAPI/libFormAPI + version: ^1.3 ... diff --git a/README.md b/README.md index c067fa55..a5eea434 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,8 @@ PiggyCustomEnchants is an open-sourced custom enchants plugin for PMMP. * We do not support any spoons. Anything to do with spoons (Issues or PRs) will be ignored. * You can find a list of the current custom enchants in the [wiki](https://github.com/DaPigGuy/PiggyCustomEnchants/wiki/Enchantments) * If you want a public custom enchant to be added, you can request it to be added by submitting them to our [google form](https://docs.google.com/forms/d/e/1FAIpQLScfWdk8OyQ6NNw6KiJxP_4CH4GHnKlaFr4VfZIQojk7OPlyoQ/viewform). You do not need to be logged in to submit a form. If you want credit to the idea, state your username anywhere in the form. +* We are using the [libFormAPI](https://github.com/jojoe77777/FormAPI), so there is no need to install the FormAPI plugin. + * In other words, you must use the pre-compiled phar from [Poggit-CI](https://poggit.pmmp.io/ci/DaPigGuy/PiggyCustomEnchants/~) instead of GitHub. + * If you wish to run it via source, check out [DEVirion](https://github.com/poggit/devirion). * Are you a developer? Check out our API Documentation at [PiggyDocs.](https://dapigguy.github.io/PiggyCustomEnchants/) * Check out our [Discord Server](https://discord.gg/ZZewRQH) for additional plugin support. diff --git a/plugin.yml b/plugin.yml index 5a136e5c..3a7a1a5b 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: PiggyCustomEnchants main: DaPigGuy\PiggyCustomEnchants\Main -version: 1.3.0 +version: 1.4.0 api: 3.0.0 load: POSTWORLD author: DaPigGuy diff --git a/src/DaPigGuy/PiggyCustomEnchants/Commands/CustomEnchantCommand.php b/src/DaPigGuy/PiggyCustomEnchants/Commands/CustomEnchantCommand.php index e3384de4..fe2cb2c7 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/Commands/CustomEnchantCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/Commands/CustomEnchantCommand.php @@ -4,6 +4,8 @@ use DaPigGuy\PiggyCustomEnchants\CustomEnchants\CustomEnchants; use DaPigGuy\PiggyCustomEnchants\Main; +use jojoe77777\FormAPI\CustomForm; +use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\command\ConsoleCommandSender; use pocketmine\command\PluginCommand; @@ -12,7 +14,7 @@ /** * Class CustomEnchantCommand - * @package PiggyCustomEnchants\Commands + * @package DaPigGuy\PiggyCustomEnchants\Commands */ class CustomEnchantCommand extends PluginCommand { @@ -39,7 +41,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $forms = $sender instanceof Player && $plugin->formsEnabled && ($formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI")) instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled(); + $forms = $sender instanceof Player && $plugin->formsEnabled; if (count($args) < 1) { if ($forms) { $this->formMenu($sender); @@ -142,9 +144,8 @@ public function formMenu(Player $player) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createSimpleForm(function (Player $player, ?int $data) { + if ($plugin->formsEnabled) { + $form = new SimpleForm(function (Player $player, ?int $data) { if (!is_null($data)) { switch ($data) { case 0: @@ -191,7 +192,7 @@ public function formMenu(Player $player) $form->addButton("Help"); $form->addButton("Info"); $form->addButton("List"); - $form->sendToPlayer($player); + $player->sendForm($form); } } } @@ -205,9 +206,8 @@ public function errorForm(Player $player, $error) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createSimpleForm(function (Player $player, ?int $data) { + if ($plugin->formsEnabled) { + $form = new SimpleForm(function (Player $player, ?int $data) { if (!is_null($data)) { $this->formMenu($player); return; @@ -216,7 +216,7 @@ public function errorForm(Player $player, $error) $form->setTitle(TextFormat::RED . "Error"); $form->setContent($error); $form->addButton(TextFormat::BOLD . "Back"); - $form->sendToPlayer($player); + $player->sendForm($form); return true; } } @@ -230,9 +230,8 @@ public function aboutForm(Player $player) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createSimpleForm(function (Player $player, ?int $data) { + if ($plugin->formsEnabled) { + $form = new SimpleForm(function (Player $player, ?int $data) { if (!is_null($data)) { $this->formMenu($player); } @@ -240,7 +239,7 @@ public function aboutForm(Player $player) $form->setTitle(TextFormat::GREEN . "About"); $form->setContent(TextFormat::GREEN . "PiggyCustomEnchants v" . $this->getPlugin()->getDescription()->getVersion() . " is a custom enchants plugin made by DaPigGuy (IGN: MCPEPIG) & Aericio. You can find it at https://github.com/DaPigGuy/PiggyCustomEnchants."); $form->addButton(TextFormat::BOLD . "Back"); - $form->sendToPlayer($player); + $player->sendForm($form); } } } @@ -252,9 +251,8 @@ public function enchantForm(Player $player) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createCustomForm(function (Player $player, ?array $data) { + if ($plugin->formsEnabled) { + $form = new CustomForm(function (Player $player, ?array $data) { if (!is_null($data)) { if (isset($data[0]) && isset($data[1]) && isset($data[2])) { $this->checkEnchantForm($player, $data); @@ -265,7 +263,7 @@ public function enchantForm(Player $player) $form->addInput(TextFormat::GREEN . "Enchantment"); $form->addInput(TextFormat::GREEN . "Level", "", 1); $form->addInput(TextFormat::GREEN . "Player", "", $player->getName()); - $form->sendToPlayer($player); + $player->sendForm($form); } } } @@ -278,8 +276,7 @@ public function checkEnchantForm(Player $player, $data) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { + if ($plugin->formsEnabled) { $enchant = null; if (is_numeric($data[0])) { $enchant = CustomEnchants::getEnchantment((int)$data[0]); @@ -354,9 +351,8 @@ public function helpForm(Player $player) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createSimpleForm(function (Player $player, ?int $data) { + if ($plugin->formsEnabled) { + $form = new SimpleForm(function (Player $player, ?int $data) { if (!is_null($data)) { $this->formMenu($player); } @@ -364,7 +360,7 @@ public function helpForm(Player $player) $form->setTitle(TextFormat::GREEN . "Help"); $form->setContent(TextFormat::GREEN . "Tell me you're joking... Why do you even need a help menu when you have the UI? Wait... why is this even here?"); $form->addButton(TextFormat::BOLD . "Back"); - $form->sendToPlayer($player); + $player->sendForm($form); } } } @@ -376,9 +372,8 @@ public function infoForm(Player $player) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createCustomForm(function (Player $player, ?array $data) { + if ($plugin->formsEnabled) { + $form = new CustomForm(function (Player $player, ?array $data) { if (!is_null($data)) { if (isset($data[0])) { $this->sendInfo($player, $data[0]); @@ -387,7 +382,7 @@ public function infoForm(Player $player) }); $form->setTitle(TextFormat::GREEN . "Info"); $form->addInput(TextFormat::GREEN . "Enchantment"); - $form->sendToPlayer($player); + $player->sendForm($form); } } } @@ -400,9 +395,8 @@ public function sendInfo(Player $player, $enchant) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createSimpleForm(function (Player $player, ?int $data) { + if ($plugin->formsEnabled) { + $form = new SimpleForm(function (Player $player, ?int $data) { if (!is_null($data)) { $this->formMenu($player); } @@ -415,7 +409,7 @@ public function sendInfo(Player $player, $enchant) $form->setContent(TextFormat::RED . "Invalid enchantment."); } $form->addButton(TextFormat::BOLD . "Back"); - $form->sendToPlayer($player); + $player->sendForm($form); } } } @@ -427,9 +421,8 @@ public function listForm(Player $player) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createSimpleForm(function (Player $player, ?int $data) { + if ($plugin->formsEnabled) { + $form = new SimpleForm(function (Player $player, ?int $data) { if (!is_null($data)) { $sorted = $this->getPlugin()->sortEnchants(); foreach ($sorted as $type => $enchants) { @@ -447,7 +440,7 @@ public function listForm(Player $player) $form->addButton($type); } $form->addButton(TextFormat::BOLD . "Back"); - $form->sendToPlayer($player); + $player->sendForm($form); } } } @@ -460,16 +453,15 @@ public function sendList(Player $player, $type) { $plugin = $this->getPlugin(); if ($plugin instanceof Main) { - $formsapi = $plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); - if ($plugin->formsEnabled && $formsapi instanceof \jojoe77777\FormAPI\FormAPI && $formsapi->isEnabled()) { - $form = $formsapi->createSimpleForm(function (Player $player, $data) { + if ($plugin->formsEnabled) { + $form = new SimpleForm(function (Player $player, $data) { if (!is_null($data)) { $this->formMenu($player); } }); $form->setContent(TextFormat::GREEN . TextFormat::BOLD . $type . "\n" . TextFormat::RESET . implode(", ", $this->getPlugin()->sortEnchants()[$type])); $form->addButton(TextFormat::BOLD . "Back"); - $form->sendToPlayer($player); + $player->sendForm($form); } } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/Main.php b/src/DaPigGuy/PiggyCustomEnchants/Main.php index 0e388457..96aba3a8 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/Main.php +++ b/src/DaPigGuy/PiggyCustomEnchants/Main.php @@ -276,11 +276,7 @@ public function onEnable() $this->initCustomEnchants(); $this->saveDefaultConfig(); if ($this->getConfig()->getNested("forms.enabled")) { - if ($this->getServer()->getPluginManager()->getPlugin("FormAPI") !== null) { - $this->formsEnabled = true; - } else { - $this->getLogger()->error("Forms are enabled but FormAPI is not found."); - } + $this->formsEnabled = true; } if ($this->getConfig()->getNested("blaze.flames")) { self::$blazeFlames = true; @@ -296,7 +292,6 @@ public function onEnable() foreach (self::PIGGY_ENTITIES as $piggyEntity) { Entity::registerEntity($piggyEntity, true); } - if (!ItemFactory::isRegistered(Item::ENCHANTED_BOOK)) { //Check if it isn't already registered by another plugin ItemFactory::registerItem(new Item(Item::ENCHANTED_BOOK, 0, "Enchanted Book")); //This is a temporary fix for name being Unknown when given due to no implementation in PMMP. Will remove when implemented in PMMP }