Solved Help with disabling fall damage?

Discussion in 'Plugin Development' started by TinyTom38, Apr 19, 2014.

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

    TinyTom38

    Okay so basically i am making a plugin which allows you to double jump but i just cant think how id disable fall damage for only when they jump
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerToggleFlight(PlayerToggleFlightEvent event){
    4. Player player = event.getPlayer();
    5. if(player.getGameMode()==GameMode.CREATIVE)
    6. return;
    7. if(!player.hasPermission(new Permissions().permTTDJ))
    8. return;
    9. event.setCancelled(true);
    10. player.setAllowFlight(false);
    11. player.setFlying(false);
    12. player.setVelocity(player.getLocation().getDirection().multiply(1.5).setY(1));
    13. //need it to remove it for just here//
    14. }
    15.  
    16. @EventHandler
    17. public void onPlayerMove(PlayerMoveEvent event){
    18. Player player = event.getPlayer();
    19. if((player.getGameMode()!=GameMode.CREATIVE)
    20. &&(player.getLocation().subtract(0, 1, 0).getBlock().getType() !=Material.AIR)
    21. &&(!player.isFlying())
    22. &&(player.hasPermission(new Permissions().permTTDJ))){
    23. player.setAllowFlight(true);
    24. }
    25. }
    26.  
     
  2. Offline

    TheMcScavenger

    EntityDamageEvent, get cause, if it's fall damage, cancel it.
     
  3. Offline

    TinyTom38

    Yeah okay ill try this thanks
     
  4. Offline

    Kyorax

    Add them to an ArrayList for like 2 seconds and disable the damage for players on that list by using the EntityDamageEvent.
     
  5. Offline

    TinyTom38

    Okay im new to plugin making and coding so how would i do this?

    Infact it doesnt matter for the reason i am making this i can just disable fall damage for the people with the permission.
    Thanks anyways :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  6. Offline

    MrInspector

    Code:java
    1. @EventHandler
    2. public void onFall(EntityDamageEvent e) {
    3. if (e.getCause() == EntityDamageEvent.DamageCause.FALL) {
    4. e.setCancelled(true);
    5. }
    6. }


    I just made this here, may be missing something.
     
  7. Offline

    coasterman10

    Add players to a Collection when they double jump. When a player takes fall damage, check if they are in the collection. If they are in the collection, cancel the damage, and then remove them from the collection.
     
  8. Offline

    TinyTom38

    Yeah whilst i was making mine i realized that's all entities isn't it? so you need do something like
    Code:java
    1.  
    2. if(event.getEntityType()==EntityType.PLAYER){
    3. //code here
    4. }
    5.  


    Ive got this:
    Code:java
    1.  
    2. @EventHandler
    3. public void onEntityDamage(EntityDamageEvent event){
    4. if(event.getCause() == DamageCause.FALL){
    5. if(event.getEntityType()==EntityType.PLAYER){
    6. Player player = (Player) event.getEntity();
    7. if(player.hasPermission(new Permissions().permTTDJ)){
    8. event.setCancelled(true);
    9. }else{ return; }
    10. }else{ return; }
    11. }else{ return; }
    12. }
    13.  


    As i want it if its a player and if they have permission
     
  9. Offline

    MrInspector

    i'm not sure what you're doing there but

    Code:java
    1. @EventHandler
    2. publicvoid onFall(EntityDamageEvent e){
    3. if(e.getEntity() instanceof Player && e.getCause() == EntityDamageEvent.DamageCause.FALL) {
    4. if(e.getEntity().getPlayer().hasPermission("enter.your.permission") {
    5. e.setCancelled(true);
    6. }
    7. }
    8. }
     
  10. Offline

    Kyorax

    Or use my version:
    Code:java
    1.  
    2. //put this at the top of your code
    3. ArrayList<Player> nofalldmg = new ArrayList<Player>();
    4.  
    5. //put this where the double jump is triggered
    6. nofalldamage.add(p);
    7.  
    8. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    9. public void run() {
    10.  
    11. nofalldmg.remove(p);
    12.  
    13. }, 60); // time in ticks until the player is removed again
    14.  
    15. }
    16. //continue your double jump code...
    17.  
    18.  
    19. //put this where your other listeners are
    20. @EventHandler
    21. public void onFall(EntityDamageEvent event) {
    22.  
    23. Entity e = event.getEntity();
    24. if(e instanceof Player && event.getCause() == EntityDamageEvent.DamageCause.Fall) {
    25.  
    26. Player p = (Player)e;
    27. if(nofalldmg.contains(p)) {
    28. event.setCancelled(true);
    29. }
    30.  
    31. }
    32.  
    33. }
    34.  

    Have fun with it :D
     
Thread Status:
Not open for further replies.

Share This Page