Skip to content

Commit 06cba71

Browse files
优化代码
1 parent eb42ab5 commit 06cba71

4 files changed

Lines changed: 35 additions & 28 deletions

File tree

pom.xml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,13 @@
2222
</repositories>
2323

2424
<dependencies>
25-
<!-- Folia API -->
25+
<!-- Paper 1.21 API -->
2626
<dependency>
27-
<groupId>dev.folia</groupId>
28-
<artifactId>folia-api</artifactId>
29-
<version>1.20.1-R0.1-SNAPSHOT</version>
27+
<groupId>io.papermc.paper</groupId>
28+
<artifactId>paper-api</artifactId>
29+
<version>1.21-R0.1-SNAPSHOT</version>
3030
<scope>provided</scope>
3131
</dependency>
32-
<dependency>
33-
<groupId>net.kyori</groupId>
34-
<artifactId>adventure-api</artifactId>
35-
<version>4.14.0</version>
36-
</dependency>
37-
<dependency>
38-
<groupId>net.kyori</groupId>
39-
<artifactId>adventure-text-minimessage</artifactId>
40-
<version>4.14.0</version>
41-
</dependency>
4232
</dependencies>
4333

4434
<build>

src/main/java/ict/minesunshineone/landmark/listener/PlayerListener.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/main/java/ict/minesunshineone/landmark/manager/LandmarkManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void createLandmark(String name, Location location, String description) {
101101

102102
normalizeMenuPositions();
103103

104-
plugin.getSLF4JLogger().info("成功创建锚点展示实体: {} (图标: {})", name, randomIcon.name());
104+
plugin.getSLF4JLogger().info("成功创建锚点: {} (菜单图标: {})", name, randomIcon.name());
105105
saveData();
106106
} catch (IllegalArgumentException | IllegalStateException e) {
107107
plugin.getSLF4JLogger().error("创建锚点时发生错误: {}", e.getMessage());

src/main/resources/plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: LandmarkSystem
22
version: '${project.version}'
33
main: ict.minesunshineone.landmark.LandmarkPlugin
4-
api-version: '1.20'
4+
api-version: '1.21'
55
description: '一个功能强大的锚点传送系统'
66
author: MineSunshineone
77
folia-supported: true
@@ -35,7 +35,7 @@ permissions:
3535
description: 允许打开锚点菜单
3636
default: true
3737
landmark.interact:
38-
description: 允许与锚点展示实体交互
38+
description: 允许在锚点范围内交互打开菜单
3939
default: true
4040
landmark.admin:
4141
description: 管理员权限

0 commit comments

Comments
 (0)