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

a little help here

Comments in 'Plugin Development' started by CoolGuyPL, Oct 21, 2014.

  1. CoolGuyPL
    Offline

    CoolGuyPL New Member

    Joined:
    Sep 24, 2014
    Posts:
    43
    Minecraft User:
    CoolGuyPlays
    well here is my code. can you please tell why its telling me isOp is on null?
    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args) {
            switch (
    $command->getName()):
                case 
    "ocheck":
                   
                    if(
    $player->isOp()){
                        
    $player =  $this->getServer()->getPlayer($player->getName());
                       
    $sender->sendMessage("The Player is OP");
                   }
                  
                 
            endswitch;
           
        }
  2. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    the code is wrong obviously.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Can you please tell me where $player comes from?
  4. CoolGuyPL
    Offline

    CoolGuyPL New Member

    Joined:
    Sep 24, 2014
    Posts:
    43
    Minecraft User:
    CoolGuyPlays
    uhh from the yonder?;)
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Learn PHP. All variables must be defined or received as parameters except $this.
  6. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Not true on multiple levels. If you don't count class instantiation as defining $this then by that order neither are super globals and list() created variables. In reality I would count new Foo and defining $this in the class scope. So the exception isn't needed.
    PEMapModder likes this.
  7. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    You have to check if $sender is instanceof Player (pocketmine\Player) or not . If it is, take the first line of code you put for setting $player, and put it above that if statement. Check if its null before doing anthing, which indicates the player is offline. Then do whatever you wanna do.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Well, in a PocketMine plugin, developers are strongly discouraged to create namespace/top-namespace functions, and few run code outside the class context. And I would classify list() (and you forgot functions with reference parameters) as defining variables too :D

    But I don't think he will use these, do you? :p
  9. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    No I highly doubt it :)
    PEMapModder likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I am thinking if this is a revenge to an old thread where I pointed out people don't always have $this->api defined as you assumed in your answer. :D

Share This Page

Advertisement