EntityDamageEvent problem.

Discussion in 'Spigot Plugin Development' started by TheMasteredPanda, May 28, 2016.

  1. So I am replacing the feature of teleporting them straight to the ground when they leave their town while flying to a EntityDamageEvent so that they can fall down without dying, but I am having a problem with actually getting it to work, I believe I have done it correctly but it gives me a horrific stacktrace which tells me it couldn't pass the event, and then it tells me it cannot cast CraftSkeleton? Feel as if I have screwed it up somehow, where am I going wrong?!

    My code: https://github.com/StuddedExpandable/TownyFly/blob/master/src/thevoxstudios/vtownyfly/TownyFly.java

    Thank you!
    Panda.
     
  2. Could you paste the stacktrace here?
     
  3. Sorry but i can't follow you. I look down you code and i get that you like to disable fly if a player leave it plot and enable if a player enter. When a player fall down cause of disable the flymode by plugin he get damage, this you want to prevent, right?

    Can you poste your error log too?
     
  4. sure thing

    indeed.

    Stacktrace: https://gist.github.com/StuddedExpandable/632be3692c637542bb88b01de6cbb894
     
  5. In logs you have older plugin version. I think, that code is ok, but you didn't upload to server corected plugin version.
     
  6. Try testing if the the entity damaged is an instance of a player, just saying it's == to a player doesn't always mean it will be.
     
  7. I would recommend printing out information about the event whenever it's called so that you can isolate the issue.

    log(e.getCause());
    log(p.hasPermission("vox.towny.fly");

    etc.
     
  8. I noticed that when someone leaves the plot, you set their flying to false. In your if statements, you check if the player is flying which is always false. So none of those statements inside the if statement will execute so the damage will not be cancelled.

    Solution: Remove the check that sees if the player is flying.
     
    • Agree Agree x 1
  9. Ah right ok, i'm currently no at home right now but would checking the material below them work too? So say instead of p.isFlying I would do p.getLocation().subtract(0, 1, 0).getBlock().getType == Material.Air, would that work too (doing it off the top of my head so excuse me if I did it wrong)?
     
  10. If you want to cancel the damage caused by hitting the floor then I don't think you have to check that they are above the ground to do so. Just remove the p.isFlying() from the of statement and try that.
     
  11. Aight cool, worked. Would there be any way to make sure that it will only cancel the damage when they fall due to them leaving their plot becuase right now they can fall off of anything and not get any damage. Would checking a arraylist do it?
     
  12. You could however, an arraylist gets cleared after a restart or reload. This means that if a player joins a plot, they'll get added to the arraylist but if the server were to restart or reload, then if the player leaves the plot, nothing will happen because the arraylist which contained that player's data was cleared.

    You could use a configuration file to store the person's name when they join the plot. Then when they leave, you check if the config file contains the person's name. If so, you cancel the fall damage and remove them from the configuration file.

    There are probably other better ways, but this is the only one I can think of at the moment.