help with falling

Discussion in 'Plugin Development' started by josha28, Aug 16, 2017.

Thread Status:
Not open for further replies.
  1. How can i check if a player is falling
     
  2. Online

    timtower Administrator Administrator Moderator

    @josha28 Checking Player#getVelocity() and Player#isOnGround()
     
  3. ? public void OnFall(player????? e)
     
  4. Online

    timtower Administrator Administrator Moderator

    @josha28 PlayerMoveEvent or BukkitTask
     
  5. oke but how can i make it so when a player is falling get his health and when he falls on the ground get his health
     
  6. Are you trying to cancel the fall damage?
     
  7. Online

    timtower Administrator Administrator Moderator

  8. Everything can be found in the Bukkit Documentation. Spoon feeding doesn't help you advance your knowledge of Java or Bukkit. Follow that link that timtower sent you and you can find everything you want on there :)
     
  9. i know how to get the entitydamage event
    Code:
        @EventHandler
        public void onFall(PlayerMoveEvent e) {
            public void onFall(EntityDamageEvent e) {
                Player player = (Player) e.getEntity();
                double beforehealth = player.getHealth();
                if (e.getCause().equals(DamageCause.FALL)) {
                    double afterhealth = player.getHealth();
                    if (afterhealth == beforehealth) {
                        player.sendMessage("Health:" + beforehealth + afterhealth);
                    }
                }
            }
        }
     
  10. Online

    timtower Administrator Administrator Moderator

    @josha28 Couple things:
    1. That won't compile, you can't put a function in a function.
    2. Entity is not always a player.
    3. Enums are compared with ==
     
  11. but how can i make it work
     
  12. Online

    timtower Administrator Administrator Moderator

    @josha28 You remove the PlayerMoveEvent, you check if the entity is a player before you cast, you change the enum check to use ==
     
  13. Online

    timtower Administrator Administrator Moderator

    @josha28 Make sure that you don't have nested methods.
    Lets start with that.
     
  14. can you just rerite it?? i don't get it to work
     
  15. Online

    timtower Administrator Administrator Moderator

  16. Code:
        @EventHandler
        public void onFall(EntityDamageEvent e) {
            Player player = (Player) e.getEntity();
            double beforehealth = player.getHealth();
            if (e.getCause().equals(DamageCause.FALL)) {
                double afterhealth = player.getHealth();
                if (afterhealth == beforehealth) {
                    player.sendMessage("Health:" + beforehealth + afterhealth);
                }
            }
        }
    i need to check his health bevore this and after
    how??
     
  17. Online

    timtower Administrator Administrator Moderator

    @josha28 Check if the entity is a Player to begin with.
    The cause should be checked with ==, not with equals.

    But what are you trying to do?
     
  18. just a test
    but i am not a pro at java so i don't know what i need to do
     
  19. Online

    timtower Administrator Administrator Moderator

    @josha28 A test doesn't say a lot, what is the purpose of the test? What are you trying to see?
     
  20. i wan't to get better in java and plugin making so i make plugin for practice
     
  21. Online

    timtower Administrator Administrator Moderator

    @josha28 But every plugin has a goal, something it does, what is the goal of this plugin?
     
  22. to check his health when he is falling and check his health when he took damage
     
  23. Online

    timtower Administrator Administrator Moderator

    @josha28 Then you need to store it for a tick.
    This event gets called before the damage is applied (you can cancel this event)
    And you need to run a task a tick later to get the new health.
     
  24. oke how can you make it better and i can see what i did wrong?
     
  25. Online

    timtower Administrator Administrator Moderator

  26. Online

    timtower Administrator Administrator Moderator

  27. It need to get the player health when he is falling more then 2.5 blocks and when the player took falldamage get the updated healht then those are the same of the last one is 20 notivie someone with the right permission.
    Code:
        public void onFallDamage(EntityDamageEvent e) {
            Player player = (Player) e.getEntity();
            float falldistance = player.getFallDistance();
            player.sendMessage("" + falldistance);
            double bhealth = player.getHealth();
            player.sendMessage("" + bhealth);
            if (player.isOnGround()) {
                player.sendMessage("flying");
                if (falldistance > 2.5f)
                    player.sendMessage("fallen");
                    if (e.getCause() == (DamageCause.FALL)) {
                        double ahealth = player.getHealth();
                        player.sendMessage("Health" + ahealth + bhealth);
                        if (ahealth == bhealth) {
                            player.sendMessage("Health:" + ahealth + " " + bhealth + "HACKER");
                        }
                    }
           
            }
        }
    I hope you can help me
     
  28. Online

    timtower Administrator Administrator Moderator

    @josha28 player#getHealth will be the same throughout the entire function.
    You need to check a tick later if the health changed.
    Not to mention that DamageCause.FALL will only trigger if the falldistance > 3
     
Thread Status:
Not open for further replies.

Share This Page