Fly disabled when Inventory open while flying

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

  1. Aight,

    So I have made a TownyFly plugin that allows players to fly within their town, I've been ironing out all the problems with it but there is one I am confused on. When a player opens their inventory while in mid air their fly mode gets disabled and they drop to the ground and die. Is there a EventHandler that listens for inventories opening and closing or am I overthinking this bug? How would I fix this?

    Cheers,
    Panda :)!
     
  2. InventoryOpenEvent
     
    • Agree Agree x 1
  3. Problem might be that there is no event, for players opening their own inventory. AFAIK the only way knowing is the achievement, but that would need faking not having it + resetting.

    So for opening their own inventory i assume that something like the InventoryClickEvent could be helpful to at least do something then.

    (If you made a count down from 5 or so, for players who stand still in-air while flying, you'd still have them opening their inventory when flying at some speed, so they actually don't stand still. In addition cheats or inventory managers would rather be quick, so one penalizes legitimate players rather than cheaters.)
     
  4. Both of these don't allow me to check if the player if flying, or if their fly mode is set? Which is annoying, would their be another alternative to the problem? Or is this the most effective way to fix it?
     
  5. Yes it does? Just check if #getPlayer instanceof Player and cast it.
     
  6. Yes :). getWhoClicked (for InventoryClick i think) -> HumanEntity -> Player ? -> isFlying ...
     
  7. Yaa sorry, just noticed what I put and recoiled in horror, brainfart moment xD.

    Still failing to resolve the bug, here is my code if you're able to point out something I have missed: https://github.com/StuddedExpandable/TownyFly/blob/master/src/thevoxstudios/vtownyfly/TownyFly.java


    Guess I'll try it out, nothing to lose xD.
     
  8. InventoryOpenEvent is not called when someone opens their own inventory as that's client side.
     
  9. Ohh alright, So InventoryOpenEvent & InventoryCloseEvent are useless in my case? Any other way I can resolve this easily?
     
  10. Yeah since you wouldn't be able to listen for them with an event. But you can however have a repeating loop that checks to see if the player's opened inventory is theirs. I'm not 100% if that's how it works though.
     
  11. When they click stuff (see above)?
     
  12. that really helps when you read the spigot javadoc

    Code (Java):
    // when player opens a inventory
    InventoryOpenEvent

    for(Player p : e.getViewers()) {
      if(p.isFlying()) {
        // do something
      }
    }