[No Longer A Problem] Code Not Working (Simple Command)

Discussion in 'Plugin Development' started by Hutchmaster99, Oct 12, 2013.

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

    Hutchmaster99

    I made a simple chat clear plugin last night, however the command isn't working. When I perform the command the console just says "Hutchmaster99 has issued server command: /iclear". Sadly, this has been happening to all my plugins lately, and I don't know what is going on. Below is the code, it's all just one file.

    Code:
    package me.hutchmaster99.iMute;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class iMute extends JavaPlugin{
       
        @Override
        public void onEnable(){
            System.out.print("iMute is enabled!");
        }
        @Override
        public void onDisable() {
            System.out.print("iMute is diabled!");
        }
       
        public boolean onCommand(Command cmd, CommandSender sender, String commandLabel, String args[]){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("iclear")){
                player.sendMessage("                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    " + ChatColor.GREEN + "Your chat has been cleared!");
            }
            return false;
        }
    }
    
    Any help would be appreciated.
     
  2. Offline

    Mre30

    Code:java
    1. public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
    2. {
    3. System.out.println(command.getName());
    4. if(command.getName().equalsIgnoreCase("command here homie g dog"))
    5. {
    6. //random code that you wish to run;
    7. }
    8. return false;
    9. }
    10.  
     
  3. Offline

    Tehmaker

    This doesn't relate to this at all...

    player.sendMessage("

    Might be ur issue?

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

    Harry5573

    Heres what i do, please note i use a loop to do it 75 times.

    Code:
     @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = null;
     
            if (sender instanceof Player) {
                p = (Player) sender;
            }
     
            if (p == null) {
                System.out.println("[Raidcraft] Thats not a console command!");
                return true;
            }
            if (commandLabel.equalsIgnoreCase("cc")) {
                if (!p.hasPermission("raidcraft.chatmod")) {
                    p.sendMessage(ChatColor.RED + "You do not have the needed permission to do that!");
                    return true;
                }
     
                for (int i = 0; i < 75; i++) {
                    Bukkit.broadcastMessage(" ");
                }
     
                Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "!!! " + ChatColor.AQUA + "Chat WIPED By " + ChatColor.GOLD + p.getName() + ChatColor.AQUA + "!" + ChatColor.LIGHT_PURPLE + " !!!");
            }
    Oh and make sure your commands are registered in your plugin.yml like the following:
    Code:
    name: RaidcraftUtils
    version: 1.0-B
    description: Plugin for Raidcraft
    authors: [Harry5573]
    main: net.harry5573.utils.Core
    softdepend: [Factions]
    commands:
      cc:
        description: Clears all chat on the server
      chat:
        description: Halt/Unhalt chat
     
  5. Offline

    Wire

  6. Offline

    iPoke111

    ^bump >_>
     
  7. Offline

    Deleted user

    Don't you need to

    a) Register the command and
    b) Implement CommandExecutor?
     
  8. Offline

    MrSparkzz

    Not if the onCommand method is in the main class.

    Hutchmaster99
    I don't really see what you're asking? I'm guessing the problem is with
    Code:java
    1. player.sendMessage("

    Try changing it to
    Code:java
    1. player.sendMessage("");

    Also, never look for commands with commandLabel. Do
    Code:java
    1. if (command.getName().equalsIgnoreCase("iclear")) {
     
  9. Offline

    super292

    Hutchmaster99
    Ok, here's your issue, the result stemming from the command is this: player.sendMessage("
    That's not finished, try it like this: player.sendMessage("tacos");
     
  10. Offline

    MrSparkzz

    He's also comparing a string to commandLabel instead of the actual command. Which is his main problem. That's just a secondary problem.
     
  11. Offline

    super292

    Lol, I just noticed that error :/ Did not see his commandLabel error there, nice catch.
     
  12. Offline

    Hutchmaster99

    Sorry guys.
    Okay, the problem isn't player.sendMessage(". I have a message there (It's just a long message of spaces and at the end is "Your chat has been cleared!".

    I have stopped making plugins. I'm learning Java and will return at some other time.

    YOU HAVE NO POWER HERE! :D

    I have used string commandLabel, before and it has worked fine :p

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

    BillyGalbreath

    Did you ever put the command in your plugin.yml?
     
  14. Offline

    1Rogue


    Using commandLabel will not always work, particularly with aliases. cmd.getName() is the better solution.

    As for a simple clearing text:
    Code:java
    1. StringBuilder sb = new StringBuilder();
    2. for (int i = 0; i < 75; i++) {
    3. sb.append('\n');
    4. }
    5. player.sendMessage(sb.toString());
     
  15. Offline

    Hutchmaster99

    I'm pretty sure it was in the plugin.yml. Again, I'm not making the plugin anymore.
     
  16. Offline

    MrSparkzz

    I like this, anyone else would be like "No I need to solve this now."
     
Thread Status:
Not open for further replies.

Share This Page