Solved How to disable fly when a player takes off the boots?

Discussion in 'Plugin Development' started by winitro, Sep 14, 2014.

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


    How do I disable the fly when someone takes off the boots with Jumping I
    1. package;
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.GameMode;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerMoveEvent;
    10. import org.bukkit.event.player.PlayerToggleFlightEvent;
    11. import;
    13. public class Main extends JavaPlugin implements Listener{
    15. public void onEnable(){
    16. getServer().getPluginManager().registerEvents(this, this);
    17. }
    18. @EventHandler
    19. public void onPlayerToggleFlight(PlayerToggleFlightEvent event){
    20. Player player = event.getPlayer();
    21. if(player.getInventory().getBoots().getItemMeta().getLore().contains(ChatColor.GRAY + "Jumping I")){
    22. if (player.getGameMode() == GameMode.CREATIVE)
    23. return;
    24. event.setCancelled(true);
    25. player.setAllowFlight(false);
    26. player.setFlying(false);
    27. player.setVelocity(player.getLocation().getDirection().multiply(2.0)
    28. .setY(1));
    29. player.setAllowFlight(false);
    30. player.setFlying(false);
    31. }
    32. }
    34. @EventHandler
    35. public void onPlayerMove(PlayerMoveEvent event) {
    36. Player player = event.getPlayer();
    37. if(player.getInventory().getBoots().getItemMeta().getLore().contains(ChatColor.GRAY + "Jumping I")){
    38. if((player.getGameMode()!=GameMode.CREATIVE)&&(player.getLocation().subtract(0, 1, 0).getBlock().getType()!=Material.AIR)&&(!player.isFlying())){
    39. player.setAllowFlight(true);
    40. }
    41. }
    42. }
    43. }


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


    winitro uhmm maybe on playermoveevent check if p.getequipment.getboots != null then p.setallowfly false ?
  3. Offline


    Ok i'll try thanks!
  4. Offline


    Dont do this, it will lag...

    Listen for the InventoryClickEvent and check if they clicked the boots slot, if so, remove fly.
  5. Offline


    Aqua that didn't work... so I tried a delayed task. and it worked but thanks for the help!
    You to EnchantedMiners
  6. Offline


    winitro Aqua np well i didnt test my code but it shouldnt lag for playermove event and on the != null null was your flyingboots itemstack so if the player doesnt have the boots on it will proceed to the rest of the code havent try the code but im pretty sure there will be no lagg or wierd stuff btw cant give an exact code since im not on my pc but glad i got to help someone :)
  7. Offline


    winitro Delayed tasks can still create lag...
  8. Offline


    The key word there is 'Can' sir.
Thread Status:
Not open for further replies.

Share This Page