Me command

Discussion in 'Plugin Development' started by mehboss, Oct 20, 2016.

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

    mehboss

    sigh..

    I think you can guess what I am trying to do, everytime I do /me test it doesn't broadcast "test" or anything, it just says &5 in chat lol...

    CODE:
    PHP:
    package me.mehboss.rockclasses;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;

    import net.md_5.bungee.api.ChatColor;

    public class 
    MeCommand implements CommandExecutor {

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

            if (
    cmd.getName().equalsIgnoreCase("me")) {
                if (
    args.length == 0) {
                    
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&'"&cInvalid Args! Use /me <message>"));
                } else if (
    args.length == 1) {
                        
    String message "";

                        for (
    int i 1args.lengthi++)
                            
    message += (" " "") + args[i];
                        
    Bukkit.broadcastMessage("&5" message);
                    }
                }
            }
            return 
    false;
        }
    }
     
  2. Offline

    xXJustiinXx

    If your command is /me la la la then it doesn´t work, because its never going to the else if because args.length is > 1 not == 1

    And if you´re doing /me test , args is 1 thats true, but in the for you´re doing i = 1; i < args.lenght which is 1 so its not going into the for loop
     
  3. Offline

    mehboss

  4. @mehboss
    You should be getting an ArrayIndexOutOfBoundsException, because the forloop starts at 1, while the array starts at 0.
     
  5. Offline

    xXJustiinXx

    someone was faster

    Edit: the & must be § this will color your messages then
     
  6. Offline

    mehboss

    so change that part to
    Code:
    int i = 0
    ?
     
  7. @mehboss
    Yes. But are you actually getting an ArrayIndexOutOfBoundsException in the console?
     
  8. Offline

    mehboss

    @xXJustiinXx @AlvinB
    I have changed to translate the color codes ;)

    nope only thing in console is:
    PHP:
    [22:59:32 INFO]: Mr_Boss_Man issued server command: /me t
    [22:59:32 INFO]: &5
     
  9. @mehboss
    Actually nevermind, the exception should not be thrown, as the forloop never fires because the boolean condition is always false. Just change the int to 0 instead of 1 and everything should work.
     
  10. Offline

    mehboss

    @AlvinB

    haha, thanks.

    UPDATE:
    Alright new problem..
    Only the first argument works, the rest do not..


    CONSOLE:
    Code:
    [23:12:24 INFO]: Mr_Boss_Man issued server command: /me test
    [23:12:24 INFO]:  Mr_Boss_Man: test
    //the first arg that is working. ^
    
    [23:12:25 INFO]: Mr_Boss_Man issued server command: /me test test
    //second arg (not working) ^
    
    [23:12:26 INFO]: Mr_Boss_Man issued server command: /me test test test
    //third arg (not working) ^
    //ect
    
    @Zombie_Striker
    Anything? You seem to be good at coding, could you please help. ~ thanks
     
    Last edited: Oct 20, 2016
  11. @mehboss
    Well, in the else statement you check if args.length is equal to 1, which it won't be if you put multiple arguments. Remove the if from the else statement and everything should work just fine.

    Also, something to keep in mind so you can solve these problems by yourself is that you read what your code does. Go through each line with the specific arguments you put in, and you would notice errors such as this one.
     
    mehboss likes this.
  12. Offline

    Lordloss

    Why dont you use the values of the ChatColor enum instead of translating them? Btw, you imported the wrong chatColor.
     
    mehboss likes this.
  13. Offline

    mehboss

    @Lordloss
    Whoopsy, meant to import bukkit's chat color :p
    thanks

    thanks
     
Thread Status:
Not open for further replies.

Share This Page