Quick maths.

Discussion in 'Spigot Plugin Development' started by Marido, Jun 14, 2018.

  1. Hello, developers.

    I've a small issue, I want to set the player's XP floatbar (not level) to the countdown progess.
    The issue is that it won't work with:
    Code (Text):
    player.setExp(startcountdown / 100 * currentcountdown);
    Because the setExp is a float, and the maximum for that is 1.0. But how do I divide it then? Since dividing by 1.0 brings you nothing back lol.

    (dont mind the 1000 typo's, just typed it real quick)
  2. You divide the current by the max amount of time. Eg a countdown of 5 seconds. Two seconds later 3 seconds will be remaining

    The remaining time as a float will be 3/5
  3. It keeps being '0' on the exp bar, weird issue.
  4. You're probably doing integer division, while you want to do float (or double) division.
  5. And how would that look like? I don't use math often in plugins.
  6. Just cast integer values to a float like so

    • Winner Winner x 1
  7. Now the exp bar is just full all the time. Here's my code.

    I feel so dumb, it was correct all the time. It was just an another class overriding my exp level. Ty for the help.