I'm not 100% what you need, so I have provided two answers I believe could solve your problem, along with some extra information that might be helpful.
Listener
I believe what you are looking for is a Listener
. Here is a link to the Spigot article on how to set one up. I would take a look at it first so you know what a Listener
is, how it works, and how to add it into your code (if you don't already know).
The particular Listener
you are looking for is called PlayerInteractEvent
. It is an event that is called when a player interacts with an object. Here is the documentation.
Specific Block Check
If you simply want to check whether or not a player clicked a specific block, you can use the getClickedBlock()
and getType()
methods to do that. I have provided an example implementation of that below. The code checks to see if a player clicks on stone and then performs an action if they have.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.STONE) {
// Actions to take here
}
}
Custom Block Check
Depending on how many unique blocks you are wanting, there are a few different ways you could go about a custom block check. Based on the knowledge I currently have, I'm not 100% sure how to implement these (I just did a little research to find them), but they should suit your needs).
The first method is using a HashMap
, which allows you to store a key and a value and then access them or reference them. Here is a link on how to implement them in Spigot.
The other thing you could use is the Material
class in the Spigot API. Here are the docs for that class.