|
10 | 10 | import java.util.Set; |
11 | 11 | import java.util.UUID; |
12 | 12 |
|
13 | | -import org.bukkit.Bukkit; |
14 | 13 | import org.bukkit.Location; |
15 | 14 | import org.bukkit.configuration.ConfigurationSection; |
16 | 15 | import org.bukkit.configuration.file.YamlConfiguration; |
17 | 16 | import org.bukkit.entity.Entity; |
18 | | -import org.bukkit.entity.Interaction; |
19 | 17 | import org.bukkit.entity.Player; |
20 | 18 |
|
21 | 19 | import ict.minesunshineone.landmark.LandmarkPlugin; |
22 | 20 | import ict.minesunshineone.landmark.model.Landmark; |
23 | | -import net.kyori.adventure.text.Component; |
24 | 21 |
|
25 | 22 | public class LandmarkManager { |
26 | 23 |
|
@@ -55,9 +52,6 @@ public void createLandmark(String name, Location location, String description) { |
55 | 52 | Landmark landmark = new Landmark(name, location, description, menuPosition[0], menuPosition[1]); |
56 | 53 | landmarks.put(name.toLowerCase(), landmark); |
57 | 54 |
|
58 | | - // 使用统一的方法创建实体 |
59 | | - createLandmarkEntities(landmark); |
60 | | - |
61 | 55 | plugin.getSLF4JLogger().info("成功创建锚点展示实体: {}", name); |
62 | 56 | saveData(); |
63 | 57 | } catch (IllegalArgumentException | IllegalStateException e) { |
@@ -107,25 +101,6 @@ public void deleteLandmark(String name) { |
107 | 101 | String lowerName = name.toLowerCase(); |
108 | 102 | Landmark landmark = landmarks.get(lowerName); |
109 | 103 | if (landmark != null) { |
110 | | - // 移除交互实体 |
111 | | - if (landmark.getInteractionEntityId() != null) { |
112 | | - Location loc = landmark.getLocation(); |
113 | | - if (loc != null && loc.getWorld() != null) { |
114 | | - // 移除交互实体 |
115 | | - Entity entity = Bukkit.getEntity(landmark.getInteractionEntityId()); |
116 | | - if (entity != null) { |
117 | | - entity.remove(); |
118 | | - } |
119 | | - |
120 | | - // 移除同位置的所有具有相同名称的交互实体 |
121 | | - loc.getWorld().getNearbyEntities(loc, 2, 2, 2).stream() |
122 | | - .filter(e -> e instanceof Interaction) |
123 | | - .filter(e -> e.customName() != null && e.customName().equals(Component.text("§e[点击打开]"))) |
124 | | - .forEach(Entity::remove); |
125 | | - } |
126 | | - landmark.setInteractionEntityId(null); |
127 | | - } |
128 | | - |
129 | 104 | // 移除锚点数据 |
130 | 105 | landmarks.remove(lowerName); |
131 | 106 |
|
@@ -254,19 +229,7 @@ public final void loadData() { |
254 | 229 | int menuColumn = landmarkSection.getInt("menu_column", 1); |
255 | 230 |
|
256 | 231 | Landmark landmark = new Landmark(key, location, description, menuRow, menuColumn); |
257 | | - String interactionId = landmarkSection.getString("interaction_entity_id"); |
258 | | - if (interactionId != null) { |
259 | | - landmark.setInteractionEntityId(UUID.fromString(interactionId)); |
260 | | - } |
261 | | - |
262 | 232 | landmarks.put(key.toLowerCase(), landmark); |
263 | | - |
264 | | - // 延迟创建实体,确保世界加载完成 |
265 | | - plugin.getServer().getRegionScheduler().runDelayed(plugin, location, task -> { |
266 | | - if (location.getWorld() != null && location.getChunk().isLoaded()) { |
267 | | - createLandmarkEntities(landmark); |
268 | | - } |
269 | | - }, 100L); |
270 | 233 | } |
271 | 234 | } catch (IllegalArgumentException | IllegalStateException e) { |
272 | 235 | plugin.getSLF4JLogger().error("加载锚点 {} 时发生错误: {}", key, e.getMessage()); |
@@ -308,8 +271,6 @@ public void saveData() { |
308 | 271 | Landmark landmark = entry.getValue(); |
309 | 272 | landmarkSection.set("location", landmark.getLocation()); |
310 | 273 | landmarkSection.set("description", landmark.getDescription()); |
311 | | - landmarkSection.set("interaction_entity_id", landmark.getInteractionEntityId() != null |
312 | | - ? landmark.getInteractionEntityId().toString() : null); |
313 | 274 | landmarkSection.set("menu_row", landmark.getMenuRow()); |
314 | 275 | landmarkSection.set("menu_column", landmark.getMenuColumn()); |
315 | 276 | } |
@@ -428,68 +389,13 @@ public boolean isPlayerNearLandmark(Player player, Location landmarkLoc) { |
428 | 389 | && playerLoc.distance(landmarkLoc) <= plugin.getConfigManager().getUnlockRadius(); |
429 | 390 | } |
430 | 391 |
|
431 | | - private void createLandmarkEntities(Landmark landmark) { |
432 | | - try { |
433 | | - Location location = landmark.getLocation(); |
434 | | - if (location.getWorld() == null || !location.getChunk().isLoaded()) { |
435 | | - return; |
436 | | - } |
437 | | - |
438 | | - // 确保位置是方块中心 |
439 | | - Location centerLoc = location.clone(); |
440 | | - centerLoc.setX(location.getBlockX() + 0.5); |
441 | | - centerLoc.setY(location.getBlockY()); |
442 | | - centerLoc.setZ(location.getBlockZ() + 0.5); |
443 | | - |
444 | | - // 创建交互实体 |
445 | | - Location interactLoc = centerLoc.clone().add(0, 0, 0); |
446 | | - Interaction interaction = location.getWorld().spawn(interactLoc, Interaction.class, entity -> { |
447 | | - entity.setInteractionWidth(3.5f); |
448 | | - entity.setInteractionHeight(2.0f); |
449 | | - entity.setPersistent(true); |
450 | | - entity.setInvulnerable(true); |
451 | | - entity.setCustomNameVisible(true); |
452 | | - entity.customName(Component.text("§e[点击打开]")); |
453 | | - entity.setGravity(false); |
454 | | - }); |
455 | | - |
456 | | - landmark.setInteractionEntityId(interaction.getUniqueId()); |
457 | | - saveData(); // 保存实体ID |
458 | | - } catch (IllegalArgumentException | IllegalStateException e) { |
459 | | - plugin.getSLF4JLogger().error("重建锚点实体时发生错误: {}", e.getMessage()); |
460 | | - } |
461 | | - } |
462 | | - |
463 | 392 | public void cleanup() { |
464 | | - // 清理所有实体 |
465 | | - for (Landmark landmark : landmarks.values()) { |
466 | | - removeLandmarkEntities(landmark); |
467 | | - } |
468 | | - |
469 | 393 | // 清理数据结构 |
470 | 394 | landmarks.clear(); |
471 | 395 | unlockedLandmarks.clear(); |
472 | 396 | cooldowns.clear(); |
473 | 397 | } |
474 | 398 |
|
475 | | - private void removeLandmarkEntities(Landmark landmark) { |
476 | | - if (landmark.getDisplayEntityId() != null) { |
477 | | - Entity entity = Bukkit.getEntity(landmark.getDisplayEntityId()); |
478 | | - if (entity != null) { |
479 | | - entity.remove(); |
480 | | - } |
481 | | - landmark.setDisplayEntityId(null); |
482 | | - } |
483 | | - |
484 | | - if (landmark.getInteractionEntityId() != null) { |
485 | | - Entity entity = Bukkit.getEntity(landmark.getInteractionEntityId()); |
486 | | - if (entity != null) { |
487 | | - entity.remove(); |
488 | | - } |
489 | | - landmark.setInteractionEntityId(null); |
490 | | - } |
491 | | - } |
492 | | - |
493 | 399 | public void updateMenuPosition(String landmarkName, int newRow, int newColumn) { |
494 | 400 | Landmark landmark = landmarks.get(landmarkName.toLowerCase()); |
495 | 401 | if (landmark != null) { |
|
0 commit comments