Creating A Plugin That Prevents Flying

Discussion in 'Plugin Development' started by Snacka Mooni, Jun 14, 2013.

?

Is this easy to fix?

Poll closed Jun 19, 2013.
  1. Yes

    0 vote(s)
    0.0%
  2. No

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

    Snacka Mooni

    What I need help with: Making a plugin that senses if the player's fly speed is not 0 and if it isn't 0, then you will be sent a warning. It will then check 5 seconds later, and if your fly speed still isn't 0, then you will be kicked, otherwise, you will be removed from the player list.

    Code I have so far:
    Code:java
    1. package me.Blindprostitute.flykick;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class flykick extends JavaPlugin {
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static flykick plugin;
    17. public List<Player> flyingplayers = new ArrayList<Player>();
    18.  
    19. @Override
    20. public void onDisable() {
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    23.  
    24. }
    25.  
    26. @Override
    27. public void onEnable() {
    28. PluginDescriptionFile pdfFile = this.getDescription();
    29. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
    30.  
    31. }
    32.  
    33. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    34. {
    35. final Player player = (Player) sender;
    36.  
    37.  
    38. if(!(player.getFlySpeed() == 0))
    39. {
    40. flyingplayers.add(player);
    41. player.sendMessage(ChatColor.DARK_RED + "[REMINDER] " + ChatColor.GOLD + "Do Not Fly!");
    42. }
    43.  
    44. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    45.  
    46. public void run()
    47. {
    48. if(player.getFlySpeed() == 0);
    49. {
    50. player.kickPlayer(ChatColor.DARK_RED + "You broke the server's rules!");
    51. }
    52. }
    53. }, 100L);
    54. return false;
    55.  
    56. }
    57. }
     
  2. Offline

    bitWolfy

    All things aside, why are you checking the player's fly speed in onCommand?..

    In either case, after looking at the javadocs, Player.getFlySpeed() actually returns the allowed speed that a player CAN fly, not the player's current flight speed. So, whatever you are doing, you are not doing it right.
     
  3. Offline

    Quidam

    Why are you checking the fly speed?
    Don't you want to check if the player is flying?


    Code:java
    1. if(player.isFlying()){
    2. //do stuff
    3. }
     
  4. Offline

    Snacka Mooni

    Forgot to note that I'm still new to coding so don't ask me why I do this stupid stuff :(
     
  5. Offline

    bitWolfy

    Quidam I believe that he is trying to make a plugin that prevents people with fly mods from using them on the server. isFlying() will not check for that.
     
  6. Offline

    Snacka Mooni


    I just want to make a plugin that prevents people from flying in general, not just with mods.
     
  7. Offline

    metalhedd

    use the OnPlayerToggleFlight event? i dont know if you can cancel it, but you can catch it, and schedule a player.setFlying(false);
     
  8. Offline

    Rprrr

    I don't think simply using player.setFlying(false) works at all against fly mods.
     
Thread Status:
Not open for further replies.

Share This Page