问题描述
我不知道为什么这不起作用。
我尝试执行它,但是当我键入 / build
时,没有放置红石块。
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
Main.java
Main.java
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
在不了解您的设置的情况下,我可以告诉您您的 plugin.yml
设置不正确。具体来说,命令
部分。您的 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!
之前, build行:
现在,您有竞技场:
。这意味着玩家必须输入 / arena
,而不是 / build
。而且,除非我不正确,否则我认为您希望播放器键入 / build
。您可以通过
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
前两个您应该切换 onCommand
方法的参数。
The first two parameters of your onCommand
method should be switched. This:
onCommand(Command cmd, CommandSender sender, String label, String args[])
应替换为:
onCommand(CommandSender sender, Command cmd, String label, String[] args)
此外,没有理由让您检查是否输入了命令 / build
。除非您在 plugin.yml
中注册了多个命令,否则可以确定播放器输入了 / build
,否则将不会调用您的 onCommand
方法。因此,我的建议是替换此行:
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) {
此行:
if (sender instanceof Player) {
您可以通过onCommand 方法和有关Bukkit插件的更多信息。 rel = nofollow>查看插件教程维基。
You can read more about the onCommand
method and about Bukkit plugins in general by checking out the Plugin Tutorial wiki.
这篇关于Spigot / Bukkit帮助:块操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!