Setting Integers

Discussion in 'Plugin Development' started by nggmc, Aug 14, 2012.

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

    nggmc

    SOLVED
     
  2. Offline

    MarkusE.s.

    getConfig().set(PATH, VALUE);
     
  3. Offline

    tr4st

    You've created an integer called jackpot and putted him in to an method where an String argument is expected.
    The method getConfig().set() expects to get and String as first argument and an Object as second.
     
  4. Offline

    nggmc

    Whoops, I made that code to try and counter my problem.

    Code:
                            getConfig().set("Jackpot", args[1]);
    
    Yay it works.. When it's called upon as a string but if I attempt to p.sendmessage(getcf.getInt("Jackpot")); it doesn't remember it as the adjusted string it remembers it as the deafult integer. Get @ me?
     
  5. You need to save the config to apply the changes between server restarts... but if it's in the same session, it should work...

    I don't know what the problem is like this, you should post the surrounding code or entire class where you set and retrieve the config value.

    Hmm, are you getting it in a diferent class than the class you're setting it in ?
     
  6. Offline

    nggmc

    I think I know what I've done wrong but done have access to my project yet. No help is required past this point. I will edit this if I was wrong and still need help. Thanks!

    Nope it didn't work. I think these may be useful..

    Code:
                        }
                        else if(args[0].equalsIgnoreCase("setjackpot")){
                            if(player.hasPermission("lotto.admin")){
                            getConfig().set("Jackpot", args[1]);
                            saveConfig();
                            player.sendMessage(ChatColor.YELLOW + "Jackpot set to " + args[1]);
                        }
                        }
                    else if(args[0].equalsIgnoreCase("setfare")){
                            if(player.hasPermission("lotto.admin")){
                            getConfig().set("TicketFare", args[1]);
                            saveConfig();
                            player.sendMessage(ChatColor.YELLOW + "Ticket fare set to " + args[1]);
                            }
                            }
     
                        else if(args[0].equalsIgnoreCase("jackpot")){
                            if(player.hasPermission("lotto.user") || player.hasPermission("lotto.admin")){
                                if(getConfig().getString("LottoEnabled") == "false") {
                                    player.sendMessage(ChatColor.RED + "The lotto has not started yet!");
                                }
                               
     
    else if(getConfig().getString("LottoEnabled") == "true"){
                                    player.sendMessage(ChatColor.YELLOW + "The jackpot is: " + jackpot + " " + econ.currencyNamePlural());
                                    player.sendMessage(ChatColor.YELLOW + "The ticket fare is: " + fare + " " + econ.currencyNamePlural());
                                    }
    Heres what happens...
    [​IMG]

    Just because I don't think I explain it very well ;P

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  7. I don't get much from the picture... you've got jackpot set to 1000 then you set it to 5 ? I don't see where you re-check it and where the problem is.
     
  8. Offline

    nggmc

    I set the jackpot to 5. But it stays as 1000. As it is called upon with getInt. But if I were to call it using getString. It would print 5. So is there a way I can set an integer and it would save accordingly.
     
  9. You're setting it after you're seeing it... like I said, you're not printing it again after you've set it so how do you know it's still 1000 ? You expect the previous message to change itself or what ?
     
  10. Offline

    nggmc

    OH! Sorry I should've made this more open. Notice the [x1] at the end of the chat. That means the line was repeated so its a bit annoying but what it means is nothing changed. Its a plugin called SuckChat I was using to test if it allowed prefix's with the latest bukkit RB. Anyhow after I set the jackpot and I attempt to look at the jackpot it will print the first message rather than the modified 1.
     
  11. That's unreliable testing because you're relying on another plugin's proper functionality.... you should print the values in the server console OR disable that plugin while testing :}

    But regardless, I noticed something...
    Code:
                                    player.sendMessage(ChatColor.YELLOW + "The jackpot is: " + jackpot + " " + econ.currencyNamePlural());
                                    player.sendMessage(ChatColor.YELLOW + "The ticket fare is: " + fare + " " + econ.currencyNamePlural());
    You're not actually getting the values from the config, you're getting them from a variable... are you updating that value ? Because I'm not seing it.
    Just replace jackpot and fare from the messages with getConfig().getString("node") with the proper node and it should display the new values :)
     
  12. Offline

    nggmc

    Yes I know that works. But I need it as an integer otherwise...
    Code:
    EconomyResponse r = econ.withdrawPlayer(player.getName(), getConfig().getInt("TicketFare"));
       //AND
    econ.depositPlayer(getConfig().getString("Ticket" + getConfig().getString("WinningNumber")), jackpot);
                     
    Will not work. As they NEED to be integers.
     
  13. Ehh... what ???
    I was saying you should check jackpot and fare variables, where they're set...
    Or you can just get the values directly in the messaegs:
    Code:
    player.sendMessage(ChatColor.YELLOW + "The jackpot is: " + getConfig().getInt("Jackpot") + " " + econ.currencyNamePlural());
    player.sendMessage(ChatColor.YELLOW + "The ticket fare is: " + getConfig().getInt("TicketFare") + " " + econ.currencyNamePlural());
    But I notice you use the "jackpot" variable again... I asked you where do you update its value ? Because when you set the jackpot you only update the one from getConfig(), the jackpot variable remains the same.
     
  14. Offline

    nggmc

    Either way. I fixed the problem with a different solution but I would like to know how to update the the value anyway :). Sorry for not looking through JavaDocs I tried but I wasn't able to find anything of that nature.
     
  15. Offline

    jacklin213

    Maybe your looking for this?
    String value = args[1]
    Int I = Interger.parseInt(value);
     
  16. nggmc
    You just don't get it... show the entire class and I'll show you what's wrong with the setting of the value, because I don't know where jackpot variable is defined and I don't know where (if it even is) updated.
     
  17. Offline

    nggmc

    It's not like that. Here try it yourself use getConfig().set then use getConfig().getInt
    I cannot use getConfig().getString as mentioned it would ruin the main purpose of the .set
    You cannot set an integer. I will upload my whole class tommorow morning.
     
  18. Yes you can use it like that, you just didn't make sure it returned an actual value, dodgy code :}

    I've just tested what you said, I set a "Test: 100" in my config, added this to my command:
    Code:
    System.out.print("Test = " + getConfig().getInt("Test"));
    
    getConfig().set("Test", 1);
    
    System.out.print("Test = " + getConfig().getInt("Test"));
    And guess what:
     
  19. Offline

    travja

    Digi
    He is setting with an arg, you are setting with an actual integer. What he needs to do is this:
    String s = args[1];
    int i = Integer.parseInt(s);
    getConfig().set("Jackpot", i);
    saveConfig();

    That will make it an integer and input it into the config as an int instead of a String, and because of that, it will not have the quotes around it. Trust me, I was messing around with this stuff yesterday and that's what I got to work.
     
  20. travja
    Ah yes, that makes more sense now :}
     
  21. Offline

    jacklin213

    Basically what I was saying Lol I just didn't say the set part cause he already knows how
     
  22. Offline

    nggmc

    SOLVED! :)
    Thank You everyone for your help.
     
  23. Offline

    jacklin213

    ^ which is what i said T_T
     
  24. Offline

    nggmc

    Ow.. Sorry just realized. Anyway you deserve some acknowledgement as well :).

    Anyway none of those actually worked they would give me
    Code:
    2012-08-17 16:30:07 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'lotto' in plugin MCLotto v3.2
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:492)
        at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:878)
        at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:825)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:807)
        at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:281)
        at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
        at net.minecraft.server.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:583)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
        at me.pineabe.modernmc.MineCraftLotto.onCommand(MineCraftLotto.java:69)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 15 more
    But I stopped using the variable and instead I did..
    Code:
    getConfig().set("Jackpot", Integer.parseInt(args[1]));
    And it worked like a charm.
     
    liamsuksu1 likes this.
  25. Offline

    jacklin213

    thats basicly the same thing except u didnt use a variable like this

    Sting value = [args1] ;
    int jackpot = Integer.parseInt(value);
    getConfig().set("Jackpot", jackpot);
     
  26. Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at me.pineabe.modernmc.MineCraftLotto.onCommand(MineCraftLotto.java:69)

    You're calling an index from an array that doesn't exist.

    args[1] is the 2nd argument, if you type the command without arguments or with only the 1st argument, the 2nd won't exist so you'll have that error.
    You need to check if args.length has the argument... it's 1 larger than the offset you can use, so if(args.length > 1) you can use lengh 1 because it's got 2 or more elements in it.
     
  27. Offline

    jacklin213

    im pretty sure he had that hum maybe not
     
Thread Status:
Not open for further replies.

Share This Page