diff --git a/src/superarmor/middle1/Main.php b/src/superarmor/middle1/Main.php index 1ac489c..e908b04 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 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"); @@ -108,7 +114,6 @@ function (Player $sender, ? int $result = null) { break; case 2: - return true; break; } return false; @@ -118,8 +123,9 @@ 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; } + return true; } }