Need help small problem ...

Discussion in 'Plugin Development' started by nehuskerfan2, Jul 6, 2012.

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

    nehuskerfan2

    I posted earlier but I disregard that thread.

    I'm making a plugin for shops basically. I'm working on the commands for help. I can't /supermarket help to work, just /supermarket

    Here are the classes I have.
    Supermarket.java
    Code:java
    1.  
    2.  
    3. package me.nehuskerfan2.Supermarket;
    4.  
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. import me.nehuskerfan2.Supermarket.commands.*;
    8.  
    9.  
    10. public class Supermarket extends JavaPlugin {
    11.  
    12. protected SupermarketLogger log;
    13.  
    14. public void onEnable(){
    15. this.log = new SupermarketLogger(this);
    16.  
    17. this.getCommand("supermarket").setExecutor(new CommandSupermarket(this));
    18.  
    19. }
    20. public void onDisable(){
    21.  
    22. }
    23.  
    24. }
    25.  
    26.  

    SupermarketLogger.java
    Code:java
    1.  
    2.  
    3. package me.nehuskerfan2.Supermarket;
    4.  
    5. import java.util.logging.Logger;
    6.  
    7. public class SupermarketLogger {
    8.  
    9. private Logger log;
    10.  
    11. public SupermarketLogger(Supermarket plugin){
    12. this.log = Logger.getLogger("Minecraft");
    13. }
    14.  
    15. private String getFormattedMessage(String message){
    16.  
    17. return "[Supermarket] " + message;
    18. }
    19.  
    20. public void info(String message){
    21. this.log.info(this.getFormattedMessage(message));
    22. }
    23.  
    24. }
    25.  
    26.  

    commands/CommandSupermarket.java
    Code:java
    1.  
    2.  
    3. package me.nehuskerfan2.Supermarket.commands;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10.  
    11. import me.nehuskerfan2.Supermarket.Supermarket;
    12.  
    13. public class CommandSupermarket implements CommandExecutor {
    14.  
    15. private Supermarket plugin;
    16.  
    17. public CommandSupermarket(Supermarket plugin) {
    18. this.plugin = plugin;
    19. }
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    22. PluginDescriptionFile pdf = plugin.getDescription();
    23. if(args.length == 0){
    24. sender.sendMessage(ChatColor.BLUE + pdf.getName() + " v" + pdf.getVersion());
    25. sender.sendMessage(ChatColor.BLUE + "Created by nehuskerfan2");
    26. sender.sendMessage(ChatColor.BLUE + "/supermarket help " + ChatColor.GOLD + "- Display Supermarket help.");
    27. return true;
    28. } else if(args.length == 1){
    29. if(args[0] == "help"){
    30. sender.sendMessage("lol");
    31. }
    32. }
    33. return true;
    34. }
    35.  
    36. }
    37.  
    38.  

    plugin.yml
    Code:
    name: Supermarket
    version: 0.1
    author: nehuskerfan2
     
    main: me.nehuskerfan2.Supermarket.Supermarket
    database: true
     
    commands: 
        supermarket:
            description: Shows Supermarket introduction
            usage: /supermarket
        supermarket help:
            description: Shows Supermarket help
            usage: /supermarket help
    
    My problem is when I execute the command /supermarket help it doesn't return anything back to me. Any ideas?
     
  2. First of all, you can't put the argument of a command in the plugin.yml that won't do anything, second, you could try to first check if the command is supermarket, like this:
    Code:java
    1.  
    2.  
    3. package me.nehuskerfan2.Supermarket.commands;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10.  
    11. import me.nehuskerfan2.Supermarket.Supermarket;
    12.  
    13. public class CommandSupermarket implements CommandExecutor {
    14.  
    15. private Supermarket plugin;
    16.  
    17. public CommandSupermarket(Supermarket plugin) {
    18. this.plugin = plugin;
    19. }
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    22. PluginDescriptionFile pdf = plugin.getDescription();
    23. if(cmd.getName().equalsIgnoreCase("supermarket")) {
    24. if(args.length == 0){
    25. sender.sendMessage(ChatColor.BLUE + pdf.getName() + " v" + pdf.getVersion());
    26. sender.sendMessage(ChatColor.BLUE + "Created by nehuskerfan2");
    27. sender.sendMessage(ChatColor.BLUE + "/supermarket help " + ChatColor.GOLD + "- Display Supermarket help.");
    28. return true;
    29. } else if(args.length == 1){
    30. if(args[0] == "help"){
    31. sender.sendMessage("lol");
    32. }
    33. }
    34. }
    35. return true;
    36. }
    37.  
    38. }
    39.  
    40.  


    I am not sure if this will fix your problem, but i think it might:p

    greetz blackwolf12333
     
  3. Offline

    nisovin

    Always compare strings with .equals(), not ==.

    Code:
    if (args[0].equals("help"))
     
    ferrybig and pd9937 like this.
  4. Offline

    nehuskerfan2

    That helped, thanks. I can continue :)
     
Thread Status:
Not open for further replies.

Share This Page