Why this doesnt work?

Discussion in 'Spigot Plugin Development' started by JimmYTje, May 27, 2017.

  1. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Is it throwing an error? Is it not doing something you want it to do?
     
  2. You forgot to register your cmd by the method getCommand("cmd").setExecutor(this)

    Envoyé de mon SM-G530W en utilisant Tapatalk
     
  3. It should say Hello iDevq but if i try /help it says Help for help
     
  4. Thanks forgot it :3
     
  5. package me.iDevq.TestPlugin;

    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin {

    @Override
    public void onEnable() {
    getCommand("main").setExecutor(new BasisCommand());
    }

    @Override
    public void onEnable() {
    getCommand("hello").setExecutor(new CMessage());
    }
    }
    I did this but it turn red?
     
  6. And in your plugin.yml did you register this cmd ?

    Envoyé de mon SM-G530W en utilisant Tapatalk
     
  7. main: me.iDevq.TestPlugin.Main
    name: TestPlugin
    version: 1.0
    author: iDevq
    description: Geen beschrijving
    commands:
    main:
    description: "Nutteloos af."
    usage: "Error! Gebruik /main"
    main:
    description: "Hij zegt wat terug :)"
    usage: "Error! Gebruik /hello"
     
  8. Duplicate method onEnable() in type Main
     
  9. What does this mean? Duplicate method onEnable() in type Main
     
  10. IT is not working if you do that !

    Envoyé de mon SM-G530W en utilisant Tapatalk
     
  11. What do i need to type then?
     
  12. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Then you probably put the method onEnable() twice in your Main plugin class.
     
  13. Yeah that's not possible? what now then?
     
  14. Mas

    Mas

    Why are you trying to make two onEnable() methods anyway? Move all the code from the duplicate into the first one.
     
  15. package me.iDevq.TestPlugin;

    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin {

    @Override
    public void onEnable() {
    getCommand("main").setExecutor(new BasisCommand());
    getCommand("hello").setExecutor(new CMessage());
    }

    }
    i did that but now its not working propperly its using the Plugin.yml message not the one that i made.
     
  16. Mas

    Mas

    Which plugin.yml message are you referring to? And show us your code so we can see what the problem may be.

    Why the hell are you bumping 5 minutes after making a post? That isn't doing anything.
     
  17. +
    main: me.iDevq.TestPlugin.Main
    name: TestPlugin
    version: 1.0
    author: iDevq
    description: Geen beschrijving
    commands:
    main:
    description: "Nutteloos af."
    usage: "Error! Gebruik /main"
    hello:
    description: "Hij zegt wat terug :)"
    usage: "Hallo hoe gaat het?"
    If i do /hello ^ this will get in the chat
    But i made this message
    =
    package me.iDevq.TestPlugin;

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

    public class CMessage extends JavaPlugin {

    @Override
    public void onEnable() {
    getLogger().info("Hello, Player plugin has been enabled!");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if (cmd.getName().equalsIgnoreCase("hello")&& sender instanceof Player) {

    Player player = (Player) sender;

    player.sendMessage("Hello, " + player.getName() + "!");

    return true;

    }

    return false;

    }

    }
     
  18. Mas

    Mas

    The usage from the plugin.yml gets printed in chat when you return false in onCommand. In your code this happens if the command is not hello or the sender is not a player, so you must be sending the command from console.

    Next time please format your code with [ code ] [ /code ] blocks so it is easier to read ;)