Every scripting experience has to start with Hello World, so I decided to create a command '/hello' which sends the sender a message with 'Hello World!' in it. Well, I try to get it to work, but it doesn't. Nothing works yet, the server log says I issue the command /hello, but there is no output at all. What is the problem with my code? Thanks a lot! HelloWorld.java Code: package me.HelloWorld; import java.util.logging.Logger; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; public class HelloWorld extends JavaPlugin { Logger log = Logger.getLogger("Minecraft"); public void onEnable() { log.info("Your plugin has been enabled!"); } public void onDisable() { log.info("Your plugin has been disabled."); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (cmd.getName().equalsIgnoreCase("hello")) { sender.sendMessage("Hello World!"); return true; } return false; } } Plugin.yml Code: name: Hello World main: me.HelloWorld.HelloWorld version: 0.1 commands: hello: description: Hello World command permission: HelloWorld.hello usage: /<command>
cmd.getName() should be fine, but using the above method can be tried as well. Anyway, as a player, did you have the permission? and in the console you don't need the '/' in front of the command.
Remove the permission. If adding Permission you must do: Code: if(p.hasPermission("blah.yeah")){ //Do stuff }
I removed the permission and changed cmd.getCommand() into commandLabel, but it still doesn't work. Is there a setting I need to change? Like if there is some 'plugins: true' setting? My code right now. Code: package me.HelloWorld; import java.util.logging.Logger; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; public class HelloWorld extends JavaPlugin { Logger log = Logger.getLogger("Minecraft"); public void onEnable() { log.info("Your plugin has been enabled!"); } public void onDisable() { log.info("Your plugin has been disabled."); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (commandLabel.equalsIgnoreCase("hello")) { sender.sendMessage("Hello World!"); return true; } return false; } } Code: name: Hello World main: me.HelloWorld.HelloWorld version: 0.1 commands: hello: description: Hello World command permission: usage: /<command>
Try without the permission alltogether: Code: name: Hello World main: me.HelloWorld.HelloWorld version: 0.1 commands: hello: description: Hello World Command usage: /<command>
Also not working, wouldn't there be a critical step in installing bukkit on my localhost to enable plugins?
Plugins are loaded by bukkit, no setting. Just have it in the plugins folder and bukkit will try to load it. Only other suggestion I can make is to try this: Code:java String cmd = args[0].toString();if(cmd.equalsIgnoreCase("hello")) { sender.sendMessage("Hello World!"); return true;}
I don't know... no one think this... You need to register the command. onEnable(): getServer().getPluginCommand("command").setExecutor("class"); For example: getServer().getPluginCommand("hello").setExecutor(this); You can use 'this' if the command is in the same class as onEnable.
if (commandLabel.equalsIgnoreCase("/hello")) try this ^^^^ Could you upload the .jar for download so I could look at the EXACT code and spacing and everything? In the console (server) are there any errors given when you try /hello? If so what are the errors.
You don't have to do that if you're handling commands in your main JavaPlugin class. Are you sure your plugin is loading at all? If you type /plugins, does your plugin show up?
HelloWorld.java Code: package me.HelloWorld; import java.util.logging.Logger; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; public class HelloWorld extends JavaPlugin { Logger log = Logger.getLogger("Minecraft"); public void onEnable() { log.info("Your plugin has been enabled!"); } public void onDisable() { log.info("Your plugin has been disabled."); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (cmd.getName().equalsIgnoreCase("hello") && sender.hasPermission("HelloWorld.hello") { sender.sendMessage("Hello World!"); return true; } return false; } } Plugin.yml Code: name: Hello World main: me.HelloWorld.HelloWorld version: 0.1 commands: hello: description: Hello World command usage: /<command> permissions: HelloWorld.hello: description: This is a description default: <who gets this by default> that should work try that
I tried to test my server with another plugin, I chose the Antihunger plugin, but when I use commands of this plugin it doesn't show up anything. I think the problem is not with the coding, but with the plugin loading. What could cause this? Thanks for helping!