Spigot/Bukkit 帮助:块操作

Spigot/Bukkit Help : Block Manipulation

我不知道为什么这不起作用。 我尝试执行它,但是当我输入 /build 时,红石块没有放置。

plugin.yml

name: SkinStandoff
version: 0.1
main: com.sumeshdesh.skinstandoff.SkinStandoff
commands:
   arena:
    usage: /build

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 设置不正确。具体来说,commands 部分。您的 plugin.yml 可能看起来像这样:

name: SkinStandoff
version: 0.1
main: com.sumeshdesh.skinstandoff.SkinStandoff
commands:
    build:
        usage: Type /build to place the block!

以前,build: 行现在是 arena:。这意味着玩家必须输入 /arena,而不是 /build。而且,除非我错了,否则我认为您希望玩家输入 /build。您可以通过 checking out the Plugin YAML wiki.

阅读有关设置 plugin.yml 的更多信息

onCommand

您的 onCommand 方法的前两个参数应该互换。这个:

onCommand(Command cmd, CommandSender sender, String label, String args[])

应替换为:

onCommand(CommandSender sender, Command cmd, String label, String[] args)

此外,您没有理由检查是否输入了命令 /build。除非你在plugin.yml中注册了多个命令,否则你可以确定玩家输入了/build,否则你的onCommand方法不会被调用。所以,我的建议是替换这一行:

if (cmd.getName().equalsIgnoreCase("build") && sender instanceof Player) {

这一行:

if (sender instanceof Player) {

您可以通过 checking out the Plugin Tutorial wiki.

阅读更多关于 onCommand 方法和 Bukkit 插件的一般信息