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

What's wrong?

Comments in 'Plugin Development' started by Marcelo234, Feb 2, 2016.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys, what is the Problem in this code?
    PHP:
    if($cmd->getName() == "limitedvip") {
                        if(!isset(
    $args[0]) || count($args) > 4){
                    
    $sender->sendMessage(TextFormat::GREEN."Usage: /limitedvip <add/remove> [player] [time]");
                    return 
    true;
                        }
                        switch(
    strtolower($args[0])){
                           
                        case 
    "add":
                            if(isset(
    $args[1])){
                                if(isset(
    $args[2])){
                                    
    $args[1] = $limitedvip;
                                    
    $this->limitedvip = new Config($this->getDataFolder() . "PlayersInfo/" strtolower($limitedvip->getName()), Config::YAML, array());
                                    
    $this->limitedvip;
                                    
    $after $args[2];
                                    
    $after round($after2);
                                    
    $secAfter $after*3600;
                                    
    $limitedviptime $secAfter time();
                                    
    $this->limitedvip->set("limited_V.I.P.""true");
                                    
    $this->limitedvip->set("limited_V.I.P._time"$limitedviptime);
                                    
    $this->limitedvip->save();
                                   
                                }
                            }
    }
    ERROR:
    Code:
    limitedvip add Simon 1
    [17:37:58] [Server thread/INFO]: An unknown error occurred while attempting to perform this command
    [17:37:58] [Server thread/CRITICAL]: Unhandled exception executing command 'limitedvip add Simon 1' in limitedvip: Undefined variable: limitedvip
    [17:37:58] [Server thread/NOTICE]: UndefinedVariableException: "Undefined variable: limitedvip" (E_NOTICE) in "/McKaff_Settings/src/McKaff_Settings/Main" at line 240
    
    Thx Marcelo234
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP...
    PHP:
    if($cmd->getName() == "limitedvip") {
                        if(!isset(
    $args[0]) || count($args) > 4){
                    
    $sender->sendMessage(TextFormat::GREEN."Usage: /limitedvip <add/remove> [player] [time]");
                    return 
    true;
                        }
                        switch(
    strtolower($args[0])){
                         
                        case 
    "add":
                            if(isset(
    $args[1])){
                                if(isset(
    $args[2])){
                                     
    $limitedvip $args[1];
                                    
    $this->limitedvip = new Config($this->getDataFolder() . "PlayersInfo/" strtolower($limitedvip->getName()), Config::YAML, array());
                                    
    $after $args[2];
                                    
    $after round($after2);
                                    
    $secAfter $after*3600;
                                    
    $limitedviptime $secAfter time();
                                    
    $this->limitedvip->set("limited_V.I.P.""true");
                                    
    $this->limitedvip->set("limited_V.I.P._time"$limitedviptime);
                                    
    $this->limitedvip->save();
                                 
                                }
                            }
    }
  3. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    What you changed?
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    $args[1] = $limitedvip; => $limitedvip = $args[1];
  5. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Code:
    limitedvip add Simon 1
    
    Fatal error: Call to a member function getName() on string in C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\plugins\McKaff_Settings\src\McKaff_Settings\Main.php on line 241
    
    
  6. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    what is line 241?
  7. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    This:
    PHP:
    $this->limitedvip = new Config($this->getDataFolder() . "PlayersInfo/" strtolower($limitedvip->getName()), Config::YAML, array()); 
  8. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I think you're is trying to get the name of the player (Should be done with $this->getServer()->getPlayer($String)->getName() )
  10. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    why don't you simply use $limitedvip? $limitedvip isn't instanceof Player, its a string.
  11. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    It should be a player
  12. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    You want to use
    /limitedvip add PocketKiller 1
  13. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    why? $args[1] is what the players typed on /limitedvip 0 {this} so what a player types is a string.
    if you want to get the player from the name on $args[1]:
    PHP:
    $this->getServer()->getPlayer($args[1]);
  14. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    $limitedvip should be the Player $args[1]
  15. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    it should not be the player, it will return just a string like 'Simon' it'll never return a player object.
    as I told you above, if you want to get the player from that string use it.
  16. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    $args[1] isn't an object, it's a string.
    Try:
    PHP:
    private function getValidPlayer($name)
    {
    $player $this->getServer()->getPlayer($name);
    if(
    $player instanceof Player){
    return 
    $player;
    }
    else{
    return 
    false;
    }
    }
  17. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Why need instanceof Player?
    PocketKiller and PEMapModder like this.
  18. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    You need it because $this->getServer()->getPlayer($name) will return null if player is not online
  19. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    To check if the player is online (actually exists).
    EDIT: Got in a few seconds too late :/
  20. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Oh...ok. Thanks for the information

Share This Page

Advertisement