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

AlwaysSpawn Version 2.0.1

Comments in 'Plugin Development' started by Comedyman937, Jan 17, 2014.

  1. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    So I've been working on the next version of AlwaysSpawn for awhile but I have run into a dead end...
    The code that I have right now is this:
    PHP:
    <?php


    /*
    __PocketMine Plugin__
    name=AlwaysSpawn
    description=Force your users to automatically spawn every time they login!
    version=2.0.1
    author=Comedyman937
    class=AlwaysSpawn
    apiversion=6,7,8,9,10,11
    */


        
    class AlwaysSpawn implements plugin{


        private 
    $api;


        public function 
    __construct(ServerAPI $api$server false)
        {
            
    $this->api $api;
        }


        public function 
    init()
        {
            
    $this->api->addHandler("player.connect", array($this"eventHandler"), 100);
            
    console("[INFO] AlwaysSpawn loaded!");
            
    console("[INFO] Your players will connect to the server at the Spawn Point!");
        }
      
        public function 
    eventHandler($data$event)
        {
            switch(
    $event)
            {
                case 
    'player.connect':


                    
    $data->setSpawn($this->api->level->getSpawn());


                break;
            }


        }


        public function 
    __destruct(){


        }


    }
    So my issue is at $data->setSpawn($this->api->level->getSpawn());... It's supposed to find the username of the player that connects then change his/her cordinates to the main worlds spawn. When I use that code I get no errors on the console, no crashes, nothing but it doesn't work at all...

    Anyone know what I can do to fix this issue?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You just set the player's spawnpoint to spawn, but it doesn't affect them at all because their spawnpoint is always at spawn.

    Like when you are in Australia your home in USA gets moved to Canada. But your body is still in Australia.

    You should use $data->teleport($this->api->level->getSpawn()) instead.
  3. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    That's what I was using in the last version. (A little different but basically the exact same thing) I've been working on this newer version ever since @shoghicp commented saying I should do it a different way.

    This was my last code:
    PHP:
    <?php
    /*
    __PocketMine Plugin__
    name=AlwaysSpawn
    description=Force your users to automatically spawn every time they login!
    version=1.0.3
    author=Comedyman937
    class=Spawner
    apiversion=6,7,8,9,10,11
    */
     
    class Spawner implements plugin{
     private 
    $api;
     public function 
    __construct(ServerAPI $api$server false)
     {
     
    $this->api $api;
     }
     public function 
    init()
     {
     
    $this->api->addHandler("player.spawn", array($this"eventHandler"), 100);
     
    console("[INFO] AlwaysSpawn loaded!");
     
    console("[INFO] Your players will now be teleported to the spawn point when they connect!");
     }
     public function 
    eventHandler($data$event)
     {
     switch(
    $event)
     {
     case 
    'player.spawn':
     
    // PocketMine core schedules lots of teleports - ugh, we need to wait awhile
     
    $this->api->schedule(31, array($this"teleport"), $data);
     break;
     }
     }
     public function 
    teleport($player)
     {
     
    $player->teleport($this->api->level->getSpawn());
     }
     public function 
    __destruct(){
     }
    }
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why did you schedule 1.505 seconds?
  5. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    PocketMine-MP schedules a lot of teleports when a player joins in order to make sure the world is loaded and keep from any issues.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    what if you make the priority in the handler to 100?
    and why is it 31?
  7. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    It's set up so that it can make the PocketMine-MP schedules the priority. I'll try taking out that and putting $data->teleport($this->api->level->getSpawn()); and see what happens.
    Last edited: Jan 17, 2014
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I mean why is it 31 ticks
  9. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    To allow the PocketMine schedules to go through first.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I mean, why is it 31 ticks, not 1 tick?
  11. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    That's because PocketMine core schedules teleport events at 3, 10 and 25 or something like that. So we have to go after all of those.
  12. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I wish people would upload files the old fashioned way, instead of those darn, new-fangled BBcode tags...
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    so 31 ticks is guessing? Then I think tping player on quit is better.
  14. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Good point. Let me try that.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    i am using nokia 5800 and bbcode is easier to read. and for pcs,, dling files spams the dl dir.
    Comedyman937 likes this.
  16. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I've got Android 2.3.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    ok so we arguin bout the forum design? If there is time can the site designers make uploaded files be readable without d!?

Share This Page

Advertisement