From 7dd8fe590356de8afb6c70c8e7237b957c54e46d Mon Sep 17 00:00:00 2001 From: XackiGiFF Date: Mon, 11 Sep 2023 00:16:27 +0300 Subject: [PATCH 1/2] Update Main.php * Delete unused class, * Comment unused variable * Price now gets from config * ITEM-FOR-BUY now gets from config with checking * Some bugs fix --- src/superarmor/middle1/Main.php | 38 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/superarmor/middle1/Main.php b/src/superarmor/middle1/Main.php index 1ac489c..f61ef82 100644 --- a/src/superarmor/middle1/Main.php +++ b/src/superarmor/middle1/Main.php @@ -7,16 +7,16 @@ use pocketmine\command\CommandSender; use pocketmine\player\Player; use pocketmine\item\VanillaItems; +use pocketmine\Server; use pocketmine\utils\Config; -use pocketmine\math\Vector3; -use superarmor\middle1\libs\Form\SimpleForm; +use superarmor\middle1\libs\jojoe77777\FormAPI\SimpleForm; use superarmor\middle1\Data\ { Enchantments, Items }; class Main extends PluginBase implements Listener { - private $config; + private Config $config; public function onEnable() : void { @@ -29,16 +29,16 @@ public function onEnable() : void $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML); } - public function onCommand(CommandSender $p, Command $cmd, string $label, array $args) : bool + public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool { - if ($cmd->getName() == "armor") { - if (!$p instanceof Player) { + if ($command->getName() == "armor") { + if (!$sender instanceof Player) { $this->getLogger()->info("Only player"); return true; } - if (!$p->isSurvival()) { - $p->sendMessage("§cIn survival only!"); + if (!$sender->isSurvival()) { + $sender->sendMessage("§cIn survival only!"); return true; } @@ -55,18 +55,24 @@ function (Player $sender, ? int $result = null) { $item_count = $inventory->getItemInHand()->getCount(); //переменная для счёта кол-во предметов в руке игрока $EnchantmentsClass = new Enchantments($this->config); //объявление Enchantments класса $ItemsClass = new Items($this->config); //объявления Items класса - if ($item_in_hand_name != $this->config->getNested("buy-armor.name-item-for-buy") || $item_count < $this->config->getNested("full-armor.cost")) { + $price = $this->config->getNested("full-armor.cost"); + $item_for_buy = $this->config->getNested("buy-armor.name-item-for-buy"); + if ($item_in_hand_name != $item_for_buy || $item_count < $price) { $sender->sendMessage( - "Take in hand " . $this->config->getNested("full-armor.cost") . " diamonds"); + "Take in hand " . $price . " " . $item_for_buy); return true; } - $inventory->removeItem(VanillaItems::DIAMOND()->setCount($this->config->getNested("full-armor.cost"))); + if(empty(VanillaItems::$item_for_buy())){ + Server::getInstance()->getLogger()->warning("The " . $item_for_buy ." is not VanillaItems"); + return false; + } + $inventory->removeItem(VanillaItems::$item_for_buy()->setCount($price)); $position = $sender->getPosition(); //Все предметы - $boots = $ItemsClass->getName("boots"); // Ботинки - $chest = $ItemsClass->getName("chest"); // Кирасса - $helmet = $ItemsClass->getName("helmet"); // Шлем - $leggins = $ItemsClass->getName("leggins"); // Штаны +// $boots = $ItemsClass->getName("boots"); // Ботинки +// $chest = $ItemsClass->getName("chest"); // Кирасса +// $helmet = $ItemsClass->getName("helmet"); // Шлем +// $leggins = $ItemsClass->getName("leggins"); // Штаны // Все чары $boots = $EnchantmentsClass->getEnchantments("boots"); $chest = $EnchantmentsClass->getEnchantments("chest"); @@ -118,7 +124,7 @@ function (Player $sender, ? int $result = null) { $form->addButton("§8To buy super armor", 0, "textures/items/chainmail_chestplate.png"); $form->addButton("§7FAQ", 0, "textures/items/book_normal.png"); $form->addButton("§o§cExit"); - $form->sendToPlayer($p); + $form->sendToPlayer($sender); return true; } } From 8b7eeb5a94fba03ac9a9169835685326022616a0 Mon Sep 17 00:00:00 2001 From: XackiGiFF Date: Mon, 11 Sep 2023 00:30:27 +0300 Subject: [PATCH 2/2] Update Main.php Fix for poggit --- src/superarmor/middle1/Main.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/superarmor/middle1/Main.php b/src/superarmor/middle1/Main.php index f61ef82..e908b04 100644 --- a/src/superarmor/middle1/Main.php +++ b/src/superarmor/middle1/Main.php @@ -9,7 +9,7 @@ use pocketmine\item\VanillaItems; use pocketmine\Server; use pocketmine\utils\Config; -use superarmor\middle1\libs\jojoe77777\FormAPI\SimpleForm; +use jojoe77777\FormAPI\SimpleForm; use superarmor\middle1\Data\ { Enchantments, Items }; @@ -114,7 +114,6 @@ function (Player $sender, ? int $result = null) { break; case 2: - return true; break; } return false; @@ -127,5 +126,6 @@ function (Player $sender, ? int $result = null) { $form->sendToPlayer($sender); return true; } + return true; } }