Skip to content

Commit

Permalink
Update to libFormAPI + v1.4.0
Browse files Browse the repository at this point in the history
* Stop using deprecated methods
* kill myself
* update readme
* use virion instead
  • Loading branch information
Aericio committed Nov 23, 2018
1 parent a25dda0 commit c5aa9be
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .poggit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ projects:
PiggyCustomEnchants:
path: ""
icon: "resources/PCE_Icon.png"
libs:
- src: jojoe77777/FormAPI/libFormAPI
version: ^1.3
...
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
72 changes: 32 additions & 40 deletions src/DaPigGuy/PiggyCustomEnchants/Commands/CustomEnchantCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,7 +14,7 @@

/**
* Class CustomEnchantCommand
* @package PiggyCustomEnchants\Commands
* @package DaPigGuy\PiggyCustomEnchants\Commands
*/
class CustomEnchantCommand extends PluginCommand
{
Expand All @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -191,7 +192,7 @@ public function formMenu(Player $player)
$form->addButton("Help");
$form->addButton("Info");
$form->addButton("List");
$form->sendToPlayer($player);
$player->sendForm($form);
}
}
}
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -230,17 +230,16 @@ 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);
}
});
$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);
}
}
}
Expand All @@ -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);
Expand All @@ -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);
}
}
}
Expand All @@ -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]);
Expand Down Expand Up @@ -354,17 +351,16 @@ 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);
}
});
$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);
}
}
}
Expand All @@ -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]);
Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
Expand All @@ -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);
}
}
}
Expand All @@ -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) {
Expand All @@ -447,7 +440,7 @@ public function listForm(Player $player)
$form->addButton($type);
}
$form->addButton(TextFormat::BOLD . "Back");
$form->sendToPlayer($player);
$player->sendForm($form);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/DaPigGuy/PiggyCustomEnchants/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}
Expand Down

0 comments on commit c5aa9be

Please sign in to comment.