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

How to register a file?

Discussion in 'Development' started by neb16, Apr 26, 2019.

  1. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
  2. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    lmao what just copy and paste this on your onEnable()
    PHP:
    if(InvMenuHandler::isRegistered()){
                
    InvMenuHandler::register($this);
            }
     
    Last edited: Apr 26, 2019
  3. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    -_- I am such a scrub, I literally copied and pasted the class. Welp thanks! :)
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    dont forget to import InvMenuHandler lol
     
  5. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    so: use Muqsit/InvMenu/InvMenuHandler; ???
     
  6. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Maybe
     
    BaconOFBurger likes this.
  7. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    -_-
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    invert the if case.
    Right below it, there's an example on how to do it. ece.PNG
    PHP:
    if(!InvMenuHandler::isRegistered()){
        
    InvMenuHandler::register($this);
    }
     
  9. neb16

    neb16 Witch

    Messages:
    71
    GitHub:
    developerneb101
    PHP:
      if(strtolower($command->getName()) === "test"){
        
        class 
    ServerSelectorGUI{

          
    /** @var InvMenu */
          
    private $menu;
     
          public function 
    __construct(string $name){
              
    $this->menu InvMenu::create(InvMenu::TYPE_CHEST)
                  ->
    readonly()
                  ->
    setName($name)
                  ->
    setListener([$this"onServerSelectorTransaction"])//you can call class functions this way
                  
    ->onInventoryClose(function(Player $player) : void{
                      
    $player->sendMessage(TextFormat::GREEN "You are being transferred...");
                  });
          }
     
          public function 
    addServerToList(Item $itemstring $addressint $port) : void{
              
    $nbt $item->getNamedTag();
              
    $nbt->setString("Server"$address ":" $port);
              
    $item->setNamedTag($nbt);
              
    $this->menu->addItem($item);
          }
     
          public function 
    onServerSelectorTransaction(Player $playerItem $itemClickedOn) : bool{
              
    $player->transfer(...explode(":"$itemClickedOn->getNamedTag()->getString("Server""play.onthefallbackserv.er:19132")));
              return 
    true;
          }
     
          public function 
    sendTo(Player $player) : void{
              
    $this->menu->send($player);
          }
      }
     
      
    $gui = new ServerSelectorGUI("Server Selector");
      
    $gui->addServerToList(Item::get(Item::DIAMOND_PICKAXE), "play.onmyserverplea.se"19132);
      
    $gui->addServerToList(Item::get(Item::IRON), "play.onmyserverplea.se"19133);
     
      
    /** @var Player $player */
      
    $gui->sendTo($player);
            return 
    true;
        }

        return 
    false;


            return 
    true;
        }

        return 
    false;
        
        
    Error that i get:
    Code:
    [Server thread/CRITICAL]: ParseError: "syntax error, unexpected 'return' (T_RETURN), expecting function (T_FUNCTION) or const (T_CONST)" (EXCEPTION) in "plugins/GladeNation Core/src/GladeNationCore/Main" at line 139
     
  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.