放置任何其他项目而不是我定义的项目时,或者从牛奶桶中喝水时,我得到一个 NPE(空指针异常)。我尝试将 isCanceled() == false 添加到我的 EventHandler 中,但它破坏了我的 RIGHT_CLICK_AIR 操作。对不起,听起来有点复杂,可以提供更多信息,提前谢谢!
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) {
Player p = event.getPlayer();
Location location = p.getLocation();
ItemStack item = event.getItem();
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasItem() != false || event.isCancelled() == true) {