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

[Config] Reading user added lines

Comments in 'Plugin Development' started by meharryp, Jan 1, 2014.

  1. meharryp
    Offline

    meharryp New Member

    Joined:
    Dec 27, 2013
    Posts:
    2
    Minecraft User:
    meharryp
    I'm working on a plugin that would involve players adding lines to the config file. However, I'm wondering how this would be possible.

    Code at the moment:
    PHP:
    class cmdr implements Plugin{
      private 
    $api;

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

      public function 
    init(){
      
    $this->path $this->api->plugin->createConfig($this, array(
                
    "cmd1" => $cmd[0],
                
    "cmd2" => $cmd[1],
                
    "cmd3" => $cmd[2],
            ));
            
    $this->config $this->api->plugin->readYAML($this->path."config.yml");
                
    $this->config["cmd1"] = $cmd[0];
                
    $this->config["cmd2"] = $cmd[1];
                
    $this->config["cmd3"] = $cmd[2];
                
    $this->api->plugin->writeYAML($this->path."config.yml"$this->config);
            foreach(
    $this->config as $read => $run){
              
    $this->api->console->run($run);
              }
        }
       
        public function 
    __destruct(){
        }
    }
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I've already made a framework for configs. Waiting for topic approval.
  3. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    Topic denied because I bugged staff about approving it. o_O Here, make sure to leave credit.

    Attached Files:

  4. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    It's not only denied because you bugged staff about approving it, your "framework" is just bad. If you have a string with a ^ it won't work anymore, and storing objects is also not possible. If you don't like don't like yaml the you could use json or a database.
    Last edited: Jan 14, 2014
  5. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I don't know where you're getting your information about ^ in strings, but last time I checked, you just couldn't put ' or " (depending on which one the string is enclosed in).
  6. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    You implode array's with the character ^
    so if you would use ^ in a string then when you read the file it will be split wrong
    Last edited: Jan 14, 2014
    LDX likes this.
  7. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I was hoping no one would put ^ in their config. XD
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I made this plugin for LegionPE, and I am releasing a very small part of it (really small, Lambo, don't blame me):
    PHP:
    define("MINKILLCOUNT_SAVE_SPLITER","::::");
    PHP:
        public function save(){
            
    $c=0;
            foreach(
    $this->playersData as $ign=>$data){
                
    file_put_contents($this->playerStreams[$ign], implode(MINKILLCOUNT_SAVE_SPLITER,$data));
                
    $c++;
            }
            
    $i=0;
            foreach (
    $this->independentSave as $ign => $data) {
                
    file_put_contents($this->playerStreams[$ign], implode(MINKILLCOUNT_SAVE_SPLITER,$data));
                
    $i++;
            }
            
    $this->independentSave=array();
            
    console(FORMAT_AQUA."[INFO] Saved $c online player database files and $i just-went-offline player database files.");
        }
    PHP:
            $contents=file_get_cotents($this->playerStreams[$player->username]);//input the old file (if exists)
            
    $data=explode(MINKILLCOUNT_SAVE_SPLITER,$contents);
    First it is me who wrote this code, second this is just not even 10% inside the code, so you see. I use constants (not too short to be generic, not too long to lag the server, so I used four colons) to split the data so that it is easier to split the data since each datum is a number and a number doesn't start/end with a colon. And even if I somehow later when updating the code find out that I have to save a string with a potential "::::", I can easily just change the four colons to something else, like "````".
  9. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I thought of that, but I gave up on CF. lol The staff is too strict.
  10. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I was going to use ***.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In fact, plugins with large databases and a lot of I/O like SimpleAuth should use this too because in its databases the YAML files are simple arrays (not nested):
    Example:
    Code:
    ---
    registerdate: 1389597556
    logindate: 1389670416
    lastip: 192.168.0.101
    hash: >
      ********HIDDEN FOR SECURITY********
    The first two are dec long data as timestamps, the second is an IP address that is always four numbers with three dots inside, and the hash code is only a hex long datum. So if SimpleAuth does not put the prefixes (regiserdate, logindate, lastip, hash) the efficiency will be faster as PHP does not need to search for the Config class then the Spyc class to toString-ize the array. If it just saves like this:
    Code:
    1389597556~~1389670416~~192.168.0.101~~1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
    It will be faster. The reason why I put two ~s instead of one is, in fact, nothing with the computer. It is for the sake of convenience to the debugger, in case any bugs occurred. Moreover, ~ once is uncommon enough even for strings, and twice is even more.
    But of course, a line break is even better, but the problem of supporting multiple OS (like \r and \r\n and \n) would occur.
  12. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    You stole my idea and rewrote it. :mad:
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Absolutely not. I swear not. I don't even know which idea of yours are you talking about.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Grammar edit: "I don't even know which idea of yours you are talking about".
  15. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    ConfigFramework.
  16. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Never mind if I really did because the early bird gets the worm. Anyway I just didn't look at whatever you are talking about because I had never read any code you wrote. Moreover this is not a releasing plugin on the forums. Just a private plugin between Lambo and me.
  18. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    Sure.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
  20. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    What does that even do??

Share This Page

Advertisement