so I'm trying to do broadcast command but it sends out the command name I don't know why? if you have any idea why and how to solve this problem
package ml.harrytubestudios.helloworld.commands;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import ml.harrytubestudios.helloworld.main;
public class bro implements CommandExecutor {
private main plugins;
@Override
public boolean onCommand(CommandSender sender, Command cmd, String no, String[] args) {
Bukkit.broadcastMessage(no);
return false;
}
}
Your problems here are twofold. If you look at the documentation for CommandExecutor
; it's the same in Spigot as in Bukkit, you'll see that it says for onCommand
:
If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be sent to the player.
Because you're returning false
, you're saying that the command wasn't entered correctly and the usage string should be sent to the CommandSender
. You should return true if the command executed successfully.
However, you should still see your broadcastMessage
, which you are. This is explained again in the documentation as it says for the 3rd argument (label
):
Alias of the command which was used
This means that you are broadcasting the alias of the command (your no
parameter) that the CommandSender
used, rather than their arguments, which is what I presume you're after.
In order to get the arguments of the command used, you'll want the args
parameter which is an array of Strings. You'll probably want to format this into one string for use with your broadcast; for which there are different solutions.