Accessing files

Discussion in 'Plugin Development' started by mastermustard, Mar 15, 2013.

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

    mastermustard

    So in my plugin I'm making I need to parse a schematic file (which I've done) but to get to that file I don't want to have it generate a folder on start-up in which i manually put the schematic in. How would I (if possible) put a schematic file in my source folder then access it in the code? Basicly how would I locate a .schematic file from the source folder.
     
  2. Offline

    CoderCloud

    Code:java
    1.  
    2. File f = new File(plugin.getDataFolder(), "YourFile.xxx" /*Config would be "config.yml"*/);
    3. String line;
    4. while((line=br.readLine()) != null) {
    5. /** Handle the Filelines here**/
    6. System.out.println("Read line: " + line);
    7. }
    8. br.close();
    9.  
     
  3. Offline

    macguy8

    CoderCloud
    I believe he means from inside the jar, not from the /plugins/<Name> folder

    I'm pretty sure JavaPlugin.getResource("your_schematic.schematic") is what you're looking for.
     
  4. Offline

    CoderCloud

  5. Offline

    macguy8

    CoderCloud
    Are you... Making a reader of the plugin?

    Edit: nvm, couldn't read the white text.
     
  6. Offline

    CoderCloud

    macguy8
    i formated the text better now^^
     
  7. Offline

    mastermustard

    Thanks CoderCloud macguy8

    But I have one question, by handle filelines do you mean my code that parses the schematics??
    Code:java
    1. /** Handle the Filelines here**/
     
  8. Offline

    macguy8

    mastermustard
    Pretty much, the code will get to that point every line in your code. Eg...
    This
    Is
    A
    Test
    Would call that code once for each LINE in the file, either add it to an array list, or do whatever you need to do there (I have no clue how schematic parsing works)
     
  9. Offline

    mastermustard

    macguy8 all im asking is if i put that code on the line not how do i code it
     
  10. Offline

    jtjj222

    In the case of reading shcematics, you wouldn't read it line by line. I haven't checked if this compiles or not, but something like it should work:
    Code:
     
    DataInputStream in = new DataInputStream(plugin.getResource("Schematicfile.schematic");
     
    //use your NBT library to read the root compound tag of the schematic file
     
    br.close();
     
    
     
Thread Status:
Not open for further replies.

Share This Page