1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Plugin Help :)

Discussion in 'Plugin Help' started by AlexPads, Oct 2, 2018.

  1. AlexPads

    AlexPads Spider Jockey

    Messages:
    27
    GitHub:
    alexpads
    Hello!, we have been working on a ShopUI plugin and we cannot figure out why it is not working.

    When we start the server it gives no errors and enables and when we run /shop in-game the UI shows but you cannot click anything any ideas?
    please help :)



    PHP:
    <?php
     
    namespace AlexPads\Shop\TinyPixelDevz;
     
     use 
    pocketmine\command\{CommandCommandSender};
     use 
    pocketmine\item\Item;
     use 
    pocketmine\Player;
     use 
    pocketmine\plugin\PluginBase;
     use 
    pocketmine\utils\TextFormat;
     
     class 
    Main extends PluginBase{
     
         private 
    $economyapi;
         private 
    $formapi;
     
         public 
    $weapons = [];
         public 
    $tools = [];
         public 
    $armor = [];
         public 
    $blocks = [];
         public 
    $specials = [];
         public 
    $masks = [];
     
         public 
    $category;
     
         public function 
    onEnable()
         {
             foreach ([
    'FormAPI''EconomyAPI'] as $depend) {
                 
    $plugin $this->getServer()->getPluginManager()->getPlugin($depend);
                 
    $name strtolower($depend);
                 if (
    is_null($plugin)) {
                     
    $this->getLogger()->error($depend " is required to use this plugin.");
                     
    $this->setEnabled(false);
                     return 
    false;
                 }
                 
    $this->$name $plugin;
             }
             
    $this->saveDefaultConfig();
             foreach ([
    "weapons""tools""armor""blocks""specials""masks"] as $category) {
                 
    $this->$category $this->getConfig()->getNested("items." $category);
             }
             
    $this->getLogger()->info("ShopUI By TinyPixelDevz Team!");
         }
     
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label,array $args) : bool {
        
            switch (
    $cmd->getName()) {
                case 
    "shop":
                    if (
    $sender instanceof Player) {
                        
    $this->mainForm($sender);
                        return 
    true;
                     }
                     
    $sender->sendMessage(TextFormat::RED "Please use this in-game.");
                     break;
             }
             return 
    true;
         }
     
         public function 
    mainForm(Player $player)
         {
                   
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
                   
    $form $api->createCustomForm(function (Player $sender, array $data null){
                     
    $result $data[0];
                  if (
    $result === null){
                     
    $categories = [=> "weapons"=> "tools"=> "armor"=> "blocks"=> "specials"=> "masks"];
                     switch (
    $result) {
                         case 
    6:
                             return;
                         default:
                             
    $this->categoryForm($player$categories[$result]);
                             
    $this->category[$player->getLowerCaseName()] = $categories[$result];
                             return;
                     }
                 }
             });
     
             
    $form->setTitle(TextFormat::WHITE "--= " TextFormat::BOLD TextFormat::GREEN $this->getConfig()->getNested("name") . TextFormat::RESET TextFormat::WHITE " =--");
             
    $money $this->economyapi->myMoney($player->getName());
             
    $form->setContent("Your Money: $" $money);
             
    $form->addButton(TextFormat::WHITE "Weapons");
             
    $form->addButton(TextFormat::WHITE "Tools");
             
    $form->addButton(TextFormat::WHITE "Armour");
             
    $form->addButton(TextFormat::WHITE "Blocks");
             
    $form->addButton(TextFormat::WHITE "Special Items");
             
    $form->addButton(TextFormat::WHITE "Masks");
             
    $form->addButton(TextFormat::GREEN "Exit");
             
    $form->sendToPlayer($player);
         }
     
         public function 
    categoryForm(Player $player$category){
                   
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
                   
    $form $api->createCustomForm(function (Player $sender, array $data null){
                     
    $result $data[0];
                  if (
    $result === null){
                     
    $category $this->category[$player->getLowerCaseName()];
                     if (
    $data[0] < count($this->$category)) {
                         
    $item $this->$category[$data[0]];
                         
    $values explode(":"$item);
                         
    $money $this->economyapi->myMoney($player->getName());
                         if (
    $money >= $values[4]) {
                             
    $player->getInventory()->addItem(Item::get($values[0], $values[1], $values[2])->setCustomName($values[3]));
                             
    $this->economyapi->reduceMoney($player$values[4]);
                             
    $message $this->getConfig()->getNested("messages.bought");
                             
    $tags = [
                                 
    "{amount}" => $values[2],
                                 
    "{item}" => $values[3],
                                 
    "{cost}" => $values[4]
                             ];
                             foreach (
    $tags as $tag => $replacement){
                                 
    $message str_replace($tag$replacement$message);
                             }
                             
    $player->sendMessage($message);
                         } else {
                             
    $message $this->getConfig()->getNested("messages.not-enough-money");
                             
    $tags = [
                                 
    "{amount}" => $values[2],
                                 
    "{item}" => $values[3],
                                 
    "{missing}" => $values[4] - $money
                             
    ];
                             foreach (
    $tags as $tag => $replacement){
                                 
    $message str_replace($tag$replacement$message);
                             }
                             
    $player->sendMessage($message);                    }
                     } else {
                         
    $this->mainForm($player);
                     }
                 }
            });
            
    $form->setTitle(ucfirst($category));
            
    $money $this->economyapi->myMoney($player->getName());
            
    $form->setContent("§a§lYour Money: " $money);
            foreach (
    $this->$category as $item) {
                
    $values explode(":"$item);
                
    $form->addButton($values[3] . " : " $values[4], isset($values[5]) ? $values[5] : -1, isset($values[6]) ? str_replace("https//""https://"$values[6]) : "");
            }
            
    $form->addButton("§bBack to main menu!");
            
    $form->sendToPlayer($player);
        }
      }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.