I don't know why this isn't working. I tried execute it, but when I type /build
, the redstone block doesn't place.
name: SkinStandoff
version: 0.1
main: com.sumeshdesh.skinstandoff.SkinStandoff
commands:
arena:
usage: /build
public class SkinStandoff extends JavaPlugin implements Listener {
public boolean onCommand(Command cmd, CommandSender sender, String label, String args[]) {
if (cmd.getName().equalsIgnoreCase("build") && sender instanceof Player) {
Player player = (Player) sender;
Location start;
Block bEnd;
Location end;
start = player.getLocation();
end = start.add(3, -1, 3);
bEnd = end.getBlock();
getLogger().info(bEnd.toString());
bEnd.setType(Material.REDSTONE_BLOCK);
return true;
}
return false;
}
}
plugin.yml
Without knowing anything more about your setup, I can tell you that your plugin.yml
was set up incorrectly. Specifically, the commands
section. Your plugin.yml
should probably look something like this:
name: SkinStandoff
version: 0.1
main: com.sumeshdesh.skinstandoff.SkinStandoff
commands:
build:
usage: Type /build to place the block!
Before, where the line build:
is now, you had arena:
. This meant that player would have to type /arena
, instead of /build
. And, unless I'm incorrect, I think you expect the player to type /build
. You can read more about setting up your plugin.yml
by checking out the Plugin YAML wiki.
onCommand
The first two parameters of your onCommand
method should be switched. This:
onCommand(Command cmd, CommandSender sender, String label, String args[])
should be replaced with:
onCommand(CommandSender sender, Command cmd, String label, String[] args)
Also, there's no reason for you to check if the command /build
was entered. Unless you've registered more than one command in your plugin.yml
, you can be certain that the player entered /build
, otherwise your onCommand
method wouldn't have been called. So, my suggestion is to replace this line:
if (cmd.getName().equalsIgnoreCase("build") && sender instanceof Player) {
with this line:
if (sender instanceof Player) {
You can read more about the onCommand
method and about Bukkit plugins in general by checking out the Plugin Tutorial wiki.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.