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

Config::correct

Comments in 'Plugin Development' started by PEMapModder, Dec 20, 2013.

  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    According to this, the issue Config::correct is solved.
    https://github.com/PocketMine/PocketMine-MP/issues/996

    But why does this still keep showing Config::correct undefined?
    IMPORTANT
    LICENSE:
    Copyright (C) 2013 PEMapModder

    All PHP files in this repository may only be downloaded and used with permission from PEMapModder given from the following means:
    - A PM from MCPE_modder_for_maps or PEMapModder on minecraftforum.net
    - A private message from PEMapModder on forums.pocketmine.net
    - An e-mail from [email protected]
    for the following purposes:
    - Used on an MCPE server hosted by people permitted by the means above, using software downloaded from pocketmine.net and the files generated by them, except files put in the /world and /plugins directory
    - Used to learn PHP and PocketMine plugin development without copying more than 80% of the originally code (permission is not required)
    - Used to improve the plugin and used for purpose on line 8 without distributing or redistributing them without permission from the above means, or commit improvements using the fork function at github.com

    Official repository for this project on GitHub:
    - https://github.com/pemapmodder/PlayerActionsLogger.git

    PHP:
    <?php
    /*
    __PocketMine Plugin__
    name=Player Actions Logger
    version=beta 2.0
    description=A plugin that logs player actions into YAML files
    apiversion=10
    class=Beta
    author=PEMapModder
    */
    class Beta implements Plugin{
        private 
    $dir,$api,$aLog,$vLog,$opLog,$griefingLog,$genericLog,$config,$a=0,$v=1,$op=2,$grief=3,$generic=4,$tempA,$tempV,$tempOp,$tempGrief,$tempGeneric,$breaks=5,$tap=6;
        public 
    $carriedItem=array();
        public function 
    __construct(ServerAPI $api$server=false){$this->api=$api;}
        public function 
    __destruct(){$this->save();}
        public function 
    init(){
            
    $this->dir=$this->api->plugin->configPath($this);
    if(
    true){
            
    $this->aLog=new Config($this->dir."annoymous_log.yml"CONFIG_YAML, array(
                
    "Default log includes"    =>array("stone","grass","dirt","cobble","all woods and saplings","sand","gravel","flowers","shrub and tall grass","torch","furnace","signs","ladder","snow","ice","crafting table","stone cutter"),
                
    "breaks"    =>array(),
                
    "places"    =>array()
            ));
            
    $this->aLog->reload();
            
    $this->tempA=array($this->aLog->get("breaks"),$this->aLog->get("places"));
           
            
    $this->vLog=new Config($this->dir."valuables_log.yml",CONFIG_YAML, array(
                
    "Default log includes"    =>array("all ores and their compressed blocks","mushrooms and crops","bookshelf","obsidian","cactus","clay","sugar cane","nether-related blocks"),
                
    "breaks"    =>array(),
                
    "places"    =>array()
            ));
            
    $this->vLog->reload();
            
    $this->tempV=array($this->vLog->get("breaks"),$this->vLog->get("places"));
           
            
    $this->opLog=new Config($this->dir."ops_generic_dangerous_and_griefing_blocks_log.yml",CONFIG_YAML, array(
                
    "breaks"    =>array(),
                
    "places"    =>array()
            ));
            
    $this->opLog->reload();
            
    $this->tempOp=array($this->opLog->get("breaks"),$this->opLog->get("places"));
               
            
    $this->griefLog=new Config($this->dir."griefing_and_dangerous_blocks_log.yml",CONFIG_YAML, array(
                
    "Default log includes"    =>array("bedrock","lava","bed","cobweb","TNT","fire","water"),
                
    "breaks"    =>array(),
                
    "places"    =>array()
            ));
            
    $this->griefLog->reload();
            
    $this->tempGrief=array($this->griefLog->get("breaks"),$this->griefLog->get("places"));
           
            
    $this->genericLog=new Config($this->dir."generic_blocks_log.yml",CONFIG_YAML, array(
                
    "breaks"    =>array(),
                
    "places"    =>array()
            ));
            
    $this->genericLog->reload();
            
    $this->tempGeneric=array($this->genericLog->get("breaks"),$this->genericLog->get("places"));
           
            
    $this->config=new Config($this->dir."config.yml",CONFIG_YAML, array(
                
    "annoymous log blocks"            =>array(1,2,3,4,5,6,12,13,17,18,31,37,38,50,61,62,63,68,65,78,79,58,245),
                
    "valuables log blocks"            =>array(14,15,16,21,22,41,39,40,42,47,49,56,57,59,73,74,81,82,83,87,89,103,105,112,114,155,156,246,247),
                
    "grief and danger log blocks"    =>array(7,10,11,30,26,46,51,71,95,8,9),
                
    "save to YAML every how many seconds"    =>300,
                
    "notice I am useless"            =>"Change the above numbers to configurate. Not included blocks are logged at generic_blocks_log.yml"
            
    ));
    }
            
    $this->api->addHandler("player.block.touch",array($this,"blockHandler"),100);
            
    $this->api->addHandler("player.equipment.change",array($this,"equipChange"),100);
            
    $this->config->reload();
            
    $this->api->console->register("instalog","save all logs instantly",array($this,"save"));
            
    $this->api->schedule($this->config->get("save to YAML every how many seconds")*20,array($this,"save"),array(),true);
        }
        public function 
    equipChange($data,$event){
            
    $this->carriedItem[$data["player"]->username]=$data["item"];
        }
        public function 
    blockHandler($data,$event){
            
    $this->config->reload();
            
    $player=$data["player"];
            
    $id=$data["target"]->getId();
            
    $config=$this->config;
            if(
    $event==="player.block.touch"){
                if(
    $data["type"]==="break"$touchType=$this->breaks; else $touchType=$this->tap;
                
    $type=$this->generic;
                if(
    in_array($id$config->get("annoymous log blocks"))){
                    
    $type=$this->a;
                }
                if(
    in_array($id$config->get("valuables log blocks"))){
                    
    $type=$this->v;
                }
                if(
    in_array($id$config->get("grief and danger log blocks"))){
                    
    $type=$this->grief;
                }
                
    $this->addLog($player,$data["target"],$type,$touchType);
            }
        }
        public function 
    addLog($player,$block,$file=-1,$type){
        if(
    $type===$this->breaks){
            if(
    $file===-1){
                
    $file=$this->generic;
            }
            
    $arrayToLog=array(
                
    "block info"    =>    array(
                    
    "world"    =>    $player->entity->level->getName(),
                    
    "x,y,z"    =>    "(".$block->x.",".$block->y.",".$block->z.")",
                    
    "id"    =>    $block
                
    ),
                
    "time"            =>    $this->api->time->get(true),
                
    "player info"    =>array(
                    
    "IGN"        =>    $player->username,
                    
    "gamemode"    =>    $player->getGamemode(),
                    
    "pinginfo"    =>    "Ping ".$player->getLag()." ms, Packet loss ".$player->getPacketLoss()." %",
                    
    "armor"        =>    array(
                        
    "helmet"    =>    $player->getArmor(0),
                        
    "chestplate"=>    $player->getArmor(1),
                        
    "leggings"    =>    $player->getArmor(2),
                        
    "boots"        =>    $player->getArmor(3)
                    ),
                    
    "item"        =>    $this->carriedItem[$player->username],
                    
    "playercoor"=>    "(".$player->entity->x.",".$player->entity->y.",".$player->entity->z.")"
                
    )
            );
            if(
    $this->api->ban->isOp($player->username)){
                
    $this->tempOp[0][]=$arrayToLog;
            }
            else switch(
    $file){
                case 
    $this->a:
                    
    $this->tempA[0][]=$arrayToLog;
                    break;
                case 
    $this->v:
                    
    $this->tempV[0][]=$arrayToLog;
                    break;
                case 
    $this->grief:
                    
    $this->tempGrief[0][]=$arrayToLog;
                    break;
                default:
                    
    $this->tempGeneric[0][]=$arrayToLog;
            }
        }
        if(
    $type===$this->tap){
           
        }
        }
        public function 
    save(){
            
    $this->aLog->set("breaks"$this->tempA[0]);
            
    $this->aLog->set("places"$this->tempA[1]);
            
    $this->vLog->set("breaks"$this->tempV[0]);
            
    $this->vLog->set("places"$this->tempV[1]);
            
    $this->opLog->set("breaks"$this->tempOp[0]);
            
    $this->opLog->set("places"$this->tempOp[1]);
            
    $this->griefLog->set("breaks"$this->tempGrief[0]);
            
    $this->griefLog->set("places"$this->tempGrief[1]);
            
    $this->genericLog->set("breaks"$this->tempGeneric[0]);
            
    $this->genericLog->set("places"$this->tempGeneric[1]);
            
    $this->aLog->save();$this->aLog->reload();
            
    $this->vLog->save();$this->vLog->reload();
            
    $this->opLog->save();$this->opLog->reload();
            
    $this->griefLog->save();$this->griefLog->reload();
            
    $this->genericLog->save();$this->genericLog->reload();
            
    console(FORMAT_AQUA."[PlayerActionsLogger] ".FORMAT_RESET."Saved players actions log");
        }
    }
  2. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    I would highly recommend you to use a database here.
    The best way to improve the performance is to make a pthreads worker and parse it the blocks that players place/break, so the main program don't need to wait before the database is done inserting the values.
    PEMapModder likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I know. i am trying to learn using databases. But what about Config::correct?

Share This Page

Advertisement