@@ -279,26 +279,43 @@ public void cleanup() {
279279 lastCheckTimes .clear ();
280280 }
281281
282- @ EventHandler (priority = EventPriority .LOWEST )
282+ @ EventHandler (priority = EventPriority .NORMAL )
283283 public void onPlayerInteract (PlayerInteractEvent event ) {
284284 Action action = event .getAction ();
285285 Player player = event .getPlayer ();
286286
287- // 检查是否是左键动作,并且点击的是空气(不要问为什么不右键,因为右键的事件好像有问题)
288- if (action == Action .LEFT_CLICK_AIR ) {
287+ // 检查是否是右键空气或左键空气
288+ if (action == Action .RIGHT_CLICK_AIR || action == Action . LEFT_CLICK_AIR ) {
289289 // 检查权限
290290 if (!player .hasPermission ("landmark.menu" )) {
291291 return ;
292292 }
293293
294- // 检查玩家是否在任意锚点范围内
295- for (Landmark landmark : plugin .getLandmarkManager ().getLandmarks ().values ()) {
296- if (plugin .getLandmarkManager ().isPlayerNearLandmark (player , landmark .getLocation ())) {
297- // 在锚点范围内,打开菜单
298- plugin .getServer ().getRegionScheduler ().execute (plugin , player .getLocation (), () -> {
299- new LandmarkMenu (plugin , player ).open ();
300- });
301- return ;
294+ // 检查玩家手上是否为空(避免与使用物品冲突)
295+ if (action == Action .RIGHT_CLICK_AIR && player .getInventory ().getItemInMainHand ().getType ().isAir ()
296+ && player .getInventory ().getItemInOffHand ().getType ().isAir ()) {
297+
298+ // 检查玩家是否在任意锚点范围内
299+ for (Landmark landmark : plugin .getLandmarkManager ().getLandmarks ().values ()) {
300+ if (plugin .getLandmarkManager ().isPlayerNearLandmark (player , landmark .getLocation ())) {
301+ // 在锚点范围内,打开菜单
302+ event .setCancelled (true ); // 取消事件以防止其他交互
303+ plugin .getServer ().getRegionScheduler ().execute (plugin , player .getLocation (), () -> {
304+ new LandmarkMenu (plugin , player ).open ();
305+ });
306+ return ;
307+ }
308+ }
309+ } else if (action == Action .LEFT_CLICK_AIR ) {
310+ // 左键空气也可以打开(作为备用)
311+ for (Landmark landmark : plugin .getLandmarkManager ().getLandmarks ().values ()) {
312+ if (plugin .getLandmarkManager ().isPlayerNearLandmark (player , landmark .getLocation ())) {
313+ // 在锚点范围内,打开菜单
314+ plugin .getServer ().getRegionScheduler ().execute (plugin , player .getLocation (), () -> {
315+ new LandmarkMenu (plugin , player ).open ();
316+ });
317+ return ;
318+ }
302319 }
303320 }
304321 }
0 commit comments