Discussion in 'Plugin Development' started by knoxcorner, Nov 5, 2011.

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


    Okay, so for one of my plugins I'm trying to get it to read from a text file where lines that start with "//" are ignored, ";" indicate that it is a world, and "*" indicates the end of the list. Here's the text file it will read from:

    //Any world names found in this file will be excluded from the backup of WorldSaver
    //There should only be lines that start with a ';' followed by the name of the world, '//' to ignore what is on that line,
    //or '*' to mark the end of the list. If it starts with anything else or is an empty line (highlight to see), an error will be returned
    //To exclude a world, type it's name EXACTLY as it is in the folder and start with a ';'
    //At the end of the list, put  a '*' on the next line
    //You may now put world names, do not skip ANY lines
    //There should be nothing past this. If there is, it will not be read.
    and here is the code to do so:
    1. if (excludeworlds.exists() == true) {
    2. try {
    3. BufferedReader exwis = new BufferedReader(new FileReader(excludeworlds));
    4. Boolean finished = false;
    5. int tempint4 = 0;
    6. String tempstring = "";
    7. while (!finished) {
    8. tempstring = exwis.readLine();
    9. if (tempstring.startsWith("//")) {}
    10. else if (tempstring.startsWith(";")) {worldlist[tempint4] = tempstring.replaceAll(";", ""); tempint4++;}
    11. else if (tempstring.startsWith("*")) {printWorlds(); finished = true;}
    12. }
    15. } catch (IOException ioe) {System.out.println("[WorldSaver] Caught IOException " + ioe + " while trying to write exludeworlds");
    16. }

    It is returning the NullPointerException error on the "else if (tempstring.startsWith(";"))..."
    Any help is appreciated, thanks.
  2. Offline


    Why are you making your life so complicated? You don't need to create a new file format... Bukkit comes with YAML support integrated, they even supply they're own API. I know there's a tutorial on it in the Resources sub forum for this forum. I suggest you start there.

    Edit: here's the link:

    Here's a example of YAML file for your plugin:

    ##Comments here
    ##And why not here?
  3. You are trying to read lines from the file forever, without checking if the file ended, in which case readLine() will return null (hence the NPE).

    Add this before your checks:
    if(tempstring == null)
    Also, replaceAll is probably not what you are looking for. It does the same as "replace", but with regular expressions (google that if you wanna know what that is). I don't think you want that, since you use fixed chars. "replace" will actually replace all, methods are named a bit crappy there.
  4. Offline


    @DDoS I tried using it, but get the following error:

    WorldSaver v1.3 (Is it up to date?): org.bukkit.plugin.Plugin.getConfig()Lorg/bukkit/configuration/file/FileConfiguration;
    java.lang.NoSuchMethodError: org.bukkit.plugin.Plugin.getConfig()Lorg/bukkit/configuration/file/FileConfiguration;
    at servm.knoxcorner.worldsaver.worldSaver.loadConfiguration(
    at servm.knoxcorner.worldsaver.worldSaver.onEnable(
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(
    at net.minecraft.server.MinecraftServer.e(
    at net.minecraft.server.MinecraftServer.a(
    at net.minecraft.server.MinecraftServer.init(
    with this code
    1. templist = worldsaver.getConfig().getList("WorldSaver.Exclude_Worlds");
  5. Offline

    Sagacious_Zed Bukkit Docs

    What version Craftbukkit do you have, probably needs an update.
  6. Offline


    @Sagacious_Zed EDIT:
    *Facepalm*, I had updated the Library but not the server I tested on.
Thread Status:
Not open for further replies.

Share This Page