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

[New API] Convert CommandSender to Player

Comments in 'Plugin Development' started by Adaasi, Sep 10, 2014.

Thread Status:
Not open for further replies.
  1. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    How can I convert a CommandSender to Player (if it's possible)?
  2. EkiFoX
    Offline

    EkiFoX Active Member Plugin Developer

    Joined:
    Feb 28, 2014
    Posts:
    94
    Plugins:
    2
    Minecraft User:
    ekifox
    Emm... WHAT? Code example...
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If it is a console command sender, you can't convert it to a player (otherwise what are the IP, username, etc. things?)
    If it is already a player, this is PHP not Java, and if you are sure it is a Player object (maybe using an instanceof check) just use it directly as a Player object.
    If you want PHPStorm to recognize that object as a Player object (it should automatically detect so if you have an instanceof check) but it doesn't automatically do so, add this line before declaration of the variable:
    PHP:
    /** @var Player $varName */
    $varName blah;
    Or for a method parameter:
    PHP:
    /**
     * @param string $a
     * @param Player $b
     */
    public function blah($aPlayer $b){}
    Adaasi likes this.
  4. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    Thanks :)
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Which one is it anyway?
Thread Status:
Not open for further replies.

Share This Page

Advertisement