Double Jump Invincibility

Discussion in 'Plugin Development' started by chasertw123, Mar 22, 2014.

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

    chasertw123

    So I made this simple double jump plugin; but I am having a problem then when people double jump the become invincible from taking damage from another player. This is a problem cause this plugin is for a kit pvp server. I am having a hard time figuring out what the problem is. If anyone has an idea feel free to post!

    Here is the soruce code:
    Code:java
    1. package me.chasertw123.kitpvp.listeners;
    2.  
    3. import me.chasertw123.kitpvp.KitPvP;
    4.  
    5. import org.bukkit.GameMode;
    6. import org.bukkit.Material;
    7. import org.bukkit.Sound;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.EntityDamageEvent;
    12. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    13. import org.bukkit.event.player.PlayerMoveEvent;
    14. import org.bukkit.event.player.PlayerToggleFlightEvent;
    15.  
    16. public class DoubleJumpListener implements Listener {
    17.  
    18. @SuppressWarnings("unused")
    19. private KitPvP plugin;
    20.  
    21. public DoubleJumpListener(KitPvP plugin) {this.plugin = plugin;}
    22.  
    23. @EventHandler
    24. public void DoubleJump(PlayerToggleFlightEvent e) {
    25. Player p = e.getPlayer();
    26.  
    27. if (p.getGameMode() == GameMode.CREATIVE) return;
    28.  
    29. e.setCancelled(true);
    30. p.setAllowFlight(false);
    31. p.setFlying(false);
    32. p.setVelocity(p.getLocation().getDirection().multiply(1).setY(0.75));
    33. p.playSound(p.getLocation(), Sound.ENDERDRAGON_WINGS, 10, 10);
    34. }
    35.  
    36. @EventHandler
    37. public void PlayerMove(PlayerMoveEvent e) {
    38. Player p = e.getPlayer();
    39. if((p.getGameMode() != GameMode.CREATIVE) && (KitPvP.dragon.contains(p.getName()))
    40. && (p.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) && (!p.isFlying()))
    41. p.setAllowFlight(true);
    42. }


    Any input is appreciated! Thanks all!
     
  2. Offline

    The Fancy Whale

    I don't think it is form this code because as far as I can tell none of this effects entity damaging another entity
     
  3. Offline

    chasertw123

    The Fancy Whale
    Something in here has to be causing it because its only after they double they become invincible. Nothing else I have seen cause this.
     
  4. Offline

    Niknea

    chasertw123 It can't be this class, as you didn't edit any damage events in this class, maybe the double jump is causing another class to trigger.
     
  5. Offline

    Konkz

    Perhaps because of the double jump another plugin is like "Ooo, he is 5 blocks above the air. Lets prevent all damage."
     
  6. Offline

    chasertw123

    Konkz Niknea
    The only damage editing that happens is this:

    Code:java
    1. @EventHandler
    2. public void PlayerFall(EntityDamageEvent e) {
    3. if (!(e.getCause() != DamageCause.FALL)) return;
    4.  
    5. if (!(e.getEntity() instanceof Player)) return;
    6. Player p = (Player) e.getEntity();
    7.  
    8. if (!(KitPvP.dragon.contains(p.getName()))) return;
    9.  
    10. e.setCancelled(true);
    11. }


    Also just to let you know that this is also in the same class with the double jump stuff; and if any one has a better way to handle the fall damage from double jump I would love to know about it. Also I have no other plugins other then the other custom plugin I made I that just displays messages.
     
  7. Offline

    The Fancy Whale

  8. Offline

    jthort

    chasertw123 You said you used multiple of the same event, so check all the events for the player fall and toggle flight events and make sure none of them put the player in god mode without checking if it's the correct event
     
  9. Offline

    chasertw123

    Ok so I figured out a way to fix it. Look below for the fix:
    Code:java
    1. @EventHandler
    2. public void DoubleJump(PlayerToggleFlightEvent e) {
    3. Player p = e.getPlayer();
    4.  
    5. if (p.getGameMode() == GameMode.CREATIVE) return;
    6.  
    7. e.setCancelled(true);
    8. p.setAllowFlight(false);
    9. p.setFlying(false);
    10. p.setVelocity(p.getLocation().getDirection().multiply(1).setY(0.75));
    11. p.playSound(p.getLocation(), Sound.ENDERDRAGON_WINGS, 10, 10);
    12. p.damage(0.1); //I added this to pretty much update the player.
    13. }

    Well thanks everyone who helped! :D
     
Thread Status:
Not open for further replies.

Share This Page