How could I turn fall damage on with this?

Discussion in 'Plugin Development' started by football70500, Aug 5, 2012.

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

    football70500

    So In my plugin, I am trying to turn fall damage on when you are flying, how would I do that?

    Also, for player.setFoodLevel(), what could I put in the ()?

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  2. Offline

    Limeth

    Do you mean flying in creative?

    Code:
    player.setFoodLevel(15) //makes you 3/4 full
     
  3. Offline

    football70500

    No, like if you are flying and just stop flying you will fall but not take any fall damage
     
  4. Offline

    Phinary

    Are you cancelling the fall damage inside your plugin? If you coded it yourself and allowed them to fly, if they stop and hit the ground they should take damage... Please share your source code.
     
  5. Offline

    Limeth

    Flying via cheats?
     
  6. Offline

    Phinary

    Ohh, that would make much more sense. But too be honest, I have no idea how to do this as I feel it would depend on the coding they are using to fly in the first place.
     
  7. Offline

    AmberK

    You could attempt using the EntityDamageEvent, but you'd have to account for a few things.
     
  8. Offline

    Limeth

    I think I have an idea.
    How about storing the player's highest point since he left the ground and then subtract the height of the ground from it? Then we could count the fall damage:
    FD = number of blocks - 3
    and execute it :)
     
  9. Offline

    football70500

    Where would I put that in my code?
    Code:JAVA
    1. package me.football70500.random;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class random extends JavaPlugin{
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15.  
    16. @Override
    17. public void onEnable() {
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info(pdfFile.getName() + " is now enabled.");
    20. }
    21. @Override
    22. public void onDisable() {
    23. PluginDescriptionFile pdfFile = this.getDescription();
    24. this.logger.info(pdfFile.getName() + " is now disabled.");
    25. }
    26.  
    27.  
    28. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    29. readCommand((Player) sender, commandLabel);
    30. return true;
    31. }
    32. public boolean readCommand(Player player, String command) {
    33. if(command.equalsIgnoreCase("fly")){
    34. if(player.hasPermission("simplefly.fly")){
    35. this.getServer().getPlayer("playername");
    36. player.setAllowFlight(true);
    37. player.setFlying(isEnabled());
    38. player.sendMessage(ChatColor.AQUA + "You are now flying.");
    39. return true;
    40. }else{
    41. player.sendMessage(ChatColor.DARK_RED + "You do not have permission to fly!");
    42. }
    43.  
    44. }
    45. else if(command.equalsIgnoreCase("nofly")){
    46. if(player.hasPermission("simplefly.nofly")){
    47. player.setAllowFlight(false);
    48. player.setFlying(false);
    49. player.sendMessage(ChatColor.RED + "You are no longer flying.");
    50. return true;
    51. }
    52. }
    53. return false;
    54.  
    55. }
    56. }
     
  10. Offline

    pzxc

    Your request is ambiguous... first you ask how to turn fall damage on, but then you say "No, like if you are flying and just stop flying you will fall but not take any fall damage"

    So do you want fall damage or not?

    If you want them to fall when they stop moving, but not take fall damage, just check if the player's velocity is low (like < 0.1) and if so setFlying(false). That will make them fall but not take fall damage because they are still in flying mode even though they stopped flying.
     
  11. Offline

    football70500

    I said that if you hit the ground while flying you take fall damage
     
  12. Offline

    pzxc

    Oh I see, I misinterpreted your post #3 as being what you wanted, not a description of what was happening that you didn't want.

    Anyway, if you do want them to take fall damage, then do setAllowFlight(false) as well as setFlying(false), that will make them stop flying (fall) and take fall damage (since they are not in fly mode anymore).

    If you want them to take damage but NOT leave flying mode, i.e. allow them to start flying again right away without having to turn fly mode back on, then the simplest way would be to turn fly mode off temporarily with setAllowFlight(false) and store the player name in a list or set, then when they take the damage (PlayerDamageEvent) if they are in the list/set remove them from it and turn fly mode back on (setAllowFlight(true))
     
Thread Status:
Not open for further replies.

Share This Page