Plugin help

Discussion in 'Spigot Plugin Help' started by VodkaRP, Oct 18, 2020.

  1. Idk why it's not working, if you do tell me what is wrong?
    package me.VodkaRP.Fly.Command;

    import me.VodkaRP.Fly.Main;

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

    import Utils.Util;

    public class Commands implements CommandExecutor{

    private Main plugin;

    public Commands(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("Only players can execute this command!");
    return true;
    }
    Player p = (Player) sender;
    if(p.hasPermission("custome.fly")){
    if(p.isFlying()){
    p.setAllowFlight(false);
    p.setFlying(false);
    p.sendMessage(Util.chat("&9You disabled flight"));
    return true;
    }
    else {
    p.setAllowFlight(true);
    p.setFlying(true);
    p.sendMessage(Util.chat("&9You enabled enabled flight"));
    }


    }
    return false;
    }
    }
     
  2. Have you registered the command? Did you put the command into plugin.yml?
     
  3. I did, lemme show it
    name: Fly
    version: 1.0
    main: me.VodkaRP.Fly.Main
    commands:
    Fly:
    Flyspeed:
     
  4. Have you set an indent after commands in plugin.yml? Is the console showing anything while loading the plugin or performing the command?
     
  5. [ERROR] Error occurred while enabling Fly v1.0 (Is it up to date?)

    java.lang.NullPointerException: null

    at me.VodkaRP.Fly.Command.SpeedCommand.<init>(SpeedCommand.java:18) ~[?:?]

    at me.VodkaRP.Fly.Main.onEnable(Main.java:12) ~[?:?]

    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:461) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:375) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:449) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.DedicatedServer.init(DedicatedServer.java:266) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:775) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at java.lang.Thread.run(Thread.java:823) [?:1.8.0_265]

    [INFO] [Eat] Enabling Eat v1.0

    [INFO] [DeathMessages] Enabling DeathMessages v1.0

    [INFO] [info] Enabling info v1.0

    [INFO] Server permissions file permissions.yml is empty, ignoring it

    [INFO] Done (49.148s)! For help, type "help"

    [INFO] Starting GS4 status listener

    [INFO] Query running on 0.0.0.0:41480

    [INFO] UUID of player VodkaRP is ff6bf408-268c-4c08-8920-9ea753bd474e

    [INFO] VodkaRP[/196.234.139.138:65007] logged in with entity id 6 at ([world]-431.69669736115173, 68.91797326234727, -151.75708819738998)
     
  6. Your passing a null value to the constructor
     
  7. How to fix that? I'm still new at this
     
  8. package me.VodkaRP.Fly;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.VodkaRP.Fly.Command.*;;


    public class Main extends JavaPlugin {

    @Override
    public void onEnable(){
    new Commands(this);
    new SpeedCommand(this);
    }
    }
     
  9. I get it now.
    I was wrong, it's not a null variable passed to the constructor, is JavaPlugin#getCommand() that returns null because plugin.yml hasn't written correctly.
    Change it to:
    Code (Text):
    name: Fly
    version: 1.0
    main: me.VodkaRP.Fly.Main
    commands:
      fly:
        description: Descript your command
     
    And so the constructor shall be:
    Code (Text):
    public Commands(Main plugin) {
        plugin.getCommand("fly").setExecutor(this);
    }
    There is no point to store the plugin variable since you're not accessing it outside the constructor
     
  10. My problem is not the Fly command, its the Flyspeed one, the fly one is working well
     
  11. Add it to the plugin.yml:
    Code (Text):
    name: Fly
    version: 1.0
    main: me.VodkaRP.Fly.Main
    commands:
      fly:
        description: Descript your command
      flyspeed:
        description: Descript your command
    And set his executor:
    Code (Text):
    public Commands(Main plugin) {
        plugin.getCommand("fly").setExecutor(this);
        plugin.getCommand("flyspeed").setExecutor(this);
    }
    Remember to add a check inside onCommand to make both commands works as expected
     
    • Agree Agree x 1