Loop for Bukkit?

Discussion in 'Plugin Development' started by Torrent, Jan 29, 2011.

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

    Torrent

    Hey all.

    I'm currently developing a plugin called 'QuestCraft'.

    But i'm currently confused with one thing in its development; listing the current quests which are active.

    The plugin creates a txt file which stores the name of the Quests once they are created and tracks if they are enabled or disabled (Via command)
    I wish for the plugin to list the current quests in the txt file - like Cmod does when it lists the current cuboids.

    I have been told that to show the quests in the txt file via a command like '/quest list' i would need a loop code.
    I have searched almost everywhere but haven't yielded any results.

    Any help on how to make it list the current quests would be awesome.

    Just note; i'm not an expert in Java. So go easy on me :p

    Thanks in advance.
     

    Attached Files:

  2. Offline

    Samkio

    First create the function list(Player player) in the FileFunctions class.
    Then call it when the player types /quest list etc.
    Then you need to get the first line of the text. Message it to the player.
    Repeat for all the quests. :)
     
  3. Offline

    Mixcoatl

    I would recommend loading your data when the plug-in is initialized and then writing it back to disk when changes are made to it. Not only will that simplify interacting with your objects in code, it will also make your code significantly faster.
    Barring that, you can get the files in a directory using one of the listFiles methods of the File class.
    Code:
    // Get the files in the directory.
    File[] fileList = new File(directory).listFiles();
    
    // Iterate over the list of files.
    for (File file: fileList) {
        // Do something to each file.
        doSomething(file);
    }
     
Thread Status:
Not open for further replies.

Share This Page