N00b Question - Long Returning 0 From Config

Discussion in 'Plugin Development' started by TheHandfish, Aug 5, 2014.

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

    TheHandfish

    Hi,

    I've been having a problem with this code of mine. It's supposed to fetch a value from my config and add it to the current time, then format that as a finish time.

    To debug, I tried:

    Code:
                                p.sendMessage("Is there such a path? " + plugin.getConfig().contains("BuildSites." + args[1].toLowerCase() + ".Time"));
    That returns true, so this must mean there is a path called "BuildSites.(site name).Time" in the config.

    Then I tried:

    Code:
                                p.sendMessage(Main.Prefix + "TIME: " + args[1].toLowerCase() + " " + plugin.getConfig().getLong("BuildSites." + args[1].toLowerCase() + ".Time") + "Site built. Your building will be completed on: §a" + form);
    But in front of "TIME:" I see the name of the second argument (expected outcome) and then "0". It couldn't possibly be "0", though, because this is my config:

    Code:
    BuildSites:
      Prefs:
        Pasting:
          Offset:
            X: 2
            Y: 2
            Z: 2
      Names:
      - house
      - lavafountain
      - premium
      house:
        Time: ’3600000’
      lavafountain:
        Time: ’3600000'
      premium:
        Time: ’3600000’
    
    "Time" is clearly 36,000,000 (milliseconds, which adds up to 1hr). How is this possible? The path is there, but when I access it, it keeps coming up as "0" when it should be coming up as"36000000". Before you say it's the ''s, I'm pretty sure the delimiters aren't the problem since I've used those in countless other occasions and they've worked fine.
    Thank you for the help. :)

    UPDATE: WOW, I am a noob. The delimiters were the problem. o_o But why? I guess I'll have to access it as a string, delete the ''s, then make it into a Long.
     
  2. Offline

    xTigerRebornx

    TheHandfish The ''s make them Strings, making them the problem. You are calling getLong(), which will return 0 if the object grabbed isn't an instanceof Number, and as a String isn't a Number, it returns 0.
     
  3. Offline

    Flamedek

    TheHandfish Maybe you dont have to fetch it as a String, just remove the ' symbols. And when setting values make sure to set it as a number, not as a String
     
  4. Offline

    TheHandfish

    Yeah, the problem was how I was storing the numbers in the first place. x_x Thanks for the help.
     
Thread Status:
Not open for further replies.

Share This Page