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

AWESOME if Possible

Discussion in 'Off-Topic' started by QuiverlyRivalry, Oct 7, 2017.

  1. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    Hi,
    It would be amazing! If someone makes CustomUI plugins and uploads them for free. Like shops and etc. Ill pay people to do it if needed.
     
  2. themestl

    themestl Spider Jockey

    Messages:
    39
    GitHub:
    themestl
    I hope that it`s work. I not use customui.
    PHP:
    private $playerCurrentAction = [];
    private 
    $actions = [];
    private 
    $shop = [];
    public function 
    init(){
    //You must use this method in onEnable or onLoad
      
    $this->actions = [
        
    'main' => [$this'getMainForm'],
        
    'shop' => [$this'getShopForm'],
        
    'pvp'  => function(){return null;}
     ];
      
    $this->shop = [[Item::BEDROK ":0" => 100000000], [Item::STONE ":0" => 1000000000000]];//[ID:damage => price]
    }

    public function 
    addMenu(Player $playerstring $action 'main', ...$args): bool{
     
    //Use it method where you need
      
    if(isset($this->actions[$action])){
       
    $this->playerCurrentAction[strtolower($player->getName())] = $action;
       
    $form call_user_func($this->actions$player, ...$args);
       if(
    $form === null){
           return 
    true;
       }
       
    $packet = new ShowModalFormPacket;
       
    $packet->formId array_search($actionarray_keys($this->action));//This must be number of your action
       
    $packet->data json_encode($formJSON_PRETTY_PRINT JSON_BIGINT_AS_STRING);
       
    $player->dataPacket($packet);
       return 
    true;
      }
      return 
    false;
    }

    public function 
    getMainForm(Player $player){
       
    $form = ['type' => 'custom_form''title' => 'Welcome to menu, §c' $player->getName() . '§r!''content' => []];
       
    $firstElement = ['type' => 'label''text'  => 'Choose an action! Available actions: shop, pvp'];
       
    $secondElement = ['type' => 'input''text'  => 'Action: ''placeholder' => 'you must write action here!''default' => ''];
       
    $form['content']= [$firstElement$secondElement];
       return 
    $form;
    }

    public function 
    getShopForm(Player $player){
       
    $items = [];
       foreach(
    $this->shop as $data){
          foreach(
    $data as $item => $price){
             
    $items[] = ['text' => (Item::get(...explode(":"$item)))->getName() . '. It`s cost $' $price];//You can use EcnonomyAPI for checking player money and if player not enough money you can either change price color or not show item in form.
          
    }
       }
       return  [
    'type' => 'custom_form''title' => 'It`s our shop! You can buy items here!''content' => '''buttons' => $items];
    }

    public function 
    handlePacket(DataPacketReceiveEvent $event){
       if((
    $packet $event->getPacket()) instanceof ModalFormResponsePacket){
           
    $player  $event->getPlayer();
           
    $data $packet->data;
           switch(
    $packet->formId){
               case 
    array_search('main'array_keys($this->actions)):
                    if(
    $this->addMenu($player$data)){
                        break;
                    }
                    
    $player->sendMessage('Sorry, but this action not available.');
                    break; 
                case 
    array_search('shop'array_keys($this->actions)):
                    
    $price array_values($this->shop[$data])[0];
                    
    $item Item::get(...explode(":"array_keys($this->shop[$data])[0]);
                    
    //TODO
                    
    break;
                case 
    array_search('pvp'array_search($this->actions)):
                    
    $player->teleport(new Vector3(111));
                    break;
          }
       }
    }
     
  3. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    This might be too much, but is it possible if you make a plugin ;D I’ll pay you if you need.
     
  4. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    I tried to make it on my github is there any errors you see?
     
  5. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    Or maybe someone could make a customui which u can edit in .json
     
  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.