How do I make this piece of code recognise a text file?

Discussion in 'Plugin Development' started by Viralcraftowner, Apr 3, 2017.

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

    Viralcraftowner

    I'm making a plugin that does loads of different stuff, but right now i'm trying to make it :
    When a player joins, put said players name into a string.
    Print that string into a new list ina yml file which is called playerwarnings.yml

    I don't want the plugin to generate a new yml file but rather use an existing one, so all players names are in one file. Basically I have another piece of code that adds a warning to a player when they say or do something stupid, but I have no way of storing how many warnings each player has, hence why i'm adding this.

    [​IMG]
    Here's what i'm trying to do. I have no idea how to get it to recognise my playerwarnings.yml so it can start printing names. I made other pieces of code able to use the config.yml and plugin.yml using the bukkitAPI method so I have no idea how to do it without bukkit. How the hell do I do this?
    The error its giving me just says it can't find playerwarnings.yml (Because i've written the code wrong)

    I'd appreciate a decent explanation, i'm really new to this and I need to learn how to do this, but if people say " yeah just put X in Y and then split the atoms of the sun and transmog them into a new universe" i'll have absolutley no clue what your talking about.

    How do I do this? Thanks for any replies!
     
  2. Offline

    Zombie_Striker

  3. Offline

    Viralcraftowner

  4. Offline

    Zombie_Striker

    @Viralcraftowner
    Exaggerations really don't help in this situation. Post your code and the errors you receive.
     
  5. Offline

    Viralcraftowner

    I've deleted the code now because for the past 3 hours i've been trying to make sense of loads of different methods. I really have no idea where to start with this, all I did was type the code into random places and that's why I got 50000 errors.
    I can't find a single tutorial that actually has a relativity simple tutorial that is understandable to anyone who doesn't have extensive knowledge of Java / Bukkit.

    I don't know where to start. In the website you linked, within the first two sentences i'm lost. The first sentence that applies to me is :

    'If for whatever reason you need another configuration file, you can use YamlConfiguration to make a new one.'

    Okay, that's fine, YamlConfiguration is a method, I understand that.

    'This reads the file data.yml from your data folder, and returns a FileConfiguration. If the file does not exist, the FileConfiguration is empty. If you need a pre-made FileConfiguration to be used, you can instead use an InputStream.'

    .. What? I don't have a Data.yml. Does it want me to make one? 'If the file does not exist, the file configuration is empty' ... is that a trick statement? I don't understand what it means by "the file configuration is empty ' . It hasn't even specified what a file configuration is! It then starts talking about InputSTream, despite the fact InputStream isn't mentioned anywhere previously, and therefore I have no idea what it is.

    Is there some kind of simpler tutorial that explains it in terms a noob can understand?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Viralcraftowner If no file is found, config is empty.
    If file is found, config will be according to that file.
    The Data.yml can be changed in your yml file.
     
  7. Offline

    Zombie_Striker

    This is a problem. You Need to know Java before working on bukkit or else you run into problems like this. If you understand Java, you should be able to understand the logic behind that second sentence and what the InputStream object is.

    If you have not learned Java yet, or only know Java through bukkit, please pick a tutorial from the following link and take some time to understand the language you are writing in. It should not take long to finish whichever tutorial you choose.
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/

    Back on topic:
    Basically, the data.yml is the name of config file you want to load. You can change it to whatever file you need. When you call loadConfiguration, it creates a new FileConfiguration object, which is the exact same thing that getConfig returns, but for this other config file. If you have ever done anything with getConfig(), you can transfer the same lines of code to this object.

    Also, if the files does not exist, loading it will return an empty config. Saving it will create a new file.
     
Thread Status:
Not open for further replies.

Share This Page