PlayerExpChangeEvent not working?

Discussion in 'Spigot Plugin Development' started by Vidsify, May 2, 2015.

  1. Hello,

    I received this message form a player today:

    From what he is saying the per permission multiplers are not working but the global one is.

    My plugin is called DoubleYourExperience, it says what it does in the title. In the config the is an option called EnablePermMultipler: <true/false>. This is will allow server owners to give certain ranks/players this permission doubleurexp.multiplier.<int/float>. This will then allow them to receive an exp multipler depending on what permission they have.

    If the option mentioned above is set to false they can enable a server wide multipler so all player get that benefit, but only if they have the permission doubleurexp.allow. This then can be set to work only on some days.

    The problem this player is having is that only the server wide multipler is working. The per permissions one's are not and I cannot see why in my code.

    Could someone help me find out why this is not working.
    Link to GitHub: https://github.com/Vidsify/DoubleYourExperience

    Thanks inadvance, credit will be given if someone can help fix this issue. :)
     
  2. gigosaurus

    Supporter

    Code (Java):

    for (float temp = 0.0F; temp <= 10.0F; temp = (float) (temp + 0.1D)) {
        if (!player.isOp() && player.hasPermission(Perm.MULTIPLIER + temp)) {
            newAmount = (int) (originalAmount * temp);
            found = true;
        }
    }
     
    Perhaps the player has op? If so, that if statement will never be true, and so the player's per permission won't be taken into account.

    Remove the player.isOp() check in the if statements (you have it in multiple places) and add this to your plugin.yml:
    Code (Text):

    permissions:
      doubleurexp.multiplier.*:
        default: false
     
     
    #2 gigosaurus, May 2, 2015
    Last edited: May 2, 2015

  3. I have done that. Can you check to see if I'm missing anything please?
     
  4. gigosaurus

    Supporter

    Oh I was blind to not see this before.

    For reasons I can't quite remember (probably because I've been up all night), adding floating point values together in java sometimes does some weird stuff. Change your for loops to use an int instead, and then calculate from there.

    Code (Java):

    for(int temp = 0; temp <= 100; temp++) {
       if(!player.isOp() && player.hasPermission(Perm.MULTIPLIER + (temp / 10.0))){
            newAmount = (int) (originalAmount * (temp / 10.0));
            found = true;
       }
    }
     
     
  5. @gigosaurus Oh ok. That's handy to know. Shall I swap the code now for what y just posted?
     
  6. gigosaurus

    Supporter

    Assuming I didn't make any mistakes and that you understand what I've actually changed, sure.