Plugin Help Help with onCommand ( return always the Command in Chat)

Discussion in 'Plugin Help/Development/Requests' started by zoblax, Aug 25, 2017.

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

    zoblax

    Hi, I'm working on a plugin and actually, when i tested it, there is a strange error when I type the command in chat. If I type for example /setcopspawn it will write in chat the command. I know that if i return false in the onCommand it will write me the usage put in the plugin.yml but i always return true. What's the problem? How can i fix it?

    -onCommandClass
    PHP:
    public class SetCopSpawn implements CommandExecutor {

        
    CommandMessage commandMessage = new CommandMessage();

        public 
    boolean onCommand(CommandSender senderCommand cmdString labelString[] args) {

            if (!(
    sender instanceof Player)) {
                
    Bukkit.getConsoleSender().sendMessage(ChatColor.RED "Only Players can perform this command!");
                return 
    true;
            }

            
    Player p = (Playersender;

            if (!
    p.hasPermission("cop.setspawn")) {
                
    commandMessage.NoPermission(p);
                return 
    true;
            }

            
    Location location p.getLocation();

            
    String world location.getWorld().getName().toString();
            
    Double x location.getX();
            
    Double y location.getY();
            
    Double z location.getZ();
            
    Float pitch location.getPitch();
            
    Float yaw location.getYaw();

            
    Core.getCore().getConfig().set("Cop Spawn.world",world);
            
    Core.getCore().getConfig().set("Cop Spawn.x",x);
            
    Core.getCore().getConfig().set("Cop Spawn.y",y);
            
    Core.getCore().getConfig().set("Cop Spawn.z",z);
            
    Core.getCore().getConfig().set("Cop Spawn.pitch",pitch);
            
    Core.getCore().getConfig().set("Cop Spawn.yaw",yaw);

            
    Core.getCore().saveConfig();

            
    p.sendMessage(ChatColor.DARK_GREEN "Cop Spawn " ChatColor.GOLD "has been set!");

            return 
    true;
        }
    }
    -Core Class (Main) Where i register the command
    PHP:
     private void registerCommands(){

            
    getCommand("cop").setExecutor(new JoinCopMode());
            
    getCommand("wantedclear").setExecutor(new WantedClear());
            
    getCommand("setspawn").setExecutor(new SetSpawn());
            
    getCommand("setcopspawn").setExecutor(new SetCopSpawn());
            
    getCommand("wanted").setExecutor(new WantedCommand());

        }
    I call registerCommands() in onEnable and The Core.getCore() return the Core instance.

    [EDIT]

    That's the plugin.yml

    Code:
    "All things about Main,author etc"
    
    commands:
      setspawn:
        usage: /<command>
        description: Use this command to set the Players Spawn
      setcopspawn:
        usage: /setcopspawn
        description: Use this command to set the Cops Spawn.
    I forgot, When i type the command it doesn't send the message i put in onCommand (p.sendMessage.etc.)
     
  2. Offline

    yPedx

  3. Offline

    zoblax

    There was a problem there but the console didn't report it to me... btw really thanks!
     
Thread Status:
Not open for further replies.

Share This Page