Advertisement
TungstenVn

Untitled

Sep 14th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.57 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tungst_thoai;
  4.  
  5. use pocketmine\plugin\PluginBase;
  6. use pocketmine\Player;
  7. use pocketmine\Server;
  8. use pocketmine\event\Listener;
  9. use pocketmine\command\Command;
  10. use pocketmine\command\CommandSender;
  11. use pocketmine\event\Event;
  12. use pocketmine\event\player\PlayerJoinEvent;
  13. class Main extends PluginBase implements Listener {
  14.  
  15.  
  16.     public function onEnable(){
  17.         $this->getLogger()->info("thoai");
  18.         $this->getServer()->getPluginManager()->registerEvents($this, $this);
  19.         $this->saveDefaultConfig();
  20.     }
  21.     public function onCommand(CommandSender $sender, Command $command, String $label, array $args) : bool {
  22.            if(strtolower($command->getName()) == "thoai"){
  23.               if(!isset($args[0])){
  24.                 $sender->sendMessage("Dùng /thoai <caijdo>"); 
  25.                 return false;  
  26.               }
  27.               if(!isset($this->getConfig()->getNested('thoai')[$args[0]])){
  28.                 $sender->sendMessage("Không thấy thoại '".$args[0]."'");  
  29.                 return false;  
  30.               }
  31.               $sender->sendMessage($this->getConfig()->getNested('thoai')[$args[0]]);  
  32.            }
  33.            else if(strtolower($command->getName()) == "addthoai"){
  34.             if(!$sender instanceof Player){$sender->sendMessage("Use in game");return false;}
  35.             $this->newform($sender,"");
  36.            }
  37.            return true;
  38.         return true;
  39.     }
  40.   public function newform($player,$err){  
  41.         $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI");
  42.         $form = $api->createCustomForm(function (Player $player, $data){
  43.             $api1 = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
  44.             $result = $data;
  45.             if($result === null){
  46.                 return false;
  47.             }
  48.             if(!isset($result[1]) || !isset($result[2])){
  49.                 $this->newform($player,"§cPlease type thoai's name and the msg\n");
  50.                 return false;
  51.             }
  52.              $thoainame = $result[1]; $thoai = $result[2];
  53.              $this->getConfig()->setNested("thoai.$thoainame",$thoai);        
  54.              $this->getConfig()->setAll($this->getConfig()->getAll());
  55.              $this->getConfig()->save();
  56.              $this->newform($player,"§aCreate thoai successfull, name: $thoainame , msg: $thoai");
  57.  
  58.             });
  59.             $form->setTitle("§0Create §cthoai");  
  60.             $form->addLabel("$err");          
  61.             $form->addInput("Thoai's name:");
  62.             $form->addInput("Message:");
  63.             $form->sendToPlayer($player);
  64.             return $form;
  65.    }
  66.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement