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

Why isn't getPlayer() working?

Comments in 'Plugin Development' started by BlubberBoy333, May 31, 2015.

  1. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    I'm making a trolling plugin, and on of the commands in it requires you to specify a player name. When I run the command, It tells me that the player isn't online even though thy are. Here's my code
    PHP:
    if(isset($args[0])){
        
    $player $args;
        
    $online $sender->getServer()->getPlayer($player);
         if(
    $online instanceof Player){
              
    $player->sendMessage($this->getConfig()->get("HeroWarn"));
               
    $sender->sendMessage("Your message has been sent!");
               return 
    true;
         }else{
             
    $sender->sendMessage("Player " .$player" not found!");
              return 
    true;
          }
    }
  2. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    Also the player variable should be...
    PHP:
    $player $this->getServer()->getPlayerExact($args);
    // OR
    $player $this->getServer()->getPlayer($args);
    There is also no use for the $online variable. Just do...
    PHP:
    if($sender instanceof Player)
    Last edited: May 31, 2015
  3. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Try:
    PHP:
    if(isset($args[0])){
        
    $player $sender->getServer()->getPlayer($args[0]);
         if(
    $player !== null and $player->isOnline()){
              
    $player->sendMessage($this->getConfig()->get("HeroWarn"));
              
    $sender->sendMessage("Your message has been sent!");
               return 
    true;
         }else{
             
    $sender->sendMessage("Player " .$args[0]. " not found!");
              return 
    true;
          }
    }
    Falk and RekkuzaRage like this.
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Just do
    PHP:
    $player $args[0];
    if(
    $player $this->getServer()->getPlayer($player)){
    // Code
    }
  5. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    It works! Thanks :D
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is your $args? State it. We don't know what you are doing.
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    A Player who has to be on.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So $args is a player instance?
  9. 64FF00
    Offline

    64FF00 Active Member Plugin Developer

    Joined:
    May 11, 2014
    Posts:
    298
    Plugins:
    2
    Minecraft User:
    64FF00
    No, just command arguments

Share This Page

Advertisement