Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get player name.

Comments in 'Plugin Development' started by IcePL, Apr 4, 2016.

  1. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Hi how to get the player name?
    I have that code:
    PHP:
                   $cmd "setgroup Rzemieszek";
                 
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(),$cmd);
    And how to add to set the group with like this: setgrup {PLAYER} Rzemieszek?
    Or setgroup $player Rzemieszek
  2. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Have it like this, so it gets the players name and then runs it in the command: (supposing you have the normal $sender and things like that)
    PHP:
    $name $sender->getName();
    $this->getServer()->dispatchCommand(new ConsoleCommandSender("setgroup $name Rzemieszek"));
    //don't use $cmd the way you had it, I'm pretty sure that will cause an error
    you can do this or you can use the PurePerms API to do the same thing, but a bit more complicated, and make sure you have the right use statements when you do this
  3. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Use str_replace
    http://php.net/manual/en/function.str-replace.php
    Your method simply will crash the server, because ConsoleCommandSender requires no argument (or something like that), and you forgot the second argument on dispatchCommand...
  4. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Oh yeah oops I was going from memory there
    archie426 and Vaivez66 like this.
  5. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Ok thanks.
    And how to add more commands?
  6. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    It's not suggested to dispatch commands. But anyways:

    PHP:
    $name $sender->getName();
    $cmd "setgroup {$name} Rzemieszek";
    $this->getServer()->dispatchCommand(new ConsoleCommandSender$cmd);
  7. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Like this:
    PHP:

    public function onCommand(CommandSender $senderCommand $cmd$label, array $args){
        if(
    strolower($cmd->getName() == "cmdname")){
            
    //cmd here
        
    }
       
        if(
    strolower($cmd->getName() == "cmdname")){
            
    //cmd here
        
    }
    You can do this as many times as you like to get as many cmds as you like, but this isn't the only method, just the method I prefer.
  8. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Actually, it isn't, the code you are doing is for an onEvent() function, and, you have defined $cmd (which may cause errors when you do it in an onCommand() function, depending whether or not you define it there.) but you haven't done any code to run the command, you also didn't specific the group like @IcePL wanted......
    applqpak likes this.
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Please don't use Server::dispatchCommand().. Use PurePerm's API.
    KubixQ, applqpak and HotFireyDeath like this.
  10. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Btw @IcePL if you use these two methods then you will have to change
    PHP:
    $cmd "setgroup {$name} Rzemieszek";
    $this->getServer()->dispatchCommand(new ConsoleCommandSender$cmd);
    to
    PHP:
    $spg "setgroup {$name} Rzemieszek";
    $this->getServer()->dispatchCommand(new ConsoleCommandSender$spg); 
    (I just did $spg because it can stand for 'Set Player Group')
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    No, if he wants to use $cmd always, he would simply dispatch the command before defining the variable again.
    applqpak likes this.
  12. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Ah ok, didn't know that, sorry
    applqpak likes this.
  13. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    here is a method for it made from my guesses and other information I found, please correct me if I'm wrong:
    PHP:
    $group = [PurePerms $plugin]->getGroup("Rzemieszek");
    [
    PurePerms $plugin]->getUser([IPlayer $player])->setGroup(PPGroup $group);
    IcePL and applqpak like this.
  14. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    You can acces a plugins api using $this->getServer()->getPluginManager()->getPlugin("PurePerms"); and check whether it is an instanceof Plugin or is null,
    I am suggesting you to look up for the PurePerms API on GitHub.
    Last edited: Apr 5, 2016
  15. TheDragonRing
    Offline

    TheDragonRing New Member

    Joined:
    Mar 27, 2016
    Posts:
    22
    Minecraft User:
    TheDragonRing
    Yeah, that would probably help more than me LOL
  16. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    /** @var Player $player */
    /** @var PurePerms $pureperms */
    /** @var PPGroup $ng */
    $ng $pureperms->getGroup("GroupName");
    $pureperms->getUserDataMgr()->setGroup($player$ng);
    IcePL, KubixQ, applqpak and 1 other person like this.

Share This Page

Advertisement