Spigot/Bukkit Help : Block Manipulation

末鹿安然 提交于 2019-12-13 21:29:48

问题


I don't know why this isn't working. I tried execute it, but when I type /build, the redstone block doesn't place.

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;
 }
 }

回答1:


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.



来源:https://stackoverflow.com/questions/39204943/spigot-bukkit-help-block-manipulation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!