{Unsolved}Setting player level as a double

Discussion in 'Plugin Development' started by AndrewAnderVille, Oct 10, 2012.

Thread Status:
Not open for further replies.
  1. I know you can set a player's level to an int but I want to be able to set it to a double. Is there anyway to do this ?
  2. Offline


    1. double level = 1.5d;
    2. player.setLevel((int)level); //set the level to the integer part
    3. player.setExp((float)(level % 1d)); //set the experience towards next level to the fractional part
  3. Offline


    Well, why not use the experience bar to store the fractional part? It's already a float - all you need is to give it a value between 0 - 1. It shouldn't be that difficult with getExp(), setExp() and setLevel(), although you probably should update setTotalExperience(). Or you can use a library.

    Essentially, setExp() updates the experience bar, setLevel() updates the level and setTotalExperience() updates an internal counter that is not directly visible, but is used by the enchanting system and the server when it determines whether or not to update the experience bar.

    Alternatively, you could store the level in a HashMap.
  4. I don't need the setExp.... Also I already tried casting the double to an int but it just gets rid of the decimals

    Also I'm already using the Expbar as a timer

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 29, 2016
  5. Offline

    Sagacious_Zed Bukkit Docs

    Minecraft only understands levels as integer, i.e. you can't be level 3.14159
  6. Dam... I guess I'll just do without it D:
Thread Status:
Not open for further replies.

Share This Page