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

Solved Message using arrays.

Comments in 'Plugin Development' started by HotFireyDeath, Jul 31, 2015.

  1. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Let's say I have a very large array with lots of different player names:
    PHP:
    $a = array(
       [
    0] => "player1"
       
    [1] => "player2"
    );
    etc.

    I could get all the values using:
    PHP:
    $ab array_values($a);
    Can I do this, and what will happen?
    PHP:
    $ab->sendMessage("Hi!");
    Last edited: Jul 31, 2015
  2. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    PHP:
    foreach($a as $id => $player){
         
    $p $this->getServer()->getPlayer($player);
         
    $p->sendMessage("Message");
    }
    like that?
    HotFireyDeath likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Noo :D If name is just String:
    PHP:
    foreach($a as $player){
    $player $this->getServer()->getPlayer($player); // THIS LINE
     
    if($player instanceof Player){
    $player->sendMessage('Hello world');
       }
    }
    But if name is Player object do same without // THIS LINE
    HotFireyDeath likes this.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Why you need $id?
    HotFireyDeath likes this.
  5. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    so you can get the [0] or whatever
    HotFireyDeath likes this.
  6. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't getPlayer every time. If it is the same player instance, do it once outside foreach.
    HotFireyDeath likes this.

Share This Page

Advertisement