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

How to write configs?

Comments in 'Plugin Development' started by iiDeathStrokeii, May 3, 2015.

  1. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    PHP:
    public function onLoad(){
            @
    mkdir($this->getDataFolder());
            
    $this->SpleefOne = (new Config($this->getDataFolder()."SpleefOne.yml"Config::YAML, array(
                
    "Join-Spleef-One-Message" => TextFormat::RED."[Spleef]".TextFormat::YELLOW."Joining Spleef Lobby One!",
                
    "Spleef_One_Players" => 0,
                
    "Spleef_One_In_Progress" => false,
                
    "SpleefOnePlayerOne" => null,
                
    "SpleefOnePlayerTwo" => null,
                
    "SpleefOnePlayerThree" => null,
                
    "SpleefOnePlayerFour" => null,
                
    "SpleefOnePlayerFive" => null,
                
    "SpleefOnePlayerSix" => null,
                
    "SpleefOnePlayerSeven" => null,
                
    "SpleefOnePlayerEight" => null,
                
    "max-players" => 8,
                )));
            
    $this->getLogger()->info(TextFormat::BLUE."CloudPvP Spleef");

        }


    (YAML)


    Code:
    ---
    Join-Spleef-One-Message: §c[Spleef]§eJoining Spleef Lobby One!
    Spleef_One_Players: 0
    Spleef_One_In_Progress: false
    SpleefOnePlayerOne: ~
    SpleefOnePlayerTwo: ~
    SpleefOnePlayerThree: ~
    SpleefOnePlayerFour: ~
    SpleefOnePlayerFive: ~
    SpleefOnePlayerSix: ~
    SpleefOnePlayerSeven: ~
    SpleefOnePlayerEight: ~
    max-players: 8
    ...
    


    PHP:
            public function onPlayerInteract(PlayerInteractEvent $event){
                
    $p $event->getPlayer();
               
                
    $tile $event->getBlock()->getLevel()->getTile($event->getBlock());
                if (
    $tile instanceof Sign) {
                    
    $tiles $tile->getText();
                     if (
    $tiles[0] == "[CloudPvP]" and $tiles[1] == "Spleef"){
                         
    $tile->setText($tiles[0], $tiles[1], $this->SpleefOne->get("Spleef_One_In_Progress"), $this->SpleefOne->get("Spleef_One_Players"). "/" $this->SpleefOne->get("max-players"));
                         if (
    $this->SpleefOne->get("Spleef_One_In_Progress") == false and $this->SpleefOne->get("Spleef_One_Players") < 8){
                           
                              
    $p->sendMessage($this->SpleefOne->get("Join-Spleef-One-Message"));
                              
    $this->SpleefOne->get("Spleef_One_Players");
                              
    $this->SpleefOne->get("Spleef_One_In_Progress") == false and $this->SpleefOne->get("Spleef_One_Players")+1;
                                   
                                    if (
    $this->SpleefOne->get("SpleefOnePlayerOne") == null or $this->SpleefOne->get("SpleefOnePlayerOne")->isOnline() == false) {
                                     
    $event->getPlayer()->teleport(new Vector3(-120626280));
                                     
    $p->sendMessage(TextFormat::RED."[Spleef] Please Wait.");
                                     
    $item Item::get(256,0,1);
                                     
    $p->getInventory()->addItem($item);
                   
                                     
    $this->SpleefOne->get("SpleefOnePlayerOne") = $this->p->getName();
                                    
                                        
                                        
                                    
                                   
                           
                                    }
                          }
                     }
                }
            }

    On the PHP code above, on the last line of text (which is obviously wrong and crashes the server) how do I correctly assign SpleefOnePlayerOne as $p's name in the config file?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Try
    PHP:
    $this->SpleefOne->set("SpleefOnePlayerOne"$p->getName());
  3. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    well no crash but when i checked the config file (yes I did refresh) but SpleefOnePlayerOne was still set to null :(
  4. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  5. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  6. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    There is other stuff wrong with that code but if you are looking for a fix for that line, you should have
    PHP:
    $this->SpleefOne->set("SpleefOnePlayerOne"$p->getName());
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The question is, why use config?
    64FF00 likes this.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Add this after setting the Player
    PHP:
    $this->SpleefOne->save();

Share This Page

Advertisement