Plugin Help Printing multiple lines drawn from a config.yml or a .txt file

Discussion in 'Plugin Help/Development/Requests' started by cheekycharlie101, Jul 5, 2015.

Thread Status:
Not open for further replies.
  1. Ok, I have a plugin that when /donate <rank> is run, it displays info about that current rank.
    example code is here: http://pastebin.com/r7ZUE3aU
    config is here: http://pastebin.com/gQ96rU40

    when /donate donator is run, it outputs the config into a table like so: [line1, line2]
    My question is, how would I go about getting the plugin to print this on mutiple lines but only using one string in the config. So the "donator" string in the config contains multiple lines. If this is not possible what about using a .txt file to hold the information, like the essentials plugin does with its /rules command. I had a look at the essentials source but it seems they use their own text formatting api to deal with this so I didn't really learn anything from it.
     
  2. Offline

    BladeFireTurtle

    Load the messages from the config as a stringlist then get the length of this list and loop through each index, sending the player a message each time.
     
  3. Errr, I'm knew to programming in java, can you give me an example of what that would look like? Thanks:)
     
  4. Offline

    BladeFireTurtle

    Well first of all, it has be said time and time again that you should really know Java before trying to program Bukkit plugins. Without a good knowledge of Java you will run into problems during every aspect of plugin development and people on these forums are not here to answer questions relating to basic Java knowledge but rather the Bukkit API.

    A quick and dirty way to do what you want to do would be this:
    Code:
    for (int i = 0; i< this.getConfig().getStringList("donator").size(); i++){
        sender.sendMessage(this.getConfig().getStringList("donator").get(i));
    }
    This loop starts at i=0 and counts its way up to the value just before the size of the list. (This is because the indices start as 0 not 1). Each time it counts up (i++) it sends the message that's located in the config list at the current index i. Also note the 'this' before getConfig() is the Main class, if this code is run from a class other than Main you need to pass it the main class.

    Read http://www.tutorialspoint.com/java/java_loop_control.htm or https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html for more info on for loops in Java.

    Also in theory the code I gave you would require the plugin to read from the file each time the command is executed which is a slow way to do it. Instead, in the on_Enable(), save this.getConfig().getStringList("donator") to a list that you initialized in the plugin and then get the messages from this list just like I did above with the this.getConfig().getStringList("donator").
     
  5. Thankyou for the help. And as for knowing basic java, The reason I jumped straight into bukkit plugins is because I'm not knew to programming in general. I already understand things like variables, data types, for loops, while loops and statements so i figured learning java wouldn't be too hard. Once I've learnt the syntax of java any issues I get will hopefully be from the bukkit api. Thanks again for your help.
     
Thread Status:
Not open for further replies.

Share This Page