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

Config code help...

Comments in 'Plugin Development' started by korado531m7, Oct 15, 2015.

  1. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    I'm creating plugin with Config that can save message data.
    I want to save to Config below if player typed chat

    $player<>$message<>$time<>$host/$ip<>

    Important: Need <> and don't use space.

    $player is message sent player
    $message is sent message
    $time is sent message time
    $host is player's host
    $ip is player's ip

    I've already defined these codes.
    But I don't know how to save these code in Config.

    Thank you for reading my thread, and answering.
  2. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Use this to save config:
    PHP:
    $this->saveConfig();
    Also, you needed a variable, example:
    PHP:
    private $example
    And make sure that variable is used in loadConfig
    PHP:
    $this->example $this->getConfig()->get("example");
    To make it works, use that variable and saveConfig together:
    PHP:
    $this->example //Code to fetch the value;
    $this->saveConfig();
    "//Code to fetch the value" is the code you use to get new $player, $messages, $host, etc
    Hope this helped ;)
    Last edited: Oct 15, 2015
    HamIsGoodie likes this.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    In that case, you could define the variable in the PlayerChatEvent itself, for example
    PHP:
    public function onChat(PlayerChatEvent $event){
       
    $message $event->getMessage();
    }
    Setting the variable to private before would be useless as you only need it in this event and it is something else for every Player
  4. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    @CraftYourBukkit
    Whatever :p, im just showing an example... He just asking the way to save config... LOL
    HamIsGoodie likes this.
  5. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Actually, I'm creating saving chat log plugin.
    So i want save Name , Message , IP , And Host
    I'm using function is PlayerCommandPreprocessEvent.
    Please tell me these code in details.
    Sorry my selfishness :-(
  6. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hmmm... saving chat log? There's server.log for it... Why you wanted to create one more log for it? :p I think it will just make your server laggy...
    HamIsGoodie likes this.
  7. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    HamIsGoodie and HotFireyDeath like this.
  8. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    server.log is for everything. A chat log would be nice. And no, it won't make it your server laggy, depending on how you save the chat messages. And can you quote posts? It makes it easier for everyone to see who you are talking to, and people will know if you're talking to them or someone else.
  9. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    I want to see in website the server chat.
    Connect to the chat log file with WebDAV server. So I want to that.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In onEnable:
    PHP:
    @mkdir($this->getDataFolder());
    touch($this->getDataFolder() . "chat.log");
    Every time you add a new line into the logs:
    PHP:
    file_put_contents($this->getDataFolder() . "chat.log"$yourLineHereJustDefineItYourselfImNotGoingToDemonstrateHow PHP_EOLFILE_APPEND);
    Two important things
    PHP_EOL: adds a line break (system dependent, LF or CRLF) after each line
    FILE_APPEND: makes the file write mode append instead of overwrite.

    You can also use fopen and fwrite and fclose if you want to make it a bit faster.
    But the best method is to use FileWriteTask like this (with the mkdir and touch):
    PHP:
    $this->getServer()->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataFolder() . " chat.log"$lineFILE_APPEND));
    This avoids the overhead for appending the line to the file. Be aware of possible race condition, where the lines may not be appended in the correct order.
    Last edited: Oct 18, 2015
  11. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    I will use function is
    PHP:
    public function PlayerCommand(PlayerCommandPreprocessEvent $event){

           
    $message $event->getMessage();

           
    $player $event->getPlayer();

           
    $name $player->getName();
           
    $host gethostbyaddr($player);
           
    $ip $player->getAddress();
           
    $id $player->getClientId();
           
    //$player->getUniqueId();
           
    $this->Data $this->getConfig();
           
    $time $this->date("Y/m/d , H:i.s"time());
           }
    And I want to save name, time, message, ip, host and clientid.
    Last edited: Oct 17, 2015

Share This Page

Advertisement