XPFLY PLUGIN FOR 1.12

Discussion in 'Spigot Plugin Help' started by TheIntelloBox, Jun 4, 2017.

  1. Hi ! :D

    I'm searching a XPFLY Plugin for 1.12 please ! :D

    Thanks ! :)
     
  2. Have you tried existing plugins? If they all don't work I may make one if there's enough demand
     
  3. I tested many plugins and they don't work. :(
     
  4. Interesting.. The plugin idea doesn't seem that complicated:
    • /xpfly
    • Allow the player to fly
    • Remove XP every x ticks
    • If the player runs out of xp or does /xpfly again disable flying
    I wonder how the plugins broke.
     
  5. Yes but they don't work. xD So you can do that ?
     
  6. I'll look into it
     
  7. Currently making it :)
     
  8. Fantastic, thanks a lot. :D
     
  9. I finished the plugin except for the part where it removes XP, because I just can't figure out how XP works. Bukkit does not support getting / removing XP. I've tried using https://gist.github.com/RichardB122/8958201b54d90afbc6f0 and that works until I get to 247 XP for some reason.
     
  10. Oh okay, maybe, see the source code of a xp fly plugin ? :D
     
  11. I've decompiled one but the code is very confusing:
    Code (Text):
    if (player.getExp() <= 0.0F){
        player.setLevel(player.getLevel() - 1);
        player.setExp(1.0F);
    }
    player.getExp() <= 0.0F - player.getExp() can never return a value lower than 0.0

    player.setLevel(player.getLevel() - 1) - Subtracts a whole level instead of some XP

    player.setExp(1.0F) - Gives the player free XP (set XP progress to full) so their level goes up one again?
     
  12. Oh... It's strange. So you know how to do or no ?
     
  13. electronicboy

    IRC Staff

    if the players experience is 0 (or less, computers suck at maths), decrement their XP level, and set their exp to full.
    basically, the code is there to decrement the players level, the reason why they set the exp back to full is so that it only actually decrements a single value, otherwise you'd start taking away their levels instead of basically removing their xp
     
    • Like Like x 1
  14. Oh it totally makes sense now! The plugin doesn't remove XP, it removes a certain percentage. This is actually makes sense, because even though XP is harder to get at a higher level it is not worth more. (Take enchanting as an example, it takes 3 levels, whether that's from 30 to 27 or from 500 to 497 doesn't matter). The code is not entirely correct, because in some rare situations it can end up setting the progress to -0.01f. It doesn't make sense that it checks afterwards, because setting the progress to -0.01f will throw an exception and stop code execution.

    Anyways, I get it now, I can continue programming!

    EDIT: Full decompiled code: https://hastebin.com/nusiwajodo.cs
     
  15. electronicboy

    IRC Staff

    comparison of floating point numbers generally means that it's more safer to compare for equality and less than (or more than if you have a ceiling), that verification was only added in fairly recently for setting exp to less than what it should be, before that, there were no checks for the accuracy of that

    that code is also a mess...
     
  16. Yes it is.. My code is like 20 lines and does exactly the same lol.

    I'm finished by the way, just putting it up on github right now :)

    Code (Text):
    @Override
        public void run() {
            for (Player player : Bukkit.getOnlinePlayers()){
                if (Main.XP_FLY_PLAYERS.contains(player.getUniqueId())){
                    //This player is currently flying
                   
                    float currentProgress = player.getExp();
                   
                    if (player.getLevel() == 0 && currentProgress < Main.XP_COST){
                        player.sendMessage(Main.RAN_OUT_OF_XP);
                        Main.XP_FLY_PLAYERS.remove(player.getUniqueId());
                        player.setAllowFlight(false);
                        player.setFlying(false);
                        continue;
                    }
                   
                    float newProgress = currentProgress - Main.XP_COST;
                   
                    if (newProgress < 0){
                        player.setLevel(player.getLevel() - 1);
                        player.setExp(1.0f + newProgress);
                    } else {
                        player.setExp(newProgress);
                    }
                }
            }
        }
     
    • Like Like x 1
  17. I don't see any errors but it's not working in 1.11.2. :c