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

Get players of another server

Comments in 'Plugin Development' started by myst02, Jul 11, 2015.

  1. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Hi,

    how can I get the players of another server and write it on a sign? Is that even possible?
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Try (onEnable add $this->updateSigns();)

    PHP:
    public function updateSigns(){
    $level "world" //write name of your world where is sign
    $x "1" //coordinates of sign
    $y "3"
    $z "91"
    $tile $level-> getTile (Vector3($x$y$z));
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new UpdateSignTask($this$tile), X*20); //X is number of seconds, write, this is interval of rewriting signs
    }
    UpdateSignTask.php:
    PHP:
    public function _construct(YourPlugin $plugin$tile){
    $this->plugin $plugin;
    $this->tile $tile;
    }

    public function 
    onRun($t){
    //Change ip and port to your own ports, KvetinacS and CTF can be changed too ;)
    if( $tile instanceof Sign){
    $lines = ["§aKvetinacS""§7§l§oCTF",file_get_contents("http://minecraft-api.com/api/query/playeronline.php?ip=127.0.0.1&port=19132" "§7/" file_get_contents("http://minecraft-api.com/api/query/maxplayer.php?ip=127.0.0.1&port=19132"""]
    $tile -> setText ($lines);
    }
    myst02 likes this.
  3. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Thanks! That is what I was looking for! Will try :)
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    • You need semicolons to delimit statements.
    • Why use a third party API while you can do the query directly?
    • You must use an AsyncTask to do that.
    • You shouldn't use strings for numbers. Put down the numbers directly.
    • You are wasting load by doing the query twice
    • This is not how you initiate a new object.
    Please, if you have the least sense of conscience, don't post wrong solutions here.
  5. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Thanks for your post. I'm still learning PocketMineAPI && PHP.
    HotFireyDeath likes this.
  6. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    your method would be laggy. if you do it async, it would help.
    Last edited by a moderator: Jul 11, 2015
  7. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    For that, i say "i think".
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Is there any difference to people who read this thread? They will still think it is impossible. If you aren't sure, don't post. Nobody is interested in what you think if it is wrong.

    Every post you make will be public. Then everyone who reads it will think that it is true in the future. The Block id = 323 was an example.
  9. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Can someone give me the right code with async?
  10. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    1) How do AsyncTask? Simply replace scheduleRepeatingTask with scheduleAsyncTask

    2) What is difference between Async and Repeating task?
    Last edited by a moderator: Jul 11, 2015
  11. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    1) You cant just simply do that. Read PocketMine API docs.
    2) AsyncTask is more like executing code in a different thread w/out affecting the main thread where PocketMine runs.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually async task and normal tasks have no relationship at all except being in the same namespace, and being handled in the same class.
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Is asynctask running a task at the same time as the main thread?
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Not exactly at the same time. Well, if the system has multiple cores it MIGHT be. Anyway, it is undefined what time things at different threads are run. It might be like, running var_dump(["a", "b"]) on two threads can result in something like this on the terminal:
    Code:
    array(2) {                                            
      [0]=>
    array(2) {                                              
      string(1) "a"           
      [0]=>
      string(1) "a"
      [1]=>                           
      [1]=>                                              
      string(1) "b"                                      
    }
      string(1) "b"
    }
    
    In this case, you are lucky because it is a human reading it, and human intelligence can sort it out what the output means. But if this happens with the variables in code, strange things may happen.
  15. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    PocketMine can't support multiple cores, unless someone has found a way around this.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So multiple threads are still run at one core?
  17. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I believe so. It still speeds things up though as nobody is waiting on the others locks and such.
  18. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    It uses pthreads (which is a proper thread implementation) so multiple cores will be used by different threads when available. The main thing about threading in PM as far as I can tell is that a lot of things are still done on the main thread and the synchronization between threads is through polling.
    PEMapModder and Falk like this.
  19. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    jajajajajajajjaa
  20. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Thanks for clarifying.

    Pushing data onto a daughter thread can be done without polling on the daughter thread, however getting data back from a pthread requires a polling strategy.
    PEMapModder likes this.

Share This Page

Advertisement