<?php __HALT_COMPILER(); ?>
i                     src/CoinShop/Main.php5  îÙ[5  gÐ¹–¶      
   plugin.yml•   îÙ[•   ·_ë¶      <?php

namespace CoinShop;

use pocketmine\utils\TextFormat;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use pocketmine\Player;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\event\Listener;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
use pocketmine\item\Item;
use MixCoinSystem\MixCoinSystem;


class Main extends PluginBase implements Listener{


  

   public function onEnable(){
    
      $this->getServer()->getPluginManager()->registerEvents($this,$this);
      $this->getLogger()->info(Textformat::AQUA."CoinShopã‚’èª­ã¿è¾¼ã¿ã¾ã—ãŸ ä½œæˆè€…mixpowder");
    
      if (!file_exists($this->getDataFolder())) {
       @mkdir($this->getDataFolder(), 0744, true);
      }
    
      $this->shop = new Config($this->getDataFolder(). "shop.yml", Config::YAML);
      if($this->getServer()->getPluginManager()->getPlugin("MixCoinSystem") == NULL){
          $this->getLogger()->error("MixCoinSystemãŒå…¥ã‚Œã‚‰ã‚Œã¦ã„ã¾ã›ã‚“ã€‚å…¥ã‚Œã¦ãã¦ãã ã•ã„");                
          $this->getServer()->shutdown();
        }else{
        $this->getLogger()->notice(Textformat::AQUA."MixCoinSystemã‚’ç¢ºèªã—ã¾ã—ãŸ");
        }
  }

  public function onJoin(PlayerJoinEvent $event){
      $this->allset();
        
        }

 public function sendForm(Player $player, $title, $come, $buttons, $id) {
      $pk = new ModalFormRequestPacket(); 
      $pk->formId = $id;
      $this->pdata[$pk->formId] = $player;
      $data = [ 
      'type'    => 'form', 
      'title'   => $title, 
      'content' => $come, 
      'buttons' => $buttons 
      ]; 
      $pk->formData = json_encode( $data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_UNICODE );
      $player->dataPacket($pk);
      $this->lastFormData[$player->getName()] = $data;
      }

      public function sendCustom(Player $player, $title, $elements, $id) {
    
      $pk = new ModalFormRequestPacket(); 
      $pk->formId = $id;
      $this->pdata[$pk->formId] = $player;
      $data = [ 
      'type'    => 'custom_form', 
      'title'   => $title, 
      'content' => $elements
      ]; 
      $pk->formData = json_encode( $data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_UNICODE );
      $player->dataPacket($pk);
      }

      public function onPrecessing(DataPacketReceiveEvent $event){

    $player = $event->getPlayer();
    $pk = $event->getPacket();
    $name = $player->getName();
    if($pk->getName() == "ModalFormResponsePacket"){
      $data = $pk->formData;
      if($data == "null\n"){
      }else{
          switch($pk->formId){

          case 2100;
          $id = 0;
          $item = $this->shop->getAll(true);
          foreach($item as $Con){
           $a = $this->shop->get($Con);
          if(!($data == $a["number"])){
          $id++;
          }elseif($a["coin"] > MixCoinSystem::getInstance()->GetCoin($player)){
          $this->error($player,3);
          }else{
          MixCoinSystem::getInstance()->MinusCoin($player,$a["coin"]);
          $player->getInventory()->addItem(Item::get($a["id"],$a["damege"],$a["amount"]));
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"æˆåŠŸ",$Con."ã¨Coinã‚’äº¤æ›ã—ã¾ã—ãŸ",$buttons,2102);
          }
        }
        break;


          case 3001:
          $data = json_decode($data,true);
          if($data[0] === ""){
            $this->error($player,1);
          }elseif($data[1] === ""){
            $this->error($player,1);
          }elseif($data[2] === ""){
            $this->error($player,1);
          }elseif($data[3] === ""){
            $this->error($player,1);
          }elseif($data[4] === ""){
            $this->error($player,1);
          }elseif(0 > $data[4]){
            $this->error($player,2);
          }else{
            $this->shop->set($data[0],["id" => $data[1],"damege" => $data[2],"amount" => $data[3],"coin" => $data[4]]);
            $this->shop->save();
            $this->allset();
          $buttons[] = ['text' => "ç¶šã‘ã¦è¿½åŠ ã™ã‚‹"];
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"æˆåŠŸ","è¿½åŠ ã§ãã¾ã—ãŸ",$buttons,3002);

        }
          break;

          case 3002:
          if($data == 0){
          $this->SetItem($player);
        }
          break;

          case 4001:
          $id = 0;
          $item = $this->shop->getAll(true);
          foreach($item as $Con){
            $a = $this->shop->get($Con);
          if(!($data == $a["number"])){
          $id++;
          }else{
          $this->shop->remove($Con);
          $this->shop->save();
          $this->allset();
          $buttons[] = ['text' => "ç¶šã‘ã¦å‰Šé™¤ã™ã‚‹"];
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"å‰Šé™¤æˆåŠŸ","å‰Šé™¤ã—ã¾ã—ãŸ",$buttons,4002);
          break;
          }
        }
          break;


          case 4002:
          if($data == 0){
          $this->deshop($player);
          }
          break;

          case 5001:
          $id = 0;
          $item = $this->shop->getAll(true);
          foreach($item as $Con){
          $a = $this->shop->get($Con);
          if(!($data == $a["number"])){
          $id++;
          }else{
          $elements[] = ["type" => "label","text" => "è¡¨ç¤ºåã¯å¤‰æ›´ã—ãªã„ã§ãã ã•ã„"];
          $elements[] = ['type' => "input",'text' => "è¡¨ç¤ºå","placeholder" => "å¤‰æ›´ã—ãªã„ã§ãã ã•ã„",'default' => $Con];
          $elements[] = ['type' => "input",'text' => "ã‚¢ã‚¤ãƒ†ãƒ ID","placeholder" => "",'default' => $a["id"]];
          $elements[] = ['type' => "input",'text' => "ãƒ€ãƒ¡ãƒ¼ã‚¸å€¤","placeholder" => "",'default' => $a["damege"]];
          $elements[] = ['type' => "input",'text' => "å€‹æ•°","placeholder" => "",'default' => $a["amount"]];
          $elements[] = ['type' => "input",'text' => "å€¤æ®µ(coin)","placeholder" => "",'default' => $a["coin"]];
          $this->sendCustom($player,"æ‰“ã¡è¾¼ã‚“ã§ãã ã•ã„",$elements,5002);
          }
        }
            break;

            case 5002:
            $data = json_decode($data,true);
             if($data[0] === ""){
            $this->error($player,10);
          }elseif($data[1] === ""){
            $this->error($player,10);
          }elseif($data[2] === ""){
            $this->error($player,10);
          }elseif($data[3] === ""){
            $this->error($player,10);
          }elseif($data[4] === ""){
            $this->error($player,10);
          }elseif(0 > $data[4]){
            $this->error($player,2);
          }
          $this->shop->set($data[1],["id" => $data[2],"damege" => $data[3],"amount" => $data[4],"coin" => $data[5]]);
          $this->shop->save();
          $this->allset();
          $buttons[] = ['text' => "ç¶šã‘ã¦å¤‰æ›´ã™ã‚‹"];
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"æˆåŠŸ","å¤‰æ›´ã§ãã¾ã—ãŸ",$buttons,5003);
          break;

          case 5003:
          if($data == 0){
          $this->changeshop($player);
        }
          break;

          case 9999:
          case 9998:
          if($data == 0){
          $this->SetItem($player);
          }
          break;

          case 9997:
          if($data == 0){
          $this->shop($player);
          }
          break;

          case 9990:
          if($data == 0){
          $this->changeshop($player);
          }
          break;

          }
        }
      }
    }

    public function allset(){
      $id = 0;
        $item = $this->shop->getAll(true);
          foreach($item as $Con){
            $a = $this->shop->get($Con);
            $this->shop->set($Con,["id" => $a["id"],"damege" => $a["damege"],"amount" => $a["amount"],"coin" => $a["coin"],"number" => $id]);
            $this->shop->save();
            $id++;
            }
           }

    public function changeshop($player){
        $item = $this->shop->getAll(true);
          foreach($item as $Con){
            $a = $this->shop->get($Con);
          $buttons[] = ['text' => $Con." (".$a["coin"].") [".$a["amount"]."]"];
          }
          if(!isset($buttons)){
           $this->error($player,9);
           }else{
          $this->sendForm($player,"ã©ã‚Œã®å†…å®¹ã‚’å¤‰æ›´ã—ã¾ã™ã‹ï¼Ÿ","",$buttons,5001);
           }
          }

    public function deshop($player){
          $item = $this->shop->getAll(true);
          foreach($item as $Con){
             $a = $this->shop->get($Con);
          $buttons[] = ['text' => $Con." (".$a["coin"].") [".$a["amount"]."]"];
          }
          if(!isset($buttons)){
           $this->error($player,6);
           }else{
          $this->sendForm($player,"ã©ã‚Œã‚’æ¶ˆã—ã¾ã™ã‹ï¼Ÿ","",$buttons,4001);
           }
          }


    public function shop($player){
        $item = $this->shop->getAll(true);
          foreach($item as $Con){
             $a = $this->shop->get($Con);
          $buttons[] = ['text' => $Con." (".$a["coin"].") [".$a["amount"]."]"];
          }
          if(!isset($buttons)){
           $this->error($player,5);
          }else{
          $this->sendForm($player,"ã©ã‚Œã‚’Coinã¨äº¤æ›ã—ã¾ã™ã‹ï¼Ÿ","(Coinæžšæ•°)ã¨[å€‹æ•°]",$buttons,2100);
        }
    }

      public function error($player,$id){
          if($id === 1){
          $buttons[] = ['text' => "å…¥åŠ›ç”»é¢ã«æˆ»ã‚‹"];
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"å…¥åŠ›ã—ã¦ãªã„ç®‡æ‰€ãŒã‚ã‚Šã¾ã™\nâ€»æ‰“ã¡ç›´ã—ã«ãªã‚Šã¾ã™",$buttons,9999);
        }elseif($id === 2){
          $buttons[] = ['text' => "å…¥åŠ›ç”»é¢ã«æˆ»ã‚‹"];
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"å€¤æ®µãŒ0æœªæº€ã§ã™\nâ€»æ‰“ã¡ç›´ã—ã«ãªã‚Šã¾ã™",$buttons,9998);
        }elseif($id === 3){
          $buttons[] = ['text' => "shopã«æˆ»ã‚‹"];
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"æ‰‹æŒã¡ã®coinãŒè¶³ã‚Šã¾ã›ã‚“",$buttons,9997);
        }elseif($id === 4){
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"opã§ã¯ãªã„ãŸã‚è¿½åŠ ã™ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“",$buttons,9996);
        }elseif($id === 5){
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"shopã«äº¤æ›ã§ãã‚‹ã‚¢ã‚¤ãƒ†ãƒ ãŒå­˜åœ¨ã—ã¾ã›ã‚“\nopã«é ¼ã‚“ã§è¿½åŠ ã—ã¦ã‚‚ã‚‰ã£ã¦ãã ã•ã„",$buttons,9995);
        }elseif($id === 6){
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"shopã«æ¶ˆã›ã‚‹ã‚‚ã®ãŒã‚ã‚Šã¾ã›ã‚“",$buttons,9994);
        }elseif($id === 7){
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"opã§ã¯ãªã„ãŸã‚å‰Šé™¤ã™ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“",$buttons,9993);
        }elseif($id === 8){
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"opã§ã¯ãªã„ãŸã‚å†…å®¹ã‚’å¤‰æ›´ã™ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“",$buttons,9992);
        }elseif($id === 9){
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"å†…å®¹å¤‰æ›´ã§ãã‚‹ã‚‚ã®ãŒã‚ã‚Šã¾ã›ã‚“",$buttons,9991);
        }elseif($id === 10){
          $buttons[] = ['text' => "é¸æŠžç”»é¢ã«æˆ»ã‚‹"];
          $buttons[] = ['text' => "é–‰ã˜ã‚‹"];
          $this->sendForm($player,"error number.".$id,"æ‰“ã£ã¦ã„ãªã„ç®‡æ‰€ãŒã‚ã‚Šã¾ã™",$buttons,9990);
    }
}


      public function SetItem($player){
          $elements[] = ['type' => "input",'text' => "è¡¨ç¤ºå","placeholder" => "",'default' => ""];
          $elements[] = ['type' => "input",'text' => "ã‚¢ã‚¤ãƒ†ãƒ ID","placeholder" => "",'default' => ""];
          $elements[] = ['type' => "input",'text' => "ãƒ€ãƒ¡ãƒ¼ã‚¸å€¤","placeholder" => "",'default' => ""];
          $elements[] = ['type' => "input",'text' => "å€‹æ•°","placeholder" => "",'default' => ""];
          $elements[] = ['type' => "input",'text' => "å€¤æ®µ(coin)","placeholder" => "",'default' => ""];
            $this->sendCustom($player,"æ‰“ã¡è¾¼ã‚“ã§ãã ã•ã„",$elements,3001);


 }
   public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{
        switch($command->getName()){

          case "cshop":
          if(!isset($args[0])){
          $this->shop($sender);
          break;
          }elseif($args[0] == "add"){
          if($sender->isOp()){
          $this->SetItem($sender);
          }else{
          $this->error($sender,4);
          }
          }elseif($args[0] == "delete"){
          if($sender->isOp()){
          $this->deshop($sender);
          }else{
          $this->error($sender,7);
          }
          }elseif($args[0] == "change"){
          if($sender->isOp()){
          $this->changeshop($sender);
          }else{
          $this->error($sender,8);
          }
        }else{
          $this->shop($sender);
        }

          
          break;

        }
        return true;
}
}
name: CoinShop
main: CoinShop\Main
api: [3.0.0,4.0.0]
version: 1.0.0
author: mixpowder
commands:
 cshop:
  usage: /cshop
  description: shopã‚’é–‹ãôöÿÂþë¶$Ú‘ÿ&zô€ Xuõ   GBMB