CommandExecutor

Discussion in 'Plugin Development' started by ProMCKingz, Aug 25, 2014.

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

    ProMCKingz

    Hey!
    I have this very basic problem which I can't seem to get round to, I can't change the console messager, so that when the command is issued it doesnt give console errors, saying its not possible to perform via console, So I want to replace it with this message:
    My Class:
    Code:java
    1. public class ConsoleListener implements CommandExecutor{
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    4. if (sender instanceof Server) {
    5. Bukkit.getServer().broadcastMessage(ChatColor.RED + "Only players can use " + ChatColor.GREEN + ChatColor.ITALIC + "" + "'/wardrobe'");
    6. String Name = sender.getServer().getMotd();
    7. Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "You may edit in the configuration file!");
    8. Bukkit.getServer().broadcastMessage(ChatColor.WHITE + "Thank you for installing this plugin, " + ChatColor.YELLOW + Name);
    9. return true;
    10. }
    11. return true;
    12. }
    13. }
    14.  

    And I have also done this in my main class to register the event
    Code:java
    1. getCommand("wardrobe").setExecutor(new ConsoleListener());

    :
     
  2. Offline

    Dragonphase

    ProMCKingz

    You need to check if (!(sender instanceof Player))
     
  3. Offline

    ProMCKingz

    Dragonphase I tried that also, however that doesn't seem to work either

    What else?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  4. You need to use
    if (!(sender instanceof Player))
    And
    sender.sendMessage();
     
  5. Offline

    ProMCKingz

    Bram0101 Let me update my code:
    Code:java
    1. public class ConsoleListener implements CommandExecutor{
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    4. if (!(sender instanceof Player)) {
    5. sender.sendMessage(ChatColor.RED + "Only players can use " + ChatColor.GREEN + ChatColor.ITALIC + "" + "'/wardrobe'");
    6. String Name = sender.getServer().getMotd();
    7. sender.sendMessage(ChatColor.AQUA + "You may edit in the configuration file!");
    8. sender.sendMessage(ChatColor.WHITE + "Thank you for installing this plugin, " + ChatColor.YELLOW + Name);
    9. }
    10. return true;
    11. }
    12. }
    13.  

    This however still does not work. Which is the issue bothering me
     
  6. Try moving the onCommand method to your main class.
    And add the command to the plugin.yml(if you haven't done it)
     
  7. Offline

    ZachBora

    ProMCKingz why not support console and commandblocks :O
     
Thread Status:
Not open for further replies.

Share This Page