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

Server goes off when command is ran

Comments in 'Plugin Development' started by Artide, Nov 9, 2015.

  1. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    WTF!? This is the weirdest thing I've seen with PocketMine. I wrote my code, I run the command but the server goes offline when ran for example: /wop steve world
    The server only goes off only if the player is online, but when player is offline it send the offline error.
    The code is the following:
    PHP:
    case 'wop':
                    if(
    $s->hasPermission("pwo.op.add")){
                        if(isset(
    $args[0]) && isset($args[1])){
                            
    $op $this->server->getPlayerExact($args[0]);
                            
    $world $args[1];
                            if(
    $op){
                                
    $this->addWorldOP($op$world);
                                
    $s->sendMessage(TXT::GREEN "Successfully added " $op " to " $world "'s op list.");
                                
    $op->sendMessage(TXT::GREEN "You are now op in " $world "!");
                            }elseif(!
    $op){
                                
    $s->sendMessage(TXT::RED $args[0] . " is offline.");
                            }elseif(
    $this->worldExist($world) === false){
                                
    $s->sendMessage(TXT::RED $world " does not exist.");
                            }
                        }
                        if(empty(
    $args) || count($args) < 1){
                            
    $s->sendMessage(TXT::RED "Usage: /wop <player> <world>");
                        }
                    }
                break;
  2. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Can you please post the offline error and have you defined $world ?
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What did you expect this to do?
    PHP:
    if($op){
      
    // if $op is resolved to true, which in this case, if $op is a valid player object
    }elseif(!$op){
      
    // why elseif(!$op)? You can simply do an else here.
    }elseif(blahblahblah){
      
    // this block will never be run, because either $op or !$op will be run.
    Also, if $args[1] is set, $args[0] must be set.

    The problem about your whole code is that your logic is wrong. Any variables in PHP are either true or false, if you cast them into booleans (if($op) and !$op will both cast them into booleans), you only need to check if().

    So can you tell me, about the worldExists thing, do you expect it to be run when $op is online or not?

    And also, the array $args is defined by an explode() from PocketMine (there is an array_shift() too, but the contents in the array are still ascending from 0). Hence, if $args[0] is not set, count($args) will obviously be 0, and empty($args) will obviously be true.

    However, in your code, if count($args) is 1, nothing will b run at all.
    Last edited: Nov 9, 2015
    remote_vase and Gamecrafter like this.
  4. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    There is no crash error. The server just stops without any message just a 'bin/php.exe' error.

    Attached Files:

  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    segfault means some strange thing happened, just restart the server and it shouldn't happen again.
    I am saying that the logic of your code is wrong.
    Gamecrafter and Legoboy0215 like this.
  6. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    I already fixed up my code and the same thing happens. the worldExists($world) function find the loaded levels if they exists (works perfectly).
  7. ItsSuka
    Offline

    ItsSuka Banned

    Joined:
    Nov 6, 2015
    Posts:
    13
    Minecraft User:
    Unknow
    PHP:
    $world $level->getLevelByName("world-name");
    Here

Share This Page

Advertisement