Solved When a Player Is In The Air, Stop Him From Falling

Discussion in 'Plugin Development' started by BungeeTheCookie, May 26, 2014.

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

    BungeeTheCookie

    So, when I a player dies, I send him launching into the air. At the end, he starts falling back down. How do you stop the player from falling through the air and toggle fly mode (yes, I know how to toggle fly mode)?
     
  2. Offline

    OHQCraft

    Possible, but may look stupid on laggy players.
     
  3. Offline

    BungeeTheCookie

    I know, I was not asking for advice on whether it would look "good" or not, I was asking how to do it. Thanks for the feedback though.
     
  4. Offline

    Necrodoom

    As far as I recall you'd freeze a dead player the same as you would to an alive one. I may be wrong though.
     
  5. Offline

    BungeeTheCookie

    What do you mean? I am trying to prevent him from falling, not "freeze" him. Also, the player is not dead at all.
     
  6. Offline

    Necrodoom

    You said the player dies in the topic. Also, what you want IS freezing him, you want to make sure the new Y doors is not smaller than current, and if yes, movement.
     
  7. Offline

    BungeeTheCookie

    Im sorry. The player doesn't die. It is cancelled when the damage dealt to it kills him.
     
  8. Offline

    Necrodoom

    So anyway, if you want him to not fall, then either cancel move event upon falling down, or toggle flight. Again, check if new Y coord is smaller than current in move event.
     
  9. Offline

    BungeeTheCookie

    I do not want the player to get stopped from flying every time, only when this code is triggered.

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void createFakeDeath(EntityDamageEvent e){
    3. if(e.getEntity() instanceof Player){
    4. Player p = (Player)e.getEntity();
    5. if(absoluteHealth(p, (int)e.getDamage(), false) <= 0) {
    6. e.setDamage(0);
    7. GameManager.getGame().addSpectator(p);
    8. p.setVelocity(p.getLocation().getDirection().multiply(5));
    9. p.setVelocity(new Vector(p.getVelocity().getX(), 2D, p.getVelocity().getZ()));
    10. p.setAllowFlight(true);
    11. ItemStack[] armorContents = p.getInventory().getArmorContents();
    12. ItemStack[] items = p.getInventory().getContents();
    13. List itemStackContents = Arrays.asList(armorContents, items);
    14. Bukkit.getServer().getPluginManager().callEvent(new PlayerDeathEvent(p, itemStackContents, 0, MessageManager.displayPlayerDeathMessage(p)));
    15. }
    16. }
    17. }
    18.  
     
  10. Offline

    Necrodoom

  11. Offline

    BungeeTheCookie

    So create my own custom event..?

    Can you give me an example...?

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

    xTigerRebornx

    BungeeTheCookie You could add the Player to a List/Set when your code is fired and in the PlayerMoveEvent, apply the falling prevention if they are inside that List/Set
     
  13. Offline

    BungeeTheCookie

    Ok, let me reword what I want. When my thing is called, I want it to force the player to fly, not give it the ability to fly, force it. Then it will launch it into the air and prevent the falling. .setFlying and .setAllowedFlight dont work.
     
  14. Offline

    xTigerRebornx

    BungeeTheCookie Wouldn't you just launch them up, then set them flying, causing them to be flying, then just listen for when they try to go down, and cancel that?
     
  15. Offline

    BungeeTheCookie

    Because I do not always want them to go down, just after they are launched. When I set them flying, they still go back down, and if I always cancel that, they can never go back down..?
     
  16. Offline

    xTigerRebornx

    BungeeTheCookie Then combine what I said earlier with the flight. When your method is called for "launching them", add them to a List/Set, and then cancel their downward movement if they are in that List/Set, which allows you to control/toggle their ability to move down.
     
  17. Offline

    BungeeTheCookie

    Oh derp. I forgot ;)
     
  18. Offline

    Garris0n

    Why not?
     
  19. Offline

    BungeeTheCookie

    xTigerRebornx Nevermind, it works. I guess it was some glitch in those two methods or something. They work now :D
     
Thread Status:
Not open for further replies.

Share This Page