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

[NEW API] Help on a config.yml file

Comments in 'Plugin Development' started by RekkuzaRage, Jul 2, 2014.

  1. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    I am currently trying to add a config file to plugin, but when I try to add a player to the player.yml by using the command /elite add <player> It automatically crashes my PM 1.4DEV server.

    Can someone show me how to create proper config file in the API.

    Below is player.yml in the OLD API, it will show you what I am trying to do in the new API.
    PHP:
    $this->players = new Config($this->api->plugin->configPath($this)."players.yml"CONFIG_YAML, array());

        }

        public function 
    commandElite($cmd$args$issuer){

        switch(
    $args[0]){

            case 
    "add":

                        if(isset(
    $args[1])) {
                            
    $user $args[1];
                         
                            if(
    $this->api->player->get($user) != false) {
                                
    $this->players->set($user,true);
                                
    $this->players->save();
                             
                                
    $issuer->sendChat("[DG Pocket] Player {$user} is now ranked Elite");
                                }
                                else    {

                                
    $issuer->sendChat("[DG Pocket] Player {$user} is not online or does not exist");

                            }

                        } else {

                            
    $issuer->sendChat("usage: /elite add|remove <player>");

                        }
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And what about new API?
    64FF00 likes this.
  3. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    PHP:
         @mkdir($this->getDataFolder());
            
    $this->elite = new Config($this->getDataFolder()."players.yml"Config::YAML, array());

        }

        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
            switch(
    $command->getName()){

                case 
    "add":
                   {
                            
    $this->elite->set($player->getName());
                            
    $this->elite->save();
                            
    $this->getLogger()->info($player->getName() . "'s Elite rank is now activated");
                    }
  4. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    For the new API just use:
    PHP:
    $this->saveDefaultConfig();
    $this->getResource("config.yml");
    To save the config onEnable() and then use:
    PHP:
    $this->getConfig()->get("config_option");
    To get the config settings.
    RekkuzaRage and 64FF00 like this.
  5. 64FF00
    Offline

    64FF00 Active Member Plugin Developer

    Joined:
    May 11, 2014
    Posts:
    298
    Plugins:
    2
    Minecraft User:
    64FF00
    PHP:
    <?php

    ...

    public function 
    onEnable()
    {
        
    $this->players = new Config($this->plugin->getDataFolder() . "players.yml"Config::YAML, array(
        ));
    }

    ...

    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
    {
        switch(
    $cmd->getName())
        {
            case 
    "elite":

                if(!isset(
    $args[0]))
                {
                     
    $sender->sendMessage("[TEST] QUACK");
                }
                
                switch(
    $args[0])
                {
                    case 
    "add":
                
                        if(!isset(
    $args[1]))
                        {
                            
    $sender->sendMessage("[TEST] Usage: /elite add <player>");
                        
                            break;
                        }
                    
                        
    $player $this->getValidPlayer($args[1]);
                    
                        
    $this->players->set($player->getName(), true);
                        
    $this->players->save();
                    
                        
    $sender->sendMessage("[TEST] Player [" $player->getName() . "] is now ranked elite.");
                    
                        break;
                    
                }
            
                return 
    true;
                
            default:
                
                return 
    false;
        }
    }

    ...

    // getValidPlayer() from xPermsMgr
    private function getValidPlayer($username)
    {
        
    $player $this->getServer()->getPlayer($username);
        
        return 
    $player instanceof Player $player $this->getServer()->getOfflinePlayer($username);
    }

    ...

    Last edited: Jul 2, 2014
    RekkuzaRage likes this.
  6. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    When I run the server there is problems.
    Code:
    08:21:31 [ERROR] A E_WARNING error happened: "yaml_parse(): parsing error encountered during parsing: did not find expected key (line 21, column 2), context while parsing a block mapping (line 14, column 2)" in "phar://C:/Users/Magali/Downloads/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginDescription.php" at line 50
    08:21:31 [NOTICE] A E_RECOVERABLE_ERROR error happened: "Argument 1 passed to pocketmine\plugin\PluginDescription::loadMap() must be of the type array, boolean given, called in phar://C:/Users/Magali/Downloads/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginDescription.php on line 50 and defined" in "phar://C:/Users/Magali/Downloads/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginDescription.php" at line 58
    
    Fatal error: Uncaught exception 'Exception' with message 'Invalid PluginDescription name' in phar://C:/Users/Magali/Downloads/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginDescription.php:61
    Stack trace:
    #0 phar://C:/Users/Magali/Downloads/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginDescription.php(50): pocketmine\plugin\PluginDescription->loadMap(false)
    #1 phar://C:/Users/Magali/Downloads/PocketMine-MP/plugins/DevTools_v1.8.0-4c37f602.phar/src/FolderPluginLoader/FolderPluginLoader.php(93): pocketmine\plugin\PluginDescription->__construct('name: EliteCore...')
    #2 phar://C:/Users/Magali/Downloads/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php(188): FolderPluginLoader\FolderPluginLoader->getPluginDescription('C:\Users\Magali...')
    #3 phar://C:/Users/Magali/Downloads/PocketMine-MP/plugins/DevTools_v1.8.0-4c37f602.phar/src/DevTools/DevTools.php(47): pocketmine\plugin\PluginManager->loadPlugins('C:\Users\Magali...', Array)
    #4 phar://C:/Users/Magali/Downloads/PocketMine-M in phar://C:/Users/Magali/Downloads/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/plugin/PluginDescription.php on line 61
    
    
    Here is the entire plugin including plugin.yml

    PHP:
    <?php

    namespace EliteCore;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;

    class 
    EliteCore extends PluginBase{

        public 
    $elite;

    public function 
    onEnable()
    {
        
    $this->players = new Config($this->plugin->getDataFolder() . "players.yml"Config::YAML, array(
        ));
    }

    ...

    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
    {
        switch(
    $cmd->getName())
        {
            case 
    "elite":

                if(!isset(
    $args[0]))
                {
                     
    $sender->sendMessage("[TEST] QUACK");
                }
                
                switch(
    $args[0])
                {
                    case 
    "add":
                
                        if(!isset(
    $args[1]))
                        {
                            
    $sender->sendMessage("[TEST] Usage: /elite add <player>");
                        
                            break;
                        }
                    
                        
    $player $this->getValidPlayer($args[1]);
                    
                        
    $this->players->set($player->getName(), true);
                        
    $this->players->save();
                    
                        
    $sender->sendMessage("[TEST] Player [" $player->getName() . "] is now ranked elite.");
                    
                        break;
                    
                }
            
                return 
    true;
                
            default:
                
                return 
    false;
        }
    }

    ...

    // getValidPlayer() from xPermsMgr
    private function getValidPlayer($username)
    {
        
    $player $this->getServer()->getPlayer($username);
        
        return 
    $player instanceof Player $player $this->getServer()->getOfflinePlayer($username);
    }

        public function 
    command($cmd$args$issuer){

             
    $player $this->getValidPlayer;

            if (
    $this->players->get($player)){

                switch(
    $cmd){

                        case 
    "basickit":

                             
    $this->getServer()->dispatchCommand("give $username 260 1");
                             
    $this->getServer()->dispatchCommand("give $username 268 1");
                             
    $output "[DG Pocket] You have received your basic kit\n";

                             return 
    $output;

                    break;

            }                 

            } else {

                
    $output "[DG Pocket] You cannot use this command, you are not ranked Elite\n";

                return 
    $output;
               
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("EliteCore is now disabled!");
            
    $this->elite->save();
        }
       
    }
    Here is the plugin.yml
    PHP:
    nameEliteCore
    main
    EliteCore\EliteCore
    author
    RekkuzaRage
    version
    0.1 Build 1
    api
    1.0.0
    commands
    :
    add:
      
    permissionelitecore.add
      description
    Activates a player's Elite rank.
      basickit:
      permission: elitecore.basickit
      description: Gives player a basickit
    permissions:
    elitecore:
      default: op
      description: Top permission
      children:
       elitecore.add:
        default: true
        description: Activates a player'
    s Elite rank.
    ]
    Thanks RekkuzaRage
  7. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Do you realy not see the syntax in plugin.yml is red?
    PHP:
    nameEliteCore
    main
    EliteCore\EliteCore
    author
    RekkuzaRage
    version
    0.1 Build 1
    api
    1.0.0
    commands
    :add:permissionelitecore.add
    description
    Activates a players Elite rank.
    basickit:
    permissionelitecore.basickit
    description
    Gives player a basickit
    permissions
    :
    elitecore:
    default: 
    op
    description
    Top permission
    children
    :
    elitecore.add:
    default: 
    true
    description
    Activates a players Elite rank.
    ]
    Try this plugin.yml
  8. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    I know one of the problems is the plugin.yml, but there is more.
  9. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    PARSER:
    ERROR:

    while parsing a block mapping
    in "<unicode string>", line 1, column 1:
    name: EliteCore
    ^
    expected <block end>, but found ']'
    in "<unicode string>", line 19, column 1:
    ]
    ^
    PHP:
    nameEliteCore
    main
    EliteCore\EliteCore
    author
    RekkuzaRage
    version
    0.1 Build 1
    api
    1.0.0
    commands
    :add:permissionelitecore.add
    description
    Activates a players Elite rank.
    basickit:
    permissionelitecore.basickit
    description
    Gives player a basickit
    permissions
    :
    elitecore:
    default: 
    op
    description
    Top permission
    children
    :
    elitecore.add:
    default: 
    true
    description
    Activates a players Elite rank.
    This realy work, try!
  10. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    Thanks, but there is still problems...
  11. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Can i see error?
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I don't think $this->getResource() is necessary.
    thebigsmileXD likes this.
  13. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    I fixed the plugin a bit more, but this is the only problem showing.
    Code:
    09:10:38 [INFO] Loading source plugin EliteCore v0.1 Build 1
    
    Fatal error: Cannot redeclare EliteCore\EliteCore::onCommand() in C:\Users\Magali\Downloads\PocketMine-MP\plugins\EliteCore_v0.1 Build 1\src\EliteCore\EliteCore.php on line 70
    
    
    The updated plugin code.
    PHP:
    <?php

    namespace EliteCore;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;

    class 
    EliteCore extends PluginBase{

        public 
    $elite;

    public function 
    onEnable()
    {
        
    $this->players = new Config($this->plugin->getDataFolder() . "players.yml"Config::YAML, array(
        ));
    }

    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
    {
        switch(
    $cmd->getName())
        {
            case 
    "elite":

                if(!isset(
    $args[0]))
                {
                     
    $sender->sendMessage("[TEST] QUACK");
                }
                
                switch(
    $args[0])
                {
                    case 
    "add":
                
                        if(!isset(
    $args[1]))
                        {
                            
    $sender->sendMessage("[TEST] Usage: /elite add <player>");
                        
                            break;
                        }
                    
                        
    $player $this->getValidPlayer($args[1]);
                    
                        
    $this->players->set($player->getName(), true);
                        
    $this->players->save();
                    
                        
    $sender->sendMessage("[TEST] Player [" $player->getName() . "] is now ranked elite.");
                    
                        break;
                    
                }
            
                return 
    true;
                
            default:
                
                return 
    false;
        }
    }

    // getValidPlayer() from xPermsMgr
    private function getValidPlayer($username)
    {
        
    $player $this->getServer()->getPlayer($username);
        
        return 
    $player instanceof Player $player $this->getServer()->getOfflinePlayer($username);
    }

        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){

             
    $player $this->getValidPlayer;

            if (
    $this->players->get($player)){

                switch(
    $cmd){

                        case 
    "basickit":

                             
    $this->getServer()->dispatchCommand("give $username 260 1");
                             
    $this->getServer()->dispatchCommand("give $username 268 1");
                             
    $output "[DG Pocket] You have received your basic kit\n";

                             return 
    $output;

                    break;

            }                 

            } else {

                
    $output "[DG Pocket] You cannot use this command, you are not ranked Elite\n";

                return 
    $output;
               
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("EliteCore is now disabled!");
            
    $this->elite->save();
        }
       
    }
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You declared function onCommand() twice.
    64FF00 likes this.
  15. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    How do I fix it then?
  16. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    just put the "basickit" command under onCommand . if you want i can fix it for you ;)
  17. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    Yeah, you can fix it.
  18. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    never mind . i don't have time to fix it now . i am on my relaxing two hours :p
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Refer to CustomRanks for a good example.
  20. RekkuzaRage
    Offline

    RekkuzaRage Active Member

    Joined:
    Apr 15, 2014
    Posts:
    252
    Minecraft User:
    RekkuzaRage
    The plugin now loads!
    Code:
    06:28:15 [INFO] Enabling DevTools v1.8.0
    06:28:15 [INFO] Loading source plugin EliteCore v0.1 Build 1
    06:28:15 [INFO] [DevTools] Registered folder plugin loader
    06:28:15 [INFO] Preparing level "world"
    06:28:15 [INFO] Enabling EliteCore v0.1 Build 1
    06:28:15 [INFO] Default game type: CREATIVE
    06:28:15 [INFO] Done (1.31s)! For help, type "help" or "?"
    
    When I the command /elite add <player>
    It says...
    Code:
    elite add RekkuzaRage
    06:33:48 [INFO] Unknown command. Type "help" for help.
    
    Here is the updated code.
    PHP:
    <?php

    namespace EliteCore;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;

    class 
    EliteCore extends PluginBase{

        public 
    $elite;

    public function 
    onEnable()
    {
       
    $this->players = new Config($this->getDataFolder()."players.yml"Config::YAML);
    }

    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
    {
        switch(
    $cmd->getName())
        {
            case 
    "elite":

                if(!isset(
    $args[0]))
                {
                     
    $sender->sendMessage("[DG Pocket] ELITECORE PROPERTY OF DG POCKET NETWORK");
                }
                
                switch(
    $args[0])
                {
                    case 
    "add":
                
                        if(!isset(
    $args[1]))
                        {
                            
    $sender->sendMessage("[DG Pocket] Usage: /elite add <player>");
                        
                            break;
                        }
                    
                        
    $player $this->getValidPlayer($args[1]);
                    
                        
    $this->players->set($player->getName(), true);
                        
    $this->players->save();
                    
                        
    $sender->sendMessage("[DG Pocket] Player " $player->getName() . "'s elite rank is now activated");
                    
                        break;
                    
                }
            
                return 
    true;
                
            default:
                
                return 
    false;
        }
    }

    // getValidPlayer() from xPermsMgr

    private function getValidPlayer($username)
    {
        
    $player $this->getServer()->getPlayer($username);
        
        return 
    $player instanceof Player $player $this->getServer()->getOfflinePlayer($username);
    }

        public function 
    Command(CommandSender $senderCommand $command$label, array $args){

             
    $player $this->getValidPlayer;

            if (
    $this->players->get($player)){

                switch(
    $cmd){

                        case 
    "basickit":

                             
    $this->getServer()->dispatchCommand("give $player 260 1");
                             
    $this->getServer()->dispatchCommand("give $player 268 1");
                             
    $output "[DG Pocket] You have received your basic kit\n";

                             return 
    $output;

                    break;

            }                 

            }
            else

            {    
    $output "[DG Pocket] You cannot use this command, you are not ranked Elite\n";

                return 
    $output;
               
        }
       
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("EliteCore is now disabled!");
            
    $this->elite->save();
        }
       
    }
    Here is the updated plugin.yml
    PHP:
    nameEliteCore
    main
    EliteCore\EliteCore
    author
    RekkuzaRage
    version
    0.1 Build 1
    api
    1.0.0
    commands
    :
    add:
      
    permissionelitecore.add
      description
    Activates a player's Elite rank.
      basickit:
      permission: elitecore.basickit
      description: Recieve a basic kit.
    permissions:
    elitecore:
      default: op
      description: Top permission
      children:
      elitecore.add:
      default: true
      description: Activates a player'
    s Elite rank.
      
    elitecore.basickit:
      default: 
    true
      description
    Recieve a basic kit.

Share This Page

Advertisement