Custom command not working!

Discussion in 'Plugin Development' started by DenverXDXDXD, Nov 22, 2017.

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

    DenverXDXDXD

    Hey guys!

    I made a simple plugin were when you enter a certain command it prints a simple message
    (I am using eclipse and minecraft 1.12.2)

    Command:

    /DXD.test

    print "Test successful!"

    Here is the code:

    Main class:
    Code:
    package com.Denver.plugin;
    
    import org.bukkit.command.*;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class main extends JavaPlugin{
       
        @Override
        public void onEnable() {
            getLogger().info("Plugin DenverXDXDXD has been enabled!");
        }
       
        @Override
        public void onDisable() {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("DXD.test") && sender instanceof Player) {
               
                Player player = (Player) sender;
               
                player.sendMessage("Test successfull!");
               
            }
           
            return false;
        }
    }
    
    Yml file:
    Code:
    name: DenverXDXDXD
    main: com.Denver.plugin.main
    version: 1.0
    commands:
       DXD.test:
          description: This is a test command.
          usage: /<command>

    It prints out "Test successful" but it also prints out the command you entered.

    I only want it to print "Test successful" and nothing else.
     
  2. Offline

    Zombie_Striker

    @DenverXDXDXD
    The reason it is printing out the command usage is because you are returning false. That value determines if the command was issued correctly. If the command worked the way it should, return true.

    BTW: If the onDisable does nothing, delete it. Also, since bukkit already logs your plugins when they are enabled, you do not need to log that your plugin has been enabled.
     
  3. Drop a return true; after the send message method. Because of ^
     
  4. Offline

    JustRendering

    The command prints out the command you entered too because the "Usage in plugin.yml, the usage tells you the usage everytime even if used correctly
     
  5. Offline

    DenverXDXDXD

    Thank you guys!

    I will try returning false
     
  6. Offline

    H1DD3NxN1NJA

    no lol, change the return false to a return true, its on the bottom of your code
     
Thread Status:
Not open for further replies.

Share This Page