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

How can i make a plugin write something to a text?

Comments in 'Plugin Development' started by TheKillerTacos, Feb 7, 2016.

  1. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Hi, im making a plugin that gets the perms of a plugin, and then writes it on a txt file, but idk how to do so,

    but how do i make the Text get written on a txt file (creating it and writing on it)
    i need the code plz :)

    I know how to get the permission, but i dont know how to write it...
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    applqpak likes this.
  3. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Ok, ill see it
  4. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    and how can i know my path? because doing
    $file = 'Permissions.txt';
    i will be where?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Prepend your paths with $main->getDataFolder(), where $main is your main class object ($this in the main class).
  6. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    So itll be /src/ ? but if i want it to be at the Plugins folder /PermList/List.txt?
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    $path $mainClass->getDataFolder() . "PermsList/" "List.txt";
    file_put_contents($path$txt);
    Last edited: Feb 7, 2016
  8. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Though it would be $mainClass->getDataFolder() . "List.txt", but close enough. :p
  9. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    thx
  10. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    but the problem now, is IDK how to do something, ill make another thread
  11. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    WHy make a whole new thread? Post the question here.
  12. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Im really confused, i cant find out how to Make the plugin write, and the plugin crashes, i used part of the code from
    http://forums.pocketmine.net/threads/list-all-your-permissions.14983/ this post. so here is my code,
    PHP:
    <?php
    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\permission\Permission;
    class 
    Main extends PluginBase implements Listener{
       
        public function 
    onEnable(){
            
    $this->getLogger()->info(TextFormat::BlUE."PermList 1.0.4.5A, make sure you always update it to latest version");
            
    $this->saveDefaultConfig();
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            if(
    $this->getConfig()->get("AllEnableStart") == "true"){
                
    $this->allEnabled "true";
            }else{
                
    $this->allEnabled "false";
            }
            
    $this->playersEnabled = array();
            
    $this->getLogger()->info(TextFormat::GREEN."You may now use /perml to get the whole list of perms in your server");
        }
       
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."PermList Deactivated");
        }
       
       
    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
            switch(
    $cmd->getName()){
                case 
    "perml":
                    if (
    $sender->hasPermission("perml.run")){
                        
    $permArray $this->getServer()->getPluginManager()->getPermissions();
                        
    $permName_DescArray NULL;
                        
    $INDEX 0;
                        foreach(
    $permArray as $perm)
                        {
                        
    $permName_DescArray[$INDEX] = $perm->getName();
                        
    $INDEX++;
                        }
                    
    $txtPerm "PermList.txt"
                   
                   
    // $path = $mainClass->getDataFolder() . "PermsList/";
                   // file_put_contents($path, $txtPerm);
                   
                
    $this->getServer()->getLogger()->info(implode(" \n ",$permName_DescArray));
            return 
    true;
        }else{
            
    $sender->sendMessage($this->permMessage);
            return 
    true;
             }
            }
        }
    }
    * YOu may use this code, ill use it for private use...

    So youll see the part where it should write all the perms, cant figure out how to do so..
    but when it try to run the plugin this happens:
    and here is the crash report,

    Attached Files:

  13. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    you forgot
    Code:
    use pocketmine\event\Listener;
  14. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    haha, ill test it. ill tell you more, but i cant figure out to make this plugin write to txt.
    EDIT ill do a tiny code and if it doenst work, ill comeback (for the text writing to txt)
  15. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Still the same but different code line..
  16. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    so this may work for the list being written on a .txt file?
    PHP:
    $path $mainClass->getDataFolder() . "PermsList/list.txt";
    $listPerm implode(" \n ",$permName_DescArray));
    file_put_contents($path$listPerm);
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    "\n" and " \n " are different.
    PocketKiller likes this.
  18. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    namespace missing...
  19. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    You are like a php ninja! spotting the smallest thing! xD
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The spaces look really ugly to me ;)

Share This Page

Advertisement