Command not working

Discussion in 'Plugin Development' started by monkeymanboy, Oct 5, 2013.

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

    monkeymanboy

    I am setting up an achievement system for my server with the command /achievement showing your achievements but when I do the command it does nothing. Here is my code
    Code:java
    1. int i = 0;
    2. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    3. if(cmd.getName().equalsIgnoreCase("achievement")){
    4. if(sender instanceof Player){
    5. sender.sendMessage("Works2");
    6. IconMenu achievement = new IconMenu("Achievement", 27, new IconMenu.OptionClickEventHandler(){
    7. public void onOptionClick(OptionClickEvent event) {
    8. final Player player = event.getPlayer();
    9. event.setWillClose(true);
    10. event.setWillDestroy(true);
    11. if(event.getName().equals("Next Page")){
    12. player.sendMessage("Not out yet");
    13. }
    14. }
    15. }, plugin);
    16. {
    17. FileConfiguration config = plugin.getConfig();
    18. Player player = (Player) sender;
    19. if(config.getBoolean("achievements." + player.getName() + ".kill")){
    20. achievement.setOption(i, new ItemStack(Material.WOOD_SWORD), "Killin' It", "First PVP Kill");
    21. }
    22. }
    23. sender.sendMessage("Works");
    24. achievement.open((Player) sender);
    25. }
    26. }
    27. return false;
    28. }

    You'll notice I added some test messages in there and it does not do any of them
     
  2. Offline

    adam753

    Have you put it in your plugin.yml?
     
  3. Offline

    monkeymanboy

    adam753 Yep, here it is.
    Code:
    name: MinecloudCore
    main: com.icloud.dcljr.MinecloudCore.MinecloudCore
    version: 1.0
    author: monkeymanboy
    commands:
      achievement:
        description: Open Achivement GUI
    
     
  4. Offline

    number1_Master

    Did you register it in the onEnable?
     
  5. Offline

    adam753

    monkeymanboy Well that looks fine. I notice you're using a plugin variable, which means this isn't inside your main class, so have you remembered to set command executors properly?
     
  6. Offline

    monkeymanboy

    adam753 Oh thats what it is I never usually have commands not in my main class so I forgot to do that

    @adam573 Still not working, this is my onEnable() now
    Code:java
    1. private final fb f = new fb(this);
    2. private final pw p = new pw(this);
    3. private final sp s = new sp(this);
    4. private final ach a = new ach(this);
    5.  
    6. @Override
    7. public void onEnable(){
    8. getLogger().info("Minecloud Core Enabled");
    9. PluginManager pm = this.getServer().getPluginManager();
    10. pm.registerEvents(this.f, this);
    11. pm.registerEvents(this.p, this);
    12. pm.registerEvents(this.s, this);
    13. pm.registerEvents(this.a, this);
    14. pm.registerEvents(this, this);
    15. getCommand("achievement").setExecutor((CommandExecutor) this.a);
    16. for (ShapedRecipe recipe : fb.recipes) {
    17. this.getServer().addRecipe(recipe);
    18. }
    19.  
    20. for (ShapelessRecipe recipe : fb.shapeless) {
    21. this.getServer().addRecipe(recipe);
    22. }
    23. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
    adam753 likes this.
  7. Offline

    adam753

    I don't think you need to cast it to CommandExecutor there. But incidentally, does your ach class extend CommandExecutor? It needs to.
     
  8. Offline

    monkeymanboy

    adam753 I am already using that class as a Listener so I am just gonna save myself the trouble and move my command to main class
     
Thread Status:
Not open for further replies.

Share This Page