I/O Help :'(

Discussion in 'Plugin Development' started by James | Buchanan, Mar 26, 2012.

Thread Status:
Not open for further replies.
  1. Hello forums,

    So, im making a Greylist plugin. I have all the code for allowing/disallowing players to build and join, but i want a file named: "greylist.txt", in that file, i want the names of all the people that are greylisted. Then, when they join, if there name is on the list, they can join and build, if it isnt, they cant.

    Not sure if this was clear enough, but i need an answer ASAP
     
  2. Offline

    CorrieKay

    Code:java
    1. public FileConfiguration getConfig(String player){ // returns a configuration by string (player name) used for grabbing offline player configs
    2. FileConfiguration config;
    3. File file = new File(instance.getDataFolder()+"\\players\\"+player+".yml");
    4. if(file.exists()){
    5. config = YamlConfiguration.loadConfiguration(file);
    6. } else {
    7. config = null;
    8. }
    9. return config;
    10. }


    This is my custom configuration GETTER in one of my plugins (basically an essentials clone but specifically for my server)

    if you dont mind working with Yaml, change the code around, specifically line 3, where it says "instance.getDataFolder()+"\\players\\"+player+".yml"" to say "instance.getDataFold()+"\\greylist.yml"
     
  3. I looked at VoxelSniper's source, and found a scanner for the 'snipers.txt' file. How would i do it like that?
     
  4. Offline

    CorrieKay

    Not sure. Embarrassingly enough, ive only been a developer since november, and ive got niche experience with just java and bukkit, so i havnt really explored much outside the bukkit api :s
     
  5. Ill just keep digging in VS then :p
     
  6. Offline

    kumpelblase2

  7. Offline

    Double0negative

    Code:java
    1.  
    2. HashSet<String>graylist = new HashSet<String>();
    3.  
    4. public void loadGrayList(){
    5. File f = new File(instance.getDataFolder()+"\\graylist.yml");
    6. Scanner s = new Scanner(f);
    7. while(s.hasNext()){
    8. graylist.add(s.next());
    9. }
    10. }
    11.  
    12. public boolean isOnGrayList(Player p){
    13. if(grayList.contains(p.getName()){
    14. return true;
    15. }
    16. return false;
    17. }
    18.  
    19.  
     
    James | Buchanan likes this.
  8. That code worked perfectly! Thank you :)
     
    Double0negative likes this.
  9. Offline

    Double0negative

    Glad to hear :)
     
  10. Mind if i post this in the resources section? i think it could be really usefull :)
     
  11. Offline

    dillyg10

    I would personally recommend using a YAML file, because you can have other options etc in it, plus it's 100% simpler. Still.. this sounds like an interesting plugin, can't wait to see it!
     
  12. Should be done in the next week ;)
     
Thread Status:
Not open for further replies.

Share This Page