Search in sources :

Example 1 with PlayerToggleFlightEvent

use of org.bukkit.event.player.PlayerToggleFlightEvent in project Glowstone by GlowstoneMC.

the class PlayerAbilitiesHandler method handle.

@Override
public void handle(GlowSession session, PlayerAbilitiesMessage message) {
    // player sends this when changing whether or not they are currently flying
    // other values should match what we've sent in the past but are ignored here
    GlowPlayer player = session.getPlayer();
    boolean flyingFlag = (message.getFlags() & 0x02) != 0;
    // the current flying state
    boolean isFlying = player.isFlying();
    boolean canFly = player.getAllowFlight();
    if (isFlying != flyingFlag) {
        // or enabled it and is allowed to fly
        if (!flyingFlag || canFly) {
            PlayerToggleFlightEvent event = EventFactory.getInstance().callEvent(new PlayerToggleFlightEvent(player, flyingFlag));
            if (event.isCancelled()) {
                session.getServer().sendPlayerAbilities(player);
            } else {
                player.setFlying(flyingFlag);
            }
        }
    }
}
Also used : PlayerToggleFlightEvent(org.bukkit.event.player.PlayerToggleFlightEvent) GlowPlayer(net.glowstone.entity.GlowPlayer)

Aggregations

GlowPlayer (net.glowstone.entity.GlowPlayer)1 PlayerToggleFlightEvent (org.bukkit.event.player.PlayerToggleFlightEvent)1