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 sender, Command cmd, String commandLabel, String[] 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 = 1; i < args.length; i++) message += (i > 1 ? " " : "") + args[i]; Bukkit.broadcastMessage("&5" + message); } } } return false; }}
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
@mehboss You should be getting an ArrayIndexOutOfBoundsException, because the forloop starts at 1, while the array starts at 0.
@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
@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.
@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
@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.
Why dont you use the values of the ChatColor enum instead of translating them? Btw, you imported the wrong chatColor.