Text File Not Reading Correctly?

Discussion in 'Plugin Development' started by BajanAmerican, Apr 24, 2013.

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

    BajanAmerican

    I do not want any hate because my knowledge for Java is limited, and I have tried troubleshooting this multiple times. I have a text file, "vips.txt", and I had my BufferReader put the lines into an arraylist. Then I put a command checking if the player was in the arraylist. I put my own MC username (BajanAmerican) in the First line of my vips.txt file, and it keeps saying that I am not in the arraylist. Any help? Sorry, I am still considered a beginner :p
    Code:
    public static List<String> vips = new ArrayList<String>();
       
     
        @Override
        public void onDisable() {
            Game.blue.clear();
            Game.red.clear();
            teamPicked.clear();
            vips.clear();
            getServer().getScheduler().cancelTask(gameLoop);
            this.logger.info("DISABLED!");
        }
     
        @Override
        public void onEnable() {
            init();
            getServer().getPluginManager().registerEvents(listener, this);
            loop.start();
            CanStart(Bukkit.getOnlinePlayers().length);
            gameState.setInLobby();
            vips.clear();
            if (!new File("vips.txt").exists()) {
                    try {
                      new File(getDataFolder(), "vips.txt").createNewFile();
                    } catch (IOException e) {
                      e.printStackTrace();
                    }
                  }
            try{
            BufferedReader br = new BufferedReader(new FileReader(new File(getDataFolder(), "vips.txt")));
                  try {
                    String line = br.readLine();
     
                    while (line != null) {
                      vips.add(line);
                    }
                  } finally {
                    br.close();
                  }
                }
                catch (Exception localException1) {
                }
            PluginDescriptionFile pdfFile = this.getDescription();
            logger.info("[" + pdfFile.getName() + "] v" + pdfFile.getVersion()
                    + " Has Been Enabled!");
        }
    Code:
    if(commandLabel.equalsIgnoreCase("vip")){
                          Player player = (Player)sender;
                          if(vips.contains(player.getName())){
                              player.sendMessage("You are a VIP!");
                          }if(!vips.contains(player.getName())){
                              player.sendMessage("You are NOT a VIP!");
                          }
                      }
    Quick note: plugin.yml is fine. It gives me the message that I am NOT a VIP. Thanks for the help!
     
  2. Offline

    kreashenz

    Maybe use a .yml instead of a .txt..
     
  3. Offline

    BajanAmerican

    What's the difference?
     
  4. Offline

    kreashenz

    BajanAmerican Well, I'm not sure, but .yml is MUCH easier to use in these cases. You won't need all that BufferReader and all that, just check if the file exists, then add them to it, with yml. .txt 's are different, because you need to do a bunch of other things with it , and I haven't really worked with the .txts before.
     
  5. Offline

    BajanAmerican

    Anyone else have any suggestions? Trying to just have a plain text file read. Don't really want to use a .yml file because ti is out of my comfort zone. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page