Java Code Examples for org.bukkit.event.player.PlayerToggleFlightEvent#isFlying()

The following examples show how to use org.bukkit.event.player.PlayerToggleFlightEvent#isFlying() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DoubleJumpMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerToggleFlight(final PlayerToggleFlightEvent event) {
  Player player = event.getPlayer();
  Jumper jumper = this.jumpers.get(player);
  if (jumper == null) return;

  if (event.isFlying()) {
    event.setCancelled(true);

    this.setCharge(jumper, 0f);
    this.refreshJump(player);

    // calculate jump
    Vector impulse = player.getLocation().getDirection();

    impulse.setY(0.75 + Math.abs(impulse.getY()) * 0.5);
    impulse.multiply(jumper.kit.power / 3f);
    event.getPlayer().setVelocity(impulse);

    player.getWorld().playSound(player.getLocation(), Sound.ZOMBIE_INFECT, 0.5f, 1.8f);
  }
}
 
Example 2
Source File: DoubleJumpMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerToggleFlight(final PlayerToggleFlightEvent event) {
    Player player = event.getPlayer();
    Jumper jumper = this.jumpers.get(player);
    if(jumper == null) return;

    if(event.isFlying()) {
        event.setCancelled(true);

        this.setCharge(jumper, 0f);
        this.refreshJump(player);

        // calculate jump
        Vector impulse = player.getLocation().getDirection();

        impulse.setY(0.75 + Math.abs(impulse.getY()) * 0.5);
        impulse.multiply(jumper.kit.power / 3f);
        event.getPlayer().applyImpulse(impulse, true);

        player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_INFECT, 0.5f, 1.8f);
    }
}
 
Example 3
Source File: DoubleJumpKit.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler
public void onPlayerToggleFly(PlayerToggleFlightEvent event) {
    if (!enabled) return;
    Player player = event.getPlayer();
    if (!players.contains(player.getUniqueId()) || player.getExp() > 1.0f || !event.isFlying()) return;
    player.setAllowFlight(false);
    player.setExp(0.0f);
    event.setCancelled(true);

    Vector normal = player.getEyeLocation().getDirection();
    normal.setY(0.75 + Math.max(normal.getY() * 0.5, 0));
    normal.multiply(power / 2);
    event.getPlayer().setVelocity(normal);

    player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_INFECT, 0.5f, 1.8f);

    update();
}
 
Example 4
Source File: ListenerFlight.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onToggleFlight(PlayerToggleFlightEvent e) {
    if(!e.isFlying()) return;

    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("flight.prevent-flying")) return;

    Player player = e.getPlayer();
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.flight.no-flying");
    this.plugin.sendMessage(player, message);
}