Solved Commands won't execute after incorporating maven

Discussion in 'Spigot Plugin Development' started by Xurvold, Apr 1, 2020.

  1. As the title says, I incorporated maven but now my commands won't execute.

    Code (Java):

    package me.xurvold.Test;

    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin {

        @Override
        public void onEnable() {
            getLogger().info("onEnable is called.");
        }

        @Override
        public void onDisable() {
            getLogger().info("onDisable is called.");
        }
       
        public boolean onCommand(CommandSender sender, CommandSender cmd, String label, String[] args) {

            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "Only players can use this command.");
                return true;

            }

            if (cmd.getName().equalsIgnoreCase("command")) {
                sender.sendMessage("Success.");
                return true;
            }
         return true;
        }
    }
     
    Pom file:
    Code (Text):

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <properties>
            <maven.compiler.source>1.6</maven.compiler.source>
            <maven.compiler.target>1.6</maven.compiler.target>
        </properties>

        <groupId>org.example</groupId>
        <artifactId>Marry</artifactId>
        <version>1.0-SNAPSHOT</version>

        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
        </repositories>

        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.15.2-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.bukkit</groupId>
                <artifactId>bukkit</artifactId>
                <version>1.15.2-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>


    </project>
     
  2. SteelPhoenix

    Moderator

    If you would use the @Override annotation you would get an indicator your #onCommand() method does not override anything
     
  3. ?
     
  4. Your onCommand method is wrong. If you used the Override annotation, you would get a warning.
    Your second parameter is a CommandSender, should be a command.
    If you're using Eclipse you can use Ctrl + Space to automatically suggest methods to override. Not sure what the is the combination for other IDEs.
     
  5. It would be CTRL + N and selecting Override
    or CMD + O (CMD on mac not sure for windows)
    for Intellij Idea by default