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

Help with custom plugin

Comments in 'Plugin Development' started by JayKay, Jun 1, 2014.

  1. JayKay
    Offline

    JayKay New Member

    Joined:
    Jun 1, 2014
    Posts:
    3
    So my 7 years old daughter got crazy about minecraft and being a great dad I wanted to setup a server for her and friends. That went well until my perfectionism kicked in :)

    So infinite worlds plugin was buggy and crashed (and world in pocket edition is just so tiny) so decided to make my own plugin, but I'm not really getting the api and haven't found working examples so maybe you could help.

    Problems begin with the code that tries to send player to the new map. Since code that should get the level (according to infinite worlds plugin) crashes with "Trying to get property of non-object" I've no idea how to get hold of the level object (and whether I should load the level first if it's not loaded). So my first question is how to make following work:

    $level = $this->server->api->level->get($newworld); //Why I don't have $server defined?
    $playerobject->teleport(new Position(0, 0, 50, $level));
    My second question is how to find ground level in the new map since I don't want to go to spawn point but just cross the map border to the other side?

    Here's the full code:
    PHP:
    <?php
    /*
    //IMPORTANT testing this code requires nine maps  named (00,01,02,10,11,12,20,21,22)
    __PocketMine Plugin__
    name=LargeWorld
    description=Simple infinity world by loading a new world.
    version=0
    author=Jay
    class=LargeWorld
    apiversion=12,13
    */
    class LargeWorld implements Plugin {
        private 
    $api;
       
        public 
    $coord = array(
            
    "gridsize" => 3,
            
    "maxx" => 255,
            
    "maxz" => 255,
            
    "minx" => 0,
            
    "minz" => 0
        
    );
       
        
    //public $maxworld = 10;
        
    private $limit;
       
        public function 
    __construct(ServerAPI $api$server false) {
            
    $this->api $api;
            
    $this->limit=$this->coord["gridsize"]-1;
        }

        public function 
    init() {
            
    $this->api->addHandler("player.move", array($this"move"));
        }

        public function 
    __destruct() {}
       
        private function 
    GetWorld($world,$dir)
            {
                
    $loc=preg_split('//'$world, -1PREG_SPLIT_NO_EMPTY);

                switch(
    $dir)
                {
                    case 
    'right':
                        
    $x=$loc[0]+1;
                        
    $y=$loc[1];
                    break;
                   
                    case 
    'left':
                        
    $x=$loc[0]-1;
                        
    $y=$loc[1];
                    break;
                   
                    default:
                        return 
    false;
                    break;
                }
               
                if(
    $x<0){ $x=$this->limit;}
                if(
    $y<0){ $y=$this->limit;}
               
                if(
    $x>$this->limit){ $x=0;}
                if(
    $y>$this->limit){ $y=0;}

                return 
    $x.$y;
            }
       
        public function 
    move($data){
            
    $plobj $this->api->player->get($data->name);
            
    $plobj->sendChat("[LargeWorld] X: ".intval($data->x)." Y:".intval($data->z));
           
            
    $newworld=false;
           
            
    //moving right
            
    if(intval($data->x) == $this->coord["maxx"])
                {
                    
    $world $plobj->level->getName();
                    
    $newworld $this->GetWorld($world,'right');
                    
    $plobj->sendChat("[LargeWorld] New World is ".$newworld);
                }
           
            
    //moving left
            
    if(intval($data->x) == $this->coord["minx"])
                {
                    
    $world $plobj->level->getName();
                    
    $newworld $this->GetWorld($world,'left');
                    
    $plobj->sendChat("[LargeWorld] New World is ".$newworld);
                }
               
            if(
    $newworld && $this->api->level->levelExists($newworld)){
                
    //$plobj->teleport(new Position(0, 0, 50, $newworld));
                
    $lv $this->server->api->level->get($newworld);
                
    //$plobj->teleport($lv->getSafeSpawn());
               
                
    $plobj->sendChat("[LargeWorld] You are in a new world: ".$newworld);
            }

            return 
    true;
        }
    }
    Thank you!
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $this->server =ServerAPI::request();
  3. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    I would advise you to wait for 0.9.0 as
    1. It has infinite worlds, so you would have to stitch these worlds together somehow
    2. This plugin would be outdated and would not work with the 1.0 API
    Darunia18 and PEMapModder like this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Otherwise I'd have released this thing two months ago.
  5. JayKay
    Offline

    JayKay New Member

    Joined:
    Jun 1, 2014
    Posts:
    3
    Thank you.
    So is this 0.9.0 like so many other releases (not minecraft related) that are about to be released for years and never come or is there a set date? I guess I'm not that serious anymore on developing this but it's so close to be 'ready' and those bugs are just irritating.

    So I got it to work for a while almost perfectly and but then I added level creation code and after that I've been spawning inside walls :( I have no idea what's wrong or if I have understood what getSafeSpawn is supposed to do. Here's the updated code:
    PHP:
    <?php
    /*
    NOTE: default map name must be 11 or other legit name
    __PocketMine Plugin__
    name=LargeWorld
    description=Simple infinity world by loading a new world.
    version=24.05.14
    author=Jay
    class=LargeWorld
    apiversion=12,13
    */
    class LargeWorld implements Plugin {
        private 
    $api;
        private 
    $server;
       
       
        public 
    $coord = array(
            
    "gridsize" => 3,
            
    "maxx" => 255,
            
    "maxz" => 255,
            
    "minx" => 0,
            
    "minz" => 0
        
    );
       
        
    //public $maxworld = 10;
        
    private $limit;
        private 
    $allowcreation;
        private 
    $debug;
       
        public function 
    __construct(ServerAPI $api$server false) {
            
    $this->api $api;
            
    $this->server =ServerAPI::request();
            
    $this->limit=$this->coord["gridsize"]-1;
            
    $this->allowcreation=true;
            
    $this->debug=true;
        }

        public function 
    init() {
            
    $this->api->addHandler("player.move", array($this"move"));
        }

        public function 
    __destruct() {}
       
        private function 
    GetWorld($world,$dir)
            {
                
    $loc=preg_split('//'$world, -1PREG_SPLIT_NO_EMPTY);
                switch(
    $dir)
                {
                    
    //y is Z
                    
    case 'right':
                        
    $x=$loc[0]+1;
                        
    $y=$loc[1];
                    break;
                   
                    case 
    'left':
                        
    $x=$loc[0]-1;
                        
    $y=$loc[1];
                    break;
                   
                    case 
    'up':
                        
    $x=$loc[0];
                        
    $y=$loc[1]+1;
                    break;
                   
                    case 
    'down':
                        
    $x=$loc[0];
                        
    $y=$loc[1]-1;
                    break;
                   
                    default:
                        return 
    false;
                    break;
                }
               
                if(
    $x<0){ $x=$this->limit;}
                if(
    $y<0){ $y=$this->limit;}
               
                if(
    $x>$this->limit){ $x=0;}
                if(
    $y>$this->limit){ $y=0;}

                return 
    $x.$y;
            }
       
        private function 
    toggle($number)
            {
                if(
    $number==$this->coord["minx"]){return $this->coord["maxx"]-1;}
                if(
    $number==$this->coord["maxx"]){return $this->coord["minx"]+1;}
                return 
    $number;
            }
           
        private function 
    getNextPosition($data)
            {
                
    //<0,x,45> turns <254,x,45> for the new map.
                
    return new Vector3($this->toggle($data->x),150,$this->toggle($data->z));
            }
       
        public function 
    move($data){
            
    $plobj $this->api->player->get($data->name);
           
            
    $world $plobj->level->getName();
            if(
    $this->debug){$plobj->sendChat("[LargeWorld] ".$world." X: ".intval($data->x)." Z:".intval($data->z)." Y: ".intval($data->y));}
           
            
    $newworld=false;
           
            
    //moving right
            
    if(intval($data->x) == $this->coord["maxx"])
                {
                    
    $world $plobj->level->getName();
                    
    $newworld $this->GetWorld($world,'right');
                }
           
            
    //moving left
            
    if(intval($data->x) == $this->coord["minx"])
                {
                    
    $world $plobj->level->getName();
                    
    $newworld $this->GetWorld($world,'left');
                }
           
            
    //moving up
            
    if(intval($data->z) == $this->coord["maxz"])
                {
                    
    $world $plobj->level->getName();
                    
    $newworld $this->GetWorld($world,'up');
                }
               
            
    //moving down
            
    if(intval($data->z) == $this->coord["minz"])
                {
                    
    $world $plobj->level->getName();
                    
    $newworld $this->GetWorld($world,'down');
                }
           
            if(
    $newworld){
           
            if(
    $this->api->level->levelExists($newworld))
            {
                
    $plobj->sendChat("[LargeWorld] Level exists");
                
    $levelLoaded=$this->api->level->loadLevel($newworld);
                if(
    $levelLoaded)
                    {
                        
    $plobj->sendChat("[LargeWorld] Level is loaded");
                        
    $lv $this->server->api->level->get($newworld);
                        
    $plobj->teleport($lv->getSafeSpawn($this->getNextPosition($data)));
                        
    $plobj->sendChat("[LargeWorld] New World is ".$newworld);

                    }
            }
            else    
    //let's create a level
            
    {
                if(
    $this->allowcreation)
                    {
                        
    $plobj->sendChat("[LargeWorld] Generating new world.");
                        
    $this->api->level->generateLevel($newworld);
                        
    $lv $this->server->api->level->get($newworld);
                        
    $plobj->teleport($lv->getSafeSpawn());
                    }
            }
                   
                   
            }
           

            return 
    true;
        }
    }
    LDX likes this.
  6. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    There is no set release date unfortunately, but beta testing for 0.9.0 should start next week if everything goes as planned for the developers.
    Once beta testing has started, it will be on for 2-4 weeks. Then once all bugs are fixed while and the app has been submitted to the Play Store it should take a week or two for Android, and at least 3 weeks for Apple.

    So basically, it will be another long month...
    DarkN3ss and PEMapModder like this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So it won't be released before July comes? That's good news for me with the LegionPE plugin... :D
  8. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    754
    Plugins:
    2
    Minecraft User:
    Darunia18
    As the above posters have stated, 0.9.0 is less than a month away. The thing is, though, PocketMine's 1.4 update is advancing very quickly, and may be released before that. I'm guessing that the 1.4 update will be moved to the master branch on it's GitHub in the next week or so, and after that, it shouldn't be long before it is the official release.
  9. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Then I guess I should quit being lazy and work on updating my plugins to the new API..... *sigh* I was enjoying being able to be lazy for once...
    Darunia18 likes this.
  10. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    754
    Plugins:
    2
    Minecraft User:
    Darunia18
    I have a few plugins I gotta update for a friend (and I also want to update Claymores). I wish I was being lazy, but I just don't have time :eek: I hate it...
    Comedyman937 and PEMapModder like this.
  11. DarkN3ss
    Offline

    DarkN3ss Active Member Plugin Developer

    Joined:
    Dec 17, 2013
    Posts:
    143
    Plugins:
    7
    Minecraft User:
    DarkN3ss61
    I agree with this except with Android I doesnt not need to get accepted, it becomes live right away, and with Apple I find it takes them 1 week to accept updates to my apps so I assume it will be the same with MCPE(P.S in case you didn't pick it up, I create apps for iOS and Android XD ). So what I guess they will do is wait till the iOS update gets accepted then once it does they will release the android update at the same time :)
    Darunia18 likes this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That's why some hate Apple.
    Comedyman937 and Darunia18 like this.
  13. DarkN3ss
    Offline

    DarkN3ss Active Member Plugin Developer

    Joined:
    Dec 17, 2013
    Posts:
    143
    Plugins:
    7
    Minecraft User:
    DarkN3ss61
    This is true but if you think about it, it stops developers from putting malicious code in there apps, and the reason why it takes so long is because Apple have hundreds of thousands of app/updates to review so the update time is justified.
    Darunia18 and PEMapModder like this.

Share This Page

Advertisement