Discussion in 'Spigot Plugin Development' started by CristianoTRS, Jun 8, 2018.

  1. When I put on GM 0 i can't fly with the plugin why?

    Attached Files:

  2. You have to allow the player to fly with Player#setAllowFlight() also it's best to move the player up 0.00001 blocks because the player will stop flying if they're on the ground.
  3. How do I do that. 0000.1 blocks?
  4. Get their current location, add 0.0001 blocks to the Y value with Location#add() and teleport them to that location.
  5. Few things about your code:

    1) Its not organized, so it makes it harder to read. If you cant read it you cant debug it.
    2) You dont need empty methods for onEnable() and onDisable(). If you arent using them, leave them out.
    3) It's advised to get in the habbit of using the @Override annotation. You'll thank me later when you learn why.
    4) Never return false unless you want the server to output the command usage/description to the command sender
    5) Never cast CommandSender to Player without checking it first
    6) Learn better bracket nesting techniques (see my example for my favorite)
    7) You want to mess with their allowed flight flag. Only use setFlying() to knock them out of flight when disabling their allowed flight flag.

    Code (Java):
    public class Main extends JavaPlugin {
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("Player only command!");
                return true;

            if (!sender.hasPermission("")) {
                sender.sendMessage("No permission");
                return true;

            Player player = (Player) sender;


            if (player.getAllowFlight()) {
                sender.sendMessage("Fly enabled");
            } else {
                sender.sendMessage("Fly disabled");

            return true;
    #5 BillyGalbreath, Jun 8, 2018
    Last edited: Jun 8, 2018
    • Agree Agree x 2
  6. Strahan


    You forgot the ! :)
    • Like Like x 1
  7. Good catch! ^_^ I wrote it from my phone :3