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

Why isn't this working?

Comments in 'Plugin Development' started by BlubberBoy333, Jun 15, 2015.

  1. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    I'm editing the VoteReward plugin a little bit, but the edits i made to it just crashes the server. I've looked all over the code but i can't find what i did wrong. The line that crashes the server is this:
    PHP:
    foreach($p->getServer()->getOnlinePlayers() as Player){
    When the server crashes it tells me that line is has an unexpected ')' but i don't see where it is. Can anyone help?
  2. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Do $player not just player that should fix the error
  3. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    And what is $p?
  4. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    $player not $p
  5. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    $p is the command sender. Doing $player won't help it will say it is an undefined variable
  6. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    try
    foreach($this->getServer()->getOnlinePlayers() as $Player){
  7. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    You might want to use $p->getServer() if your not working in plugin's main class. Also it's good practice to keep variables "camel-case", for example,"$minecraftPocketEdition" instead of "$MinecraftPocketEdition", and in your case "$player" instead of "$Player".
    RekkuzaRage and iksaku like this.
  8. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    At first the line was
    PHP:
    foreach($p->getServer()->getOnlinePlayers() as Player){
    That still crashed the server

    Again, making 'Player' a variable won't work
  9. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Show us the whole function, you've probably gone wrong some where else. ;)
  10. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Yes it will because your defining the variable in the sentence.
  11. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    This is everything I added to the main class:
    PHP:
    foreach(getServer()->getOnlinePlayers() as Player){
            
    $player getServer()->getOnlinePlayers();
            
    $name $player->getName();
            
    $voted file_get_contents($this->url);
            if(!(
    in_array($name$voted))){
                
    player->sendMessage(TextFormat::GREEN .    "Vote>> " .TextFormat::RESET "You have not voted today. Help the server by voting and get cool rewards! You can use /vote to vote.");
            return 
    true;
        }
    }
  12. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    I already told you its $player not just player.
    PHP:
    foreach($this->getOwner()->getServer()->getOnlinePlayers() as $Player){
            
    $name $Player->getName();
            
    $voted file_get_contents($this->url);
            if(!(
    in_array($name$voted))){
                
    $Player->sendMessage(TextFormat::GREEN .    "Vote>> " .TextFormat::RESET "You have not voted today. Help the server by voting and get cool rewards! You can use /vote to vote.");
            return 
    true;
        }
    }
    dont be stuborn and try it. :)
    Last edited: Jun 15, 2015
  13. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Huh that worked...
    Andrey Nazarchuk likes this.
  14. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Yea i know haha. Glad i helped. :)
    BlubberBoy333 likes this.
  15. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
  16. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    I don't think getOwner() method is required.
    xiaoq likes this.
  17. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    If you are not on the main class it is.
  18. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    Yeah, but he was using the main class. So it isn't required.
    PixelGuy75 likes this.

Share This Page

Advertisement