提问者:小点点

如何在Spigot 1.13.2的消息中返回块类型


我正在尝试获取玩家右键单击的块类型,并将其作为消息返回给游戏中的玩家。目前我一无所获。

public class BlockIdentifier extends JavaPlugin {
    public void onEnable(){
        getLogger().info("BlockIdentifier started!");
    }

    @EventHandler
    public void onInteract(PlayerInteractEvent event){
        Action action = event.getAction();
        Player player = event.getPlayer();
        Block block = event.getClickedBlock();

        if(action.equals(Action.LEFT_CLICK_BLOCK)){
            player.sendMessage(block.getType().toString());
        }

    }

    public void onDisable(){
        getLogger().info("BlockIdentifier stopped!");
    }
}

共2个答案

匿名用户

除了执行Darkilen建议的(实现侦听器)外,您还需要使用以下方法在onEnable中注册您的事件/侦听器:

getServer().getPluginManager().registerEvents​(Listener listener, Plugin plugin)

对于您的情况,这看起来像:

public void onEnable(){
    getLogger().info("BlockIdentifier started!");
    getServer().getPluginManager().registerEvents(this, this);
}

匿名用户

您忘记实现Listener

公共类BlockIdfier扩展JavaPlugin实现Listener