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

How to check the worlds time

Comments in 'Plugin Development' started by jerlegoman, Jun 19, 2014.

  1. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Hi my name is jerlegoman I am working on a plugin and what I want to know is how to use the OLD API code to check the worlds time for example

    If (the code to check the worlds time)
    $player->sendchat(" the worlds time is day")
  2. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Hi
  3. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    I don't know the exact code but it's something like $this->api->level->getPhase
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    PHP:
    if($this->api->time->getPhase() == "day"){
    //Run this code
    }
  5. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    I was almost there ;)
    Falk likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Different worlds.
    Falk likes this.
  7. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Oh, whoops :)

    PHP:
    if($this->api->time->getPhase(($this->api->level->get($name))->getTime()) == "day"){
    //Run this code
    }
  8. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    But what if I wanted to have it say if it is morning noon evening and night
  9. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    PHP:
    $this->api->chat->broadcast("It is " $this->api->time->getPhase(($this->api->level->get($name))->getTime()) );
  10. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Thanks
  11. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    There was an error on line 40 here is the code:
    PHP:
    <?php
    /*
    __PocketMine Plugin__
    name=TOspawn
    version=1.0
    apiversion=12
    author=Jerlegoman
    class=spaplus
    */
    class spaplus implements Plugin {
    private 
    $api;
    public function 
    __construct(ServerAPI $api,$server false) {
    $this->api $api;
    }
    public function 
    init() {
    $this->api->addHandler("player.action", array($this"eventHandle"), 50);
    $this->api->addHandler("player.equipment.change", array($this"eventHandle"), 50);
    }
    public function 
    eventHandle($data$event) {
    switch (
    $event) {
    case 
    "player.action":
    $player $data["player"];
    $item $player->getSlot($player->slot);
    if(
    $item->getid()==345){
    $player->teleport($this->api->level->getspawn());
    $player->sendChat("[FindSpawn] You have arrived at Spawn!");
    }
    Break;
    case 
    "player.equipment.change":
    $player $data["player"];
    $item $player->getSlot($player->slot);
    if(
    $item->getid()==345){
    $player->sendChat("Tap and Hold on the screen to tp to spawn!");
    }
    Break;
    case 
    "player.action":
    $player $data["player"];
    $item $player->getSlot($player->slot);
    if(
    $item->getid()==347){
    $player->sendChat("It is " $this->api->time->getPhase($this->api->level->get($name)->getTime()));
    }
    Break;
    }
    }
    public function 
    __destruct(){}
    }
    ?>
    Last edited by a moderator: Jun 20, 2014
  12. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Could you give us the error?
  13. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Is player.action a real PocketMine event? I've never seen that before...
  14. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Yeah.
  15. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    I guess you learn something new every day :p
    jerlegoman likes this.
  16. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    the error is
    Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\Users\Jeremy Haft\Desktop\PocketMine-MP use only\plugins\TOspawn.php on line 40
  17. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    the error is:
    Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\Users\Jeremy Haft\Desktop\PocketMine-MP use only\plugins\TOspawn.php on line 40
  18. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    Check tpcompass and drinkbucketwater by blinksun and me
  19. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    You just forgot the second ')' in line 40. Look, that should fix it :

    $player->sendChat("It is " . $this->api->time->getPhase($this->api->level->get('name'))->getTime());
  20. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    And better use 'name' instead of $name.

Share This Page

Advertisement