Solved Jump effect without fall damage

Discussion in 'Plugin Development' started by Tomass, Aug 20, 2014.

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

    Tomass

    Hello guys,

    I want fix one issue - when player jumping with Jump 3 Effect, and when he lands he takes fall damage. I want, that players no longer will take damage while jumping.

    P.S admin (OPs) not take damage while jumping!

    Thanks! Sorry for my bad english.
     
  2. Offline

    Aqua

    Listen for the PlayerDamageEvent and check if DamageCause is Falldamage.
    If it is; cancel the event.

    To make it only do this when having jump potion also check if the player has the Jump potion effect.

    Tomass
    Forgot to tahg

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
    hintss and Tomass like this.
  3. well that's difficultly, because you cant exactly tell if a player jumped or if he fall down somewhere. there is an event for falldamage, isn't it? you could get the player who will get falldamage, look if he has the jump 3 effect, and if so, reduce the falldamage about the damage you get if you get falldamage from jump 3 effect. so if he jumps down in a hole or something, he still will get damage, but not the damage which is caused by his jumpheigh.
    if you do this and he jumps down in a hole which is as high as he would jump with jump 3 effect, he wont get damaged. thats the only stupid thing if you do it like this.
    or you choose to set a jump flag, but this would be much work and could be very buggy
     
  4. Aqua You can edit your post to put the tag in and it'll send them the alert all the same :)
     
    Aqua likes this.
  5. Aqua Tomass in my first post you can read why thats not totally correct, but the easiest way
     
  6. Offline

    Funergy

    First your English is not bad!

    and the reason why admins ops don't take damage while jumping is, if you have essentials it can be they did /god or /fly because if you have fly on you won't take fall damage
     
  7. Offline

    Tomass

    Aqua, but I need only while jumping, not always. Because players have always Jump effect...
    Funergy, I don't use Essentials or something like that. If you op, you didn't get the jump damage, but fall damage you getting.
    Shmobi, there are no falldamage events.
     
  8. It's no direct event, but you can do it like Aqua told you. So you know when it is falldamage and you can check if the damage is as high as the damage you get from jump 3 Effect. This are 2 flags which tell you that he jumped. But there is still the very small chance, that the player fall into a hole which makes exactly the same damage as the Jump 3 Effect. But it's a 80% chance to be right.
    Tomass i cant explain why op dont get falldamage. The Server cant know if the player is jumping or falling, because it's clientsided. the client is sending the location the player wants to go to. the client does not send a signal that he pressed space as far as i know
     
    Tomass likes this.
  9. Offline

    Tomass

    Really! Thanks!
     
  10. Offline

    Anrza

    Smartest way might be to getFallDistance, and if the player has jump boost 3, setFallDistance(getFallDistance - x).
    Set x to one or two, depending on which is necessary.
     
  11. Anrza nope, because if he runs down into a hole without jumping he wouldn't get any damage if the damage would be lower than damage from the jump 3 boost. you have to check if he did jump and did only get damage from this. because you want the player to get more falldamage if he was stupid enough to jump with jump 3 boost into a hole. just if he jumps so, that the damage is only from the jump 3 boost he should get damage.
     
  12. Offline

    Anrza


    I wouldn't consider that a problem in many situations, but I guess it's a problem to you.

    You could actually "make" a PlayerJumpEvent, simply use PlayerMoveEvent, check if the player is on the ground and check if the player's velocity has a positive Y.
     
  13. Anrza he can be launched by a explosion or if he gets hit. he can be moved by a piston or step on stairs or halfbricks..... there are to much exceptions. maybe you don't care for such things but a good programmer calls something like this a bug and nothing else!
     
  14. Offline

    Anrza


    Mate, getting pushed by pistons and stepping on stairs still keeps you on the ground and doesn't give you any velocity.
    And there's a heart of damage in difference, at max, and it would only happen if the fallDistance is exactly the right value.

    Yea, a good programmer would call this a bug, and I do too, but there's a line between big problems and small things that people wont notice or care about. I've presented to you the best solution so far. Maybe you should use it and stop whining about it, or come up with your own one?
     
  15. Anrza i already told my own solution before you :O and yes, small things that people wont notice that much, but they will. and if there is any way (like mine) to solve this without those or with less bugs, choose it!
     
  16. Offline

    Anrza

    You're really just overcomplicating, the chance of this even happening is tiny, and no one will give a shit about it.
     
  17. Anrza i'm just asking why you would use a way which includes new bugs if there is another way which is as good as yours and works as fine but without including new bugs? yes they are small and nobody cares about, but your way isn't better than mine, it's equal. Your way does just have more bugs. So even if they are small and whatever, why including them anyway? I don't get your logic :O
     
  18. Offline

    Anrza

    Shmobi Uh... you know, my solution was just like yours, except better, it removes the falling down part, only keeps the explosion and getting hit away bug.
     
  19. Anrza see your bugs:
    1. you check if player jumps up, not if he gets falldamage, so you can't exactly tell if he does not get damage while jumping. like a explosion or he gets hit by an arrow while being in air. what you are doing is
    if(playerJumps()){notHurtAble();}
    2. if you swim in water or lava your method would think that he is jumping. while being in lava he wouldn't get damaged. if you edit your method, that liquid will count as hard ground, your method won't work if the player jumps out of the water/lava
    3. if the player gets launched by arrow/snowball/fireball/explosion/hit/enderdragon/.... idk your method would think he is jumping
    4. if the player has fly mode he can't be damaged while flying up
    5. you have to setUp flags/listener for each player or set flags and handle them
    etc.....
    there are many reasons why you can ask the DAMAGECAUSE!!! because if you try to solve it on your own you must overlook many exceptions. and yes, some of them are small and you can leave them. some of them are not so small. and if there are many there is a high chance that they happen often. then they count again

    you could fix it, but you've to add way to much things to take care of everything. it's slower, it's ugly and it's way more work. Also i don't think you could get it 100% debugged. My method does just has the bug, that you can get falldamage in high of the damage you get through jump3 boost without jumping. this is 1 case which won't happen that often, and if so you can't really fix it.
     
  20. Offline

    Anrza

    Shmobi
    1. You do that BEFORE the player hits the ground. It will trigger if he is blown away by an explosion or hit as well, but that's a minor bug. If you check this and registers the time on which this happened and the velocity, you can make sure that it only triggers the first tick of air-time, and then, when the player hits the ground again, you can see if it happened in a reasonable time after he first jumped, and decrease the damage or cancel it accordingly.

    2. I NEVER said ANYTHING about cancelling damage. What I did say was that you could decrease the distanceFallen, to give less damage.

    3. Correct, but I will tell you why that's not a problem.

    4. Incorrect, I never said anything about cancelling damage. Besides, while flying, your velocity is always 0.

    This is what to do:
    1st step:
    To add some limits to what will be counted as player jumping, you jump around with jump boost 3 and collect values.
    You then write down the highest and lowest velocity you were able to get somewhere. Call them vMax and vMin.

    2nd step:
    You jump around with jump boost 3, and every time you hit the ground, have a plugin tell you your fallDistance.
    Write down highest and lowest value. Call them fMax and fMin

    3rd step:
    Code:java
    1. HashMap<Player, Long> timeOfJump = new HashMap<Player, Long>();
    2. HashMap<Player, Double> oldVelocity = new HashMap<Player, Double>();
    3. @SuppressWarnings("deprecation")
    4. public void onPlayerJumpEvent(PlayerMoveEvent event) {
    5. Player player = event.getPlayer();
    6. PotionEffect pe = new PotionEffect(PotionEffectType.JUMP, whatEverTimeYouPrefer, 3);
    7. if (player.getActivePotionEffects().contains(pe)) {
    8. if (!player.isOnGround()) {
    9. if (player.getVelocity().length() < vMax && player.getVelocity().length() > vMin) {
    10. if (player.getVelocity().length() > oldVelocity.get(player)) {
    11. timeOfJump.put(player, System.currentTimeMillis() + reasonableAmountOfTimeUntilHitGround);
    12. oldVelocity.put(player, player.getVelocity().length());
    13. }
    14. }
    15. }
    16. }
    17. }
    18.  
    19. public void onPlayerHitGroundEvent(EntityDamageEvent event) {
    20. if (event.getEntity() instanceof Player) {
    21. if (event.getCause().equals(FALL)) {
    22. if (timeOfJump.containsKey(player)) {
    23. if (timeOfJump.get(player) > System.currentTimeMillis()) {
    24. if (event.getEntity().getFallDistance() < fMax && event.getEntity().getFallDistance() > fMin) {
    25. event.setDamage(event.getDamage() - 2);
    26. }
    27. }
    28. }
    29. }
    30. }
    31. }


    Now, because fallDistance is a float, it has a lot of decimals and accuracy, meaning that it's quite unlikely that anything else would trigger this.
     
  21. Anrza 2. and 4. yea, you're right. sorry i made a mistake. but if you don't do damage or if you reduce damage you shouldn't is wrong anyway in this situation. i don't knew that velocity is 0 while flying, then lets say he is grabed by a fishing rod. I just see there way to much points where your method doesn't work. Also it's way more work. Also you forgor my fith point. I already told you that i don't think it is a bad or a wrong way. It's just why making your self much work with coding a own method for this which includes some bugs if you can just use the possibilitys which are given from the bukkit api? It's a possible, not bad solution, but it's not worth it.

    But whatever, i don't care which way Tomass is gonna use. I'm tired of discussing with a stubborn head, who does not accept any criticism without getting in ragemode. Btw i use the EntityDamageEvent for the timepoint of damage, so your 1. is wrong. i do it if he hit the ground. Also you should look at one point in your method. If i saw it right, you reduce the damage everytime the player gets falldamage. you just shall reduce it if he does only get it from his jump boost. if he does jump in a hole with jump 3 boost it is his fault and he should not get the damage reduced. you know what i mean? like if he jumps from x1|y1|z1 to x2|y1|z2. then you should cancel the damage. because if you jump down into a hole without jump 3 boost, minecraft does not reduce the damage about the amount of the damage you get from jumping added. simple check you should include :)
     
  22. Offline

    Tomass

    Shmobi, now I use, not very good, but I think that's enough:
    Check if player have a jump effect and:
    Code:
    if (e.getDamage() == 1.1688556671142578 || e.getDamage() == 1.153745174407959) {
              e.setCancelled(true);
          }
    }
     
  23. Offline

    Anrza

    Shmobi Really, stubborn head? Ragemode? Please, I'm no more stubborn than you, and I do accept criticism, I even use it to improve what I have already. I started with EntityDamageEvent and added PlayerMoveEvent as a check to wether he qualifies for having a decrease in fall damage or not.

    I only reduce damage if the player is in the timeOfJump HashMap and then only if it was put there in the last few seconds. A check to wether he does or does not have jump boost 3 is therefore unnecessary. I'm confident enough to say that my code will work without any problems or bugs whatsoever, and that any exceptions will be extremely rare. The only way this is gonna happen is if an explosion happens 4-5 blocks below the player, and even then it's quite unlikely that it will happen.

    If you're gonna say that my code doesn't work, do read it first.

    EDIT: Tomass the thing I wrote will work if you supply the right numbers.
     
  24. Anrza 1. i never said it wont work and i read it, else i couldn't have seen the problems by using your way. 2. You might will get in a conflict with other plugins. if you know it is falldamage and he has the jump 3 boost you are safer. should be included, is just one if case with 2 boolean. i've never met a good programmer who says "that the bug happens is a very small chance, so let's keep with it, that's fine". if you can remove a bug, do it. no matter how small it is. and yes, stubborn head. maybe you improve criticism sometimes, but i am talking about this thread. but fuck it, i'm done with this :p
     
  25. Offline

    ChipDev

    Tldr.
    Cancel damage event if player is OP and cause was fall
    How the heck did this get so long?
     
  26. Offline

    Anrza


    1. "I just see there way to much points where your method doesn't work", you did say it wont work. You said this: " If i saw it right, you reduce the damage everytime the player gets falldamage. ", while my method includes this:
    timeOfJump.put(player, System.currentTimeMillis()+ reasonableAmountOfTimeUntilHitGround);
    and checks:
    if(timeOfJump.containsKey(player)){
    if(timeOfJump.get(player)>System.currentTimeMillis()){

    so excuse me for thinking you didn't read it.

    2. Alright, big deal, add the jump boost 3 check for all I care. It's already in the onPlayerJumpEvent, so it doesn't matter the slightest, but if you really want to slow down the plugin a bit, fine, that's a good idea.

    "i've never met a good programmer who says 'that the bug happens is a very small chance, so let's keep with it, that's fine'"
    Now you have. And let me explain further:
    The onPlayerHitGroundEvent is buggy, as it can be triggered by a lot more than jumping with jump boost 3 and then hitting the ground. I added onPlayerJumpEvent as to see wether the player is or isn't qualified to be affected by onPlayerHitGroundEvent. I'm basically taking a piece of cloth with a big hole in and patching the hole with another piece of cloth with a hole that's a whole lot smaller than the original one. Sure, there are bugs in it, but since it's part of fixing a lot bigger bug, it's fine. While it may not be water-proof, it's at least sand-proof. It IS still possible for it to throw a few false positives, but on the whole, you're gonna get a lot less than you would've gotten without it.
    This last small hole there is, I do not know how to fix. If you have a better idea, please share it, but for now, it's as close to water-proof that we can get.

    ChipDev
    Actually, reread what Tomass(original poster) said. What he want is no fall damage for everyone (including, but not limited to OPs) if they jump with jump boost 3 and hit the ground.
     
    ChipDev likes this.
  27. Offline

    Funergy

    Tomass If he jumps and he has the jump effect you add him to an arraylist.
    then you create a method with a bukkit repeating runnable. if hes on the ground you delete him from the arraylist.

    then you create an event: the EntityDamageEvent then you get the Cause and if it equals to fall damage and he is in the arraylist you cancel the event.

    This will delete the fall damage and when the jump effect lasts in the air you don't take damage

    WARNING: I haven't test this so it will happen if you fall on the ground and it deletes you from the arraylist it still damages you! if this happens you create another method with a delayed scheduler for like 3 seconds and if it ends you delete him from the arraylist.
    And you do one modification to the bukkit repeating runnable in place of you delete him from the arraylist when hes on the ground, you delete that line and change it to the method name of your scheduled delayed task.
     
  28. Offline

    Tomass

  29. Offline

    ChipDev

    Oh.
     
Thread Status:
Not open for further replies.

Share This Page