How do I create a plugin where you do a command and it gives you a message, That's all! It just gives the player a message with a color like chatcolor.GOLD + ("Message") how would I make this?
Code:java public boolean onCommand(CommandSender Sender, Command command, String commandLabel, String[] args){if(command.getName().equalsIgnoreCase("hello")){Sender.sendMessage(ChatColor.GREEN + "Hello!!"); }return true;}}
Famous Guy PHP: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {if(cmd.getName().equalsIgnoreCase("command")) {sender.sendMessage(ChatColor.GOLD + "MESSAGE");}}
Yes. thats correct. But one thing i saw. You have plugin.yml in the wrong place. you have to right click at the project file, not the package, to make the file
name: Sweg version: 1.0 main: me.Famous_Guy2.Sweg.Sweg description: a plugin commands: test: description: thx for testing
Code: name: sweg version: 1.0 main: me.Famous_Guy2.Sweg description: a plugin commands: test: usage: /<command> description: a test command. This is how your plugin.yml should be. You need to MAKE SURE that you are not "tabbing" when you use spaces in YAML configuration. You need to do 4 spaces per tab, otherwise it won't work!
You don't need on enable or ondisable methods unless you need to register events or call methods in onEnable() or onDisable(). In this case he just has commands so that isn't necessary. That's why I go on these forums. I help others and learn more stuffs in the process . EDIT: Sorry for the double post :/ EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Here: Code:java package me.cruz2000; 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 MyFirstPlugin extends JavaPlugin { @Override public void onEnable() { getLogger().info("Hello Youtube! onEnable has been enabled!"); } @Override public void onDisable() { } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player) { Player player = (Player) sender; player.sendMessage(ChatColor.GOLD + "Hello"); return true; } return false; } }
Are you sure about that, cause I had the same problem once, but it got fixed when I added the onEnable and onDisable methods...
I'm very sure that onEnable and onDisable methods aren't needed. In earlier versions of bukkit (about a year ago) it was a necessity, but it isn't needed anymore.
It doesn't matter if things return false or true when using a command Boolean method. But just so you know... the original poster already had his problem solved.
what? You return the success of handling the command. If you handled it correctly or as intended, then you return true.