Fly wont load

Discussion in 'Spigot Plugin Development' started by Alphine, Jun 20, 2018.

  1. Hello, I'm getting an error that fly wont load. I tried renaming, recoding, and carefully looking over the code and I can't seem to find the problem. I need another set of eyes helping find this error.

    Fly command class code:
    Code (Text):
    package me.alphine.customessentials.commands;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import me.alphine.customessentials.Main;
    import me.alphine.customessentials.utils.Utils;

    public class Fly implements CommandExecutor {
       
        private Main plugin;
       
        public Fly(Main plugin) {
            this.plugin = plugin;
           
            plugin.getCommand("fly").setExecutor(this);
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (!(sender instanceof Player)){
                sender.sendMessage(Utils.chat(plugin.getConfig().getString("console_error_message")));
                return true;
            }
           
            Player p = (Player) sender;
           
            if (p.hasPermission("customessentials.fly")) {
                if (p.isFlying()) {
                    p.setAllowFlight(false);
                    p.setFlying(false);
                    p.sendMessage(Utils.chat(plugin.getConfig().getString("Fly.flying disabled")));
                    return true;
                } else {
                    p.setAllowFlight(true);
                    p.setFlying(true);
                    p.sendMessage(Utils.chat(plugin.getConfig().getString("Fly.flying enabled")));
                }
               
            } else {
               
                p.sendMessage(Utils.chat(plugin.getConfig().getString("no_perm_message")));
               
            }
           
            return false;
        }

    }
     
    Main class code:
    Code (Text):
    import me.alphine.customessentials.commands.Blast;
    import me.alphine.customessentials.commands.Fly;

    public class Main extends JavaPlugin {
       
       
        @Override
        public void onEnable() {
           
            FileConfiguration config = getConfig();
           
            config.options().copyDefaults(true);
            saveConfig();
           
            Bukkit.getConsoleSender().sendMessage("§7(§c!§7) §eCustomEssentials has been §aenabled");
            PluginManager pm = this.getServer().getPluginManager();
            new Fly(this);
            pm.registerEvents((Listener) new Blast(this), this);
        }

       
        @Override
        public void onDisable() {
            Bukkit.getConsoleSender().sendMessage("§7(§c!§7) §eCustomEssentials has been §cdisabled");
            saveConfig();
        }
    }
     
    I have the other imports imported like the FileConfiguration and Listener.
    Here is also the plugin.yml
    Code (YAML):
    name: CustomEssentials
    version
    : 1.4.0 Beta
    author
    : Alphine
    main
    : me.alphine.customessentials.Main
    description
    : Custom Essentials coded by Alphine

    commands
    :
      customessentials
    :
      fly
    :
      blast
    :

     
    permissions
    :
      customessentials.*
    :
        description
    : access too all commands
        children
    :
         customessentials.fly
          customessentials.blast
        default
    : op
       
      customessentials.fly
    :
     customessentials.blast:
    If you can help me. That would be awesome.
     
    • Funny Funny x 1
  2. Errors in the commands i see, also in the plugin.yml
    After a while ill post you a fixes
     
    • Like Like x 1
  3. Thank you so much
     
  4. Okay, here are the fixes:
    Fly command class:
    Code (Java):
    package me.alphine.customessentials.commands;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import me.alphine.customessentials.Main;
    import me.alphine.customessentials.utils.Utils;

    public class Fly implements CommandExecutor {
        private Main plugin;
        public Fly(Main plugin) { this.plugin = plugin; }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)){
                sender.sendMessage(Utils.chat(plugin.getConfig().getString("console_error_message")));
                return true;
            }
            Player p = (Player) sender;
            if(p.hasPermission("customessentials.fly")) {
                if(p.isFlying()) {
                    p.setAllowFlight(false);
                    p.setFlying(false);
                    p.sendMessage(Utils.chat(plugin.getConfig().getString("Fly.flying disabled")));
                    return true;
                }else{
                    p.setAllowFlight(true);
                    p.setFlying(true);
                    p.sendMessage(Utils.chat(plugin.getConfig().getString("Fly.flying enabled")));
                }
            }else{
                p.sendMessage(Utils.chat(plugin.getConfig().getString("no_perm_message")));
            }
            return true;
        }
    }
    Main class:
    Code (Java):
    import me.alphine.customessentials.commands.Blast;
    import me.alphine.customessentials.commands.Fly;

    public class Main extends JavaPlugin {

        @Override
        public void onEnable() {
            saveResource("config.yml", false);
            Bukkit.getConsoleSender().sendMessage("§7(§c!§7) §eCustomEssentials has been §aenabled");
            PluginManager pm = this.getServer().getPluginManager();
            getCommand("fly").setExecutor(new Fly(this));
            pm.registerEvents(new Blast(this), this);
        }
        @Override
        public void onDisable() {
            Bukkit.getConsoleSender().sendMessage("§7(§c!§7) §eCustomEssentials has been §cdisabled");
        }
    }
    the plugin.yml:
    Code (YAML):
    name: CustomEssentials
    version
    : 1.4.0 Beta
    author
    : Alphine
    main
    : me.alphine.customessentials.Main
    description
    : Custom Essentials coded by Alphine
    default
    : op

    commands
    :
      customessentials
    :
        description
    : YourDescription
      fly
    :
        description
    : Fly command
      blast
    :
        description
    : YourDescription
    permissions
    :
      customessentials.*
    :
        description
    : access too all commands
        child
    :
          customessentials.fly
    : true
          customessentials.blast
    : true
    Please do not just copy and paste, try to see the difference between your classes and my edits! Thanks! Also ill be very happy if you give me a positive rating (7 far from posting premium resources)
     
    • Like Like x 1
    • Informative Informative x 1
  5. Thanks for helping!