Getting the plugins folder

Discussion in 'Plugin Development' started by ZephireNZ, Jan 25, 2013.

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

    ZephireNZ

    I'm trying to access the Essentials player configs (to get ban reasons). This is the code I have currently:
    Code:
    public class EssConfigManager {
     
    private EssBans plugin;
    public EssConfigManager (EssBans plugin) {
    this.plugin = plugin;
    }
     
    public String getEssDir(){
    String pluginDir = plugin.getDataFolder().toString();
    String essDir = pluginDir.replaceAll(plugin.pdfFile.getName() + File.separator, "Essentials" + File.separator);
    plugin.getLogger().info("Ess Directory: " + essDir);
    return essDir;
    }
     
    }
    
    But it returns a NullPointer exception, the important line being:
    java.lang.NullPointerException
    at me.ZephireNZ.EssBans.EssConfigManager.getEssDir(EssConfigManager.java:21)

    Line 21 is "String essDir = pluginDir.replaceAll(plugin.pdfFile.getName() + File.separator, "Essentials" + File.separator);", but I'm unsure as to where the Null is in there.

    So 2 questions:
    1) Why am I getting a NullPointerException, and
    2) Is there any way to make this more compact (ie a method to call that gets the plugin directory)?

    Also, how do I see the 'Code:java' I see around, not just general code? :p
     
  2. Offline

    nisovin

    I expect you can do something like this:

    Code:
    Plugin plugin = Bukkit.getPluginManager().getPlugin("Essentials");
    File essentialsFolder = plugin.getDataFolder();
    
     
  3. Offline

    ZephireNZ

    Ok, that seens a LOT more reasonable, as well as more smart. Thanks! :D

    Also, the code:java bit?

    EDIT: Whoops, derped my original question. What the BBCode tags to do the code:java bit?
     
  4. Offline

    RealDope

    ZephireNZ
    Use [syntax=java obviously with a closing bracket.
     
Thread Status:
Not open for further replies.

Share This Page