File tree Expand file tree Collapse file tree
src/main/java/ict/minesunshineone/landmark/listener Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import org .bukkit .Location ;
99import org .bukkit .Particle ;
1010import org .bukkit .Sound ;
11- import org .bukkit .block .Block ;
1211import org .bukkit .configuration .file .FileConfiguration ;
1312import org .bukkit .entity .Player ;
1413import org .bukkit .event .EventHandler ;
@@ -282,22 +281,19 @@ public void cleanup() {
282281
283282 @ EventHandler
284283 public void onPlayerInteract (PlayerInteractEvent event ) {
285- if (event .getAction () != Action .RIGHT_CLICK_BLOCK ) {
284+ // 只监听右键空气
285+ if (event .getAction () != Action .RIGHT_CLICK_AIR ) {
286286 return ;
287287 }
288288
289- Block block = event .getClickedBlock ();
290- if (block == null ) {
291- return ;
292- }
289+ Player player = event .getPlayer ();
293290
294- // 检查是否是锚点中心方块
291+ // 检查玩家是否在任意锚点范围内
295292 for (Landmark landmark : plugin .getLandmarkManager ().getLandmarks ().values ()) {
296- Location landmarkLoc = landmark .getLocation ();
297- if (block .getLocation ().equals (landmarkLoc )) {
298- event .setCancelled (true );
299- new LandmarkMenu (plugin , event .getPlayer ()).open ();
300- break ;
293+ if (plugin .getLandmarkManager ().isPlayerNearLandmark (player , landmark .getLocation ())) {
294+ // 在锚点范围内,打开菜单
295+ new LandmarkMenu (plugin , player ).open ();
296+ return ;
301297 }
302298 }
303299 }
You can’t perform that action at this time.
0 commit comments