Creating a plugin directory|Folder

Discussion in 'Plugin Development' started by Luke_Lax, Sep 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Luke_Lax

    Hello there, my title is pretty self explanatory, how do I create a new folder from my plugin?
    I've seen many threads for creating a new config.yml file but not for a folder. I'm going to use it the same way that essentials creates and uses it's "Userdata" folder that contains, clearly, userdata :p

    In addition to that, how would I go about adding files into that folder with the name of the file as the name of the player and inside the file to be whatever I want?

    I greatly appreciate all help! Thanks in advance :)
     
  2. Offline

    ZeusAllMighty11

    Using Bukkit's 'saveDefaultConfig' file, will create the directory for you.

    To create one yourself:

    Code:
    File f = new File(plugin.getDataFolder() + "/");
    if(!f.exists())
        f.mkdir();
     
  3. Offline

    Luke_Lax

    TheGreenGamerHD I get this error under ".exists":
    "The method exists() is undefined for the type Seekable.File" ?
    Also I assume "f" in that instance would the the file name or no?
     
  4. Offline

    ZeusAllMighty11

    Did you import java.io.File; ?
    .exists() returns if a file is existent (returns true/false)

    f wouldn't be the file name, it'd be a variable for the root directory we're creating
     
  5. Offline

    jayfella

    Java is interesting like that. A directory and a file are both labelled under the "File" object. There is no "Directory" object. I can only assume they did that because they share so many similar attributes.
     
    TheGreenGamerHD likes this.
  6. Offline

    Luke_Lax

    TheGreenGamerHD
    There was no import option for that so I manually added it and I got this:
    "The import java.io.File collides with another import statement"

    Here's a list of all my imports if this helps:
    Code:text
    1.  
    2. import java.io.IOException;
    3. import java.util.HashMap;
    4. import java.util.logging.Logger;
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.craftbukkit.libs.org.ibex.nestedvm.util.Seekable.File;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.plugin.Plugin;
    13. import org.bukkit.plugin.PluginDescriptionFile;
    14. import org.bukkit.plugin.PluginManager;
    15. import org.bukkit.plugin.RegisteredServiceProvider;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17. import net.milkbowl.vault.economy.Economy;
    18. import java.io.File;
    19.  
     
  7. Offline

    jayfella

    remove the import "import org.bukkit.craftbukkit.libs.org.ibex.nestedvm.util.Seekable.File"
     
  8. Offline

    Luke_Lax

    jayfella ha I assumed it was that, not even sure where that was imported from :p

    Anyway I tried starting my test server: "NullPointerException" :( What was that code TheGreenGamerHD supposed to do anyway? I couldn't tell :S I wanted to be able to name it and place it within the existing folder that the config.yml is in
     
  9. Offline

    jayfella

    Luke_Lax
    Code:java
    1.  
    2. File newFolder = new File(plugin.getDataFolder() + File.separator + "newfolder");
    3. File newfile = new File(newFolder + File.separator + "newfile.yml");
    4.  
     
    TheGreenGamerHD likes this.
  10. Offline

    Luke_Lax

    @TheGreatGamerHD
    Sorry to be a noob but how would I use this?
    @jeyfella
    I tried something like:
    Code:java
    1. File newFolder = new File(plugin.getDataFolder() + File.separator + "PlayerAccounts");
    2. if (!(newFolder.exists())) {
    3. new File(plugin.getDataFolder() + File.separator + "PlayerAccounts");
    4. }


    in my onEnable but again I get a "java.lang.NullPointerException" ?

    jayfella

    I managed to get this working:

    Code:java
    1. File dir = new File("PlayerAccounts");
    2. if (!dir.exists()) {
    3. this.logger.info("[" + pdfFile.getName() + "] Could not find your player account folder, Generating it!");
    4. dir.mkdir();
    5. } else {
    6. this.logger.info("[" + pdfFile.getName() + "] Found the PlayerAccounts folder");
    7. }


    but how would I add the new files to that specific folder?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page