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

Online Players

Discussion in 'Development' started by XdmingXD, Apr 14, 2017.

  1. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    I have tried this :
    PHP:
    $player $this->getServer()->getPlayer($args[0]);
    if(
    $player instanceof Player) {
    //blahh
    }
    However, it gives me error : unknow error when platform the command...
    Anyone help?
     
    WinterBuild7074 likes this.
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Your title and post tell different things. We need more code than this, and the error that showed up in console when executing this command, if you want us to help you.
     
    Primus likes this.
  3. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args) {
            if(
    $sender instanceof Player) {
                if(
    strtolower($command->getName() === "hi")) {
                    if(
    $sender->hasPermission("agagawgg.rstsh")) {
                        switch (
    $args[0]) {
                            case 
    "player":
                                if(
    count($args) === 2){
                                    
    $name strtolower($args[1]);
                                    
    $this->target $name;
                                    
    $target $this->getServer()->getPlayer($args[1]);
                                    
    //if(target instanceof Player) ?
                                    
    if(!$target->hasPermission("agagawgg.rstsh")) {
                                        
    $sender->sendMessage(C::LIGHT_PURPLE "You targeted" C::AQUA $this->target);
                                        
    $target->sendMessage(C::RED "You are targeted!");
                                        }
                                    }
                                break;
    and the error is the same as I said
    Code:
    [23:14:11] [Server thread/INFO]: An unknown error occurred while attempting to perform this command
    [23:14:11] [Server thread/CRITICAL]: Unhandled exception executing command 'mute player akwfaw4' in mute: Call to a member function getPlayer() on array
    [23:14:11] [Server thread/CRITICAL]: Error: "Call to a member function getPlayer() on array" (EXCEPTION) in "/Mute/src/Mute/mute" at line 135
    
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    Have you overwritten getServer() function?
     
    corytortoise likes this.
  5. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    ohhh i didn't
    How should I overwrite it?
     
  6. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    you are using: use pocketmine\Player; ?
     
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args) {
            if(
    $sender instanceof Player) {
                if(
    strtolower($command->getName() === "hi")) {
                    if(
    $sender->hasPermission("agagawgg.rstsh")) {
                        switch (
    $args[0]) {
                            case 
    "player":
                                if(
    count($args) === 2){
                                    
    $name strtolower($args[1]);
                                    
    $this->target $name;
                                    
    $target $sender->getServer()->getPlayer($args[1]); // If $this->getServer() is being overwritten use $sender->getServer()
                                    
    if($target instanceof Player and !$target->hasPermission("agagawgg.rstsh")) {
                                        
    $sender->sendMessage(C::LIGHT_PURPLE "You targeted" C::AQUA $this->target);
                                        
    $target->sendMessage(C::RED "You are targeted!");
                                        }
                                    }
                                break;
     
  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.