String for score

Discussion in 'Spigot Plugin Development' started by Nico12, Jan 9, 2020.

  1. Sorry if the title of this thread was not very specific, but I'll get to the point, I need a new score to be created when creating a string in a configuration file. Example:
    Code (Text):

      1: // Here will be the content of the 1st score.    
     - "Hi"
    2: // Here you would have to create another score and obviously here will be its content.
    - "% player_name%"
    I am a person with basic knowledge about java, so first of all I want to make it clear that this I do not want to be a spoon feeding and less, if there is a misunderstanding, that this thread is not intended as a feeding but to learn. Rehitero, I would need to be able to create a score for each string in the configuration file, thanks in advance. :D.
  2. sorry but I don't know if I don't understand you or you don't understand me, I need that for each string that I believe in the configuration file a new Score is created. If for example I create a string called "1" and then create another string called "2", do I need to create 2 Scores on the scoreboard? It is understood? But let me know if I explain myself wrong or do not understand.
  3. Yes, a language barrier does exist.
    What I think you are trying to do is something like:

    Code (Text):
    line1: 'Scoreboard first line'
    line2: 'Scoreboard second line'
    line3: 'Scoreboard third line'
  4. Right! I need that.
  5. I need to do it in a nutshell in a single
    Code (Text):
     board.getScore ("First score, * Here would be the position of the line *);
  6. Then your best option is to loop the config values. A better configuration would be:
    Code (Text):
        line1: 'Line1'
        line2: 'Line2'
    Then, create a score object based on that, so
    Code (Text):

    // Pretty sure line limit is 16 if i remember
    for(int i =0; i<16; i++) {
        // Access using config#getString("line" + i);
  7. Ok, I appreciate your help, as soon as I can try the code I will, your idea seems very convincing
  8. I just tried the code, this is what happens, If there are less than 16 Strings in the configuration it shows the amount of strings that there are
    in scores but throws error
    Code (Text):

    for(int i=0;i<5;i++) {
                    String list = plugin.getConfig().getString(""+i+"");
                        board.set(list, i);
    Code (Text):

    0: 'SKIRIIR'

    1: 'Skere'

    2: 'Skiri'
    Code (Text):

    [19:16:03 WARN]: [Skiri] Task #98 for Skiri v1.0 generated an exception
    java.lang.NullPointerException: null
            at fr.minuskube.netherboard.bukkit.BPlayerBoard.set( ~[?:?]
            at ~[?:?]
            at$ ~[?:?]
            at ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.mainThreadHeartbeat( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C( [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at Source) [?:1.8.0_231]
  9. 1)
    Code (Java):
     String list = plugin.getConfig().getString(""+i+"");
    does not need the trailing space apended. Use:
    Code (Text):
     String list = plugin.getConfig().getString(""+i);
    2) Break down the error. So, we know we got a NullPointerException. Which means whatever we are playing with, is null. The strack trace lists:
    Code (Text):
            at fr.minuskube.netherboard.bukkit.BPlayerBoard.set( ~[?:?]
            at ~[?:?]
    So, if we read in in reverse, we can see that your code, calls BPlayerBoard.set, which is some sort of API im guessing. The api may be broken or outdated. Most IDE's allow for library code to be seen, you could look at that line and make sure you have used to api correctly.
  10. change String list = plugin.getConfig().getString(""+i+"");
    String list = plugin.getConfig().getString(""+i, ""); this says give me i from the config if it doesn't exists then I want "" instead.
  11. Well, take into account what Darwin said, and stop throwing an error but now he adds a Score but basically says nothing because he has "". As for what xXXIMMAMTTHEWXXx said, yes, it is an API but I am using it correctly.
    Here I leave a picture of what happens with that score of more "that says nothing.":