Solved Need help debugging please

Discussion in 'Plugin Development' started by TfwMinecraft, Jan 29, 2016.

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

    TfwMinecraft

    For a while, I wanted to stop pearl damage. After a bit of Googling, I found a solution that worked.

    While screwing around on my server, I realized that if you pearl while falling, you will take fall damage depending on how far you fell. I've been trying to fix this bug for days, but can't figure out what to do. Some help would be greatly appreciated. I noticed that it TPs you, then causes you to take fall damage after the event call is over.

    This is what I have currently:

    Code:
    @EventHandler
         public void onEntityDamage(PlayerTeleportEvent e)
         {
            Player p = e.getPlayer();
     
            if (e.getCause() == TeleportCause.ENDER_PEARL)
            {
                e.setCancelled(true);
    
                p.teleport(e.getTo());
            }
         }
     
    Last edited: Jan 29, 2016
  2. Offline

    Zombie_Striker

    @TfwMinecraft
    Check EntiyDamageEvent. If the player has just teleported 5 seconds ago (estimation), and the damage cause from from "SMALL_FALL" or "LARGE_FALL", then set the damage to 0.
     
  3. Offline

    teej107

    Where are you getting those DamageCause's from?

    @TfwMinecraft You registered the event right? What if you teleported the player in a task?
     
  4. Offline

    MarinD99

    Perhaps something like this? You basically want to alleviate the player's damage rate from the fall height. Now, the code that I wrote doesn't provide you with what you desire( for instance, I haven't checked whether the player's teleported by using an ender pearl ), but it gives you a brief premise of what you could do.
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onEntityDamageEvent(final EntityDamageEvent e) {
            if (!(e.getEntity() instanceof Player)) {
                return;
            }
            Player p = (Player) e.getEntity();
            if (e.getCause() == DamageCause.FALL) {
                    //do whatever you'd like here
     
  5. Offline

    TfwMinecraft

    Thanks for the replies, guys.

    I have no idea how to check for things within a given period of time.

    I don't know how to create tasks. I tried Googling them, but I have no idea how to create one for this matter. Part of the reason I made this thread was I thought someone might be able to help me with that.

    I tried creating a HashMap to store the name while pearling, then checking if they took fall damage while pearling. The only problem is, I don't know how to remove the name after a given period of time. Anyone can avoid fall damage while in the HashMap.

    Thanks again for helping, everyone.
     
  6. Offline

    MarinD99

    @TfwMinecraft You could create a runnable and after a certain period of time just do map.remove(values);
     
  7. Offline

    TfwMinecraft

    Thanks, but I just fixed it.

    Made it store the start time, then compared it to the end time. If it was less than 2, I set the damage to 0. Otherwise, I would remove the name if it was normal fall damage.

    Should work for now, I'll bump this thread if my debugging process finds something new related to this Otherwise, it's solved.

    Thanks everyone who commented.
     
Thread Status:
Not open for further replies.

Share This Page