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

Unset the player from array from another plugin

Comments in 'Plugin Development' started by JackboyPlay, Jul 7, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Hi if I want to unset a player from an array [The array is in the Plugin JCLobbySystem] with this method:
    PHP:
    //Plugin SR
    $lobby $this->getServer()->getPluginManager()->getPlugin("JCLobbySystem")->lobby;
    unset(
    $lobby[array_search($name$lobby)]);
    it doesnt work!
    The player is in the array !
  2. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    Is this array a property in that plugin?
    It have to be public so you could access it.
    What error did you get?
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    I get no error and the array is public
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Please use var_dump() on $lobby and tell us the output.
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Weird. Try to set the array after unset().
    (....->lobby = $lobby)
  7. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How do you mean this?
  8. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Did you mean that I put a value after that into the array?
  9. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    If I do something like $lobby[] = $player->getName() with the plugin JCSR it doesnt work
  10. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @CraftYourBukkit Maybe pocketmine block it to add/unset values into an array
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I mean:
    PHP:
    $lobby $this->getServer()->getPluginManager()->getPlugin("JCLobbySystem")->lobby;
    unset(
    $lobby[array_search($name$lobby)]);
    $this->getServer()->getPluginManager()->getPlugin("JCLobbySystem")->lobby $lobby;
  12. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    I have an another method which is easier i created in the other plugin a function to remove the player from the array
    Jazzwhistle likes this.
  13. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    In PHP, arrays are not implicitly passed by reference like objects (in Java, arrays are objects, that's why they are passed by reference).

    What you are trying to do is the same as this:
    PHP:
    $one "bar";
    $two $one;
    $two "foo";

    echo 
    "Two: $two, One: $one";
    Output:
    Code:
    Two: foo, One: bar
    This is the same for individual elements in an array.

    What you should do is to assign variables by reference. http://bit.ly/29vMDT4

    Corrected code:
    PHP:
    $lobby =& $this->getServer()->getPluginManager()->getPlugin("JCLobbySystem")->lobby;
    unset(
    $lobby[array_search($name$lobby)]);
    THe only thing changed is an extra ampersand on line 1 column 8.

Share This Page

Advertisement