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!");
}
}
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);
}
您忘记了实现Listener
:
public class BlockIdentifier extends JavaPlugin implements Listener
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.