Thernandez
Thernandez

Reputation: 23

How to return block type in a message for Spigot 1.13.2

I'm attempting to get the block type that is right clicked by the player and return it back as a message sent to the player in-game. Currently i'm getting absolutely nothing.

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!");
    }
}

Upvotes: 2

Views: 188

Answers (2)

Rishaan Gupta
Rishaan Gupta

Reputation: 563

As well as doing what Darkilen suggested (implementing Listener) you need to register your events/listener in your onEnable using:

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

For your case, this would look like:

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

Upvotes: 3

Darkilen
Darkilen

Reputation: 571

You forgot to implements Listener :

public class BlockIdentifier extends JavaPlugin implements Listener

Upvotes: 1

Related Questions