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

Config Help

Comments in 'Plugin Development' started by Lambo, Apr 21, 2014.

  1. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Hi guys, I'm working on a chat plugin and I don't really understand how to get and set stuff from the config.

    Exampe: $this->config->exists("ranks")[$this->getRank($player->username)] doesnt work as it says "cant use exists on a non-object"

    Code:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=MultiCbat
    version=1.0
    description=Separate chat for each world
    author=Lambo
    class=multichat
    apiversion=11
    */

    class multichat implements Plugin{
            private 
    $api;

            public function 
    __construct(ServerAPI $api$server false){
                
    $this->api $api;
            }

            public function 
    __destruct(){}

            public function 
    init(){
                
    $this->api->addHandler("player.chat", array($this,"onChat"));
                
    $this->config = new Config($this->api->plugin->configPath($this)."config.yml"CONFIG_YAML, array(
                        
    "ranks"=> array(
                            
    "default"=> array(
                                
    "world"=> array(
                                   
    "tag"=>"Player","chat-format"=>"|@tag|@player: @message"
                                
    )
                            ),
                            
    "moderator"=> array(
                                
    "world"=>array(
                                   
    "tag"=>"Mod","chat-format"=>"|@tag|@player: @message"
                                
    )
                            ),
                            
    "admin"=> array(
                                
    "world"=>array(
                                   
    "tag"=>"Admin","chat-format"=>"|@tag|@player: @message"
                                
    )
                            ),
                           
    "owner"=>array(
                              
    "world"=>array(
                                 
    "tag"=>"Owner","chat-format"=>"|@tag|@player: @message"
                              
    )
                           ),
                            
    "vip"=> array(
                                
    "world"=>array(
                                   
    "tag"=>"ViP","chat-format"=>"|@tag|@player: @message"
                                
    )
                            )
                        ),
                        
    "in-ranks"=>array(
                            
    "ranks" => array(
                               
    "moderator"=>array(),
                               
    "admin"=>array(),
                               
    "owner"=>array(),
                               
    "vip"=>array()
                           )
                        )
                   )
                );
            }

            public function 
    onChat($data){
                
    $player $data["player"];
                
    $message $data["message"];
                
    $level $player->level->getName();
                
    $tag $this->config->get("ranks")[$this->getRank($player->username)]["tag"];
                
    $format $this->config->get("ranks")[$this->getRank($player->username)]["chat-format"];
                
    $username $player->username;
                foreach(
    $this->api->player->getAll($level) as $players){
                    if(
    $this->config->exists("ranks")[$this->getRank($player->username)][$level]){
                        
    $players->sendChat(str_replace(array("@tag","@player"),array($tag,$username),$format));
                    }else{
                        
    $this->config->set("ranks")[$this->getRank($player->username)][$level][$this->config->get("ranks")[$this->getRank($player->username)]["tag"]];//basically creates the other world in the config
                        
    $this->config->set("ranks")[$this->getRank($player->username)][$level][$this->config->get("ranks")[$this->getRank($player->username)]["chat-format"]];
                        
    $players->sendChat(str_replace(array("@tag","@player"),array($tag,$username),$format));
                    }
                }
            }
    So can you guys teach me how to use configs like the way im using them in my code?

    PS: I have the function $this->getRank defined in my code ;)

    Thanks.
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    No help? :/
    Nautox likes this.
  3. Nautox
    Offline

    Nautox Banned

    Joined:
    Mar 29, 2014
    Posts:
    8
    Minecraft User:
    Nautox
    Can i help you in a private conversation?
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Sure.
  5. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Anyone help?
  6. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    ...

Share This Page

Advertisement