int help

Discussion in 'Plugin Development' started by mehboss, Feb 4, 2017.

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

    mehboss

    This is probably a really easy fix..
    BTW this is an item consume event just if case you were wondering..

    PROBLEM:
    Also, I have no errors in console, if my weight is 97 and I eat a food that is 10 weight, it won't check to see if equals up to 100 so it can cancel it and say that I have reached max weight out of 100.

    CODE:
    Code:
                } else {
                   
                    plugin.getConfig().set("Players." + player.getName() + ".Weight", current + amount);
                   
                    if (plugin.getConfig().getInt("Player." + player.getName() + ".Weight") > 100) {
                        plugin.getConfig().set("Players." + player.getName() + ".Weight", "100");
                        player.sendMessage("You have max weight compacity!");
                    }
                    else {
                    player.sendMessage("You ate food! You gained weight :o");
                    plugin.getConfig().set("Players." + player.getName() + ".Weight", current + amount);
    
                    plugin.saveConfig();
                    plugin.reloadConfig();
                    plugin.saveConfig();
                    return;
                    }
     
  2. @mehboss Why do you keep setting it? And you didn't save and reload it, since Bukkit has the cached version only to stop it from breaking you'd need to save and reload. But why set it multiple times and you set to a string not an int in the > 100
     
  3. Offline

    mehboss

    @bwfcwalshy
    First, I add the '10' to the config. I check the new int in the config after the 10 was added. If the new value is greater than 100, I set it to 100 and then give them the max weight compacity message. The else statement runs if the value is not greater than 100 and it goes to add the normal value to the config. It won't work, it acts as if the check to see if it is greater than 100 is not even there and it just lets the player eat to add the 10 to the value which allows it to be greater than the max compacity of 100.

    I put the statement to check if it is greater than 100 because if a player runs (removes 1 from weight every block walked) and they stop when there weight is, lets say 93. When they eat it will add 10 to 93, making it 103 when the max weight compacity is 100.

    UPDATE: I fixed it, it was a typo I made..
    "Player." was supposed to be "Players."
    Surprised there was no null error.. I will test it soon..
     
    Last edited: Feb 5, 2017
Thread Status:
Not open for further replies.

Share This Page