1010import java .util .Set ;
1111import java .util .UUID ;
1212
13- import org .bukkit .Bukkit ;
1413import org .bukkit .Location ;
1514import org .bukkit .configuration .ConfigurationSection ;
1615import org .bukkit .configuration .file .YamlConfiguration ;
1716import org .bukkit .entity .Entity ;
18- import org .bukkit .entity .Interaction ;
1917import org .bukkit .entity .Player ;
2018
2119import ict .minesunshineone .landmark .LandmarkPlugin ;
2220import ict .minesunshineone .landmark .model .Landmark ;
23- import net .kyori .adventure .text .Component ;
2421
2522public class LandmarkManager {
2623
@@ -55,9 +52,6 @@ public void createLandmark(String name, Location location, String description) {
5552 Landmark landmark = new Landmark (name , location , description , menuPosition [0 ], menuPosition [1 ]);
5653 landmarks .put (name .toLowerCase (), landmark );
5754
58- // 使用统一的方法创建实体
59- createLandmarkEntities (landmark );
60-
6155 plugin .getSLF4JLogger ().info ("成功创建锚点展示实体: {}" , name );
6256 saveData ();
6357 } catch (IllegalArgumentException | IllegalStateException e ) {
@@ -107,25 +101,6 @@ public void deleteLandmark(String name) {
107101 String lowerName = name .toLowerCase ();
108102 Landmark landmark = landmarks .get (lowerName );
109103 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-
129104 // 移除锚点数据
130105 landmarks .remove (lowerName );
131106
@@ -156,6 +131,10 @@ public void unlockLandmark(Player player, String landmarkName) {
156131 }
157132
158133 public boolean canTeleport (Player player ) {
134+ // 如果玩家有无视冷却权限,直接返回true
135+ if (player .hasPermission ("landmark.bypass.cooldown" )) {
136+ return true ;
137+ }
159138 long lastTeleport = cooldowns .getOrDefault (player .getUniqueId (), 0L );
160139 long cooldownTime = plugin .getConfigManager ().getCooldownTime () * 1000L ;
161140 return System .currentTimeMillis () - lastTeleport >= cooldownTime ;
@@ -254,19 +233,7 @@ public final void loadData() {
254233 int menuColumn = landmarkSection .getInt ("menu_column" , 1 );
255234
256235 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-
262236 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 );
270237 }
271238 } catch (IllegalArgumentException | IllegalStateException e ) {
272239 plugin .getSLF4JLogger ().error ("加载锚点 {} 时发生错误: {}" , key , e .getMessage ());
@@ -308,8 +275,6 @@ public void saveData() {
308275 Landmark landmark = entry .getValue ();
309276 landmarkSection .set ("location" , landmark .getLocation ());
310277 landmarkSection .set ("description" , landmark .getDescription ());
311- landmarkSection .set ("interaction_entity_id" , landmark .getInteractionEntityId () != null
312- ? landmark .getInteractionEntityId ().toString () : null );
313278 landmarkSection .set ("menu_row" , landmark .getMenuRow ());
314279 landmarkSection .set ("menu_column" , landmark .getMenuColumn ());
315280 }
@@ -428,68 +393,13 @@ public boolean isPlayerNearLandmark(Player player, Location landmarkLoc) {
428393 && playerLoc .distance (landmarkLoc ) <= plugin .getConfigManager ().getUnlockRadius ();
429394 }
430395
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-
463396 public void cleanup () {
464- // 清理所有实体
465- for (Landmark landmark : landmarks .values ()) {
466- removeLandmarkEntities (landmark );
467- }
468-
469397 // 清理数据结构
470398 landmarks .clear ();
471399 unlockedLandmarks .clear ();
472400 cooldowns .clear ();
473401 }
474402
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-
493403 public void updateMenuPosition (String landmarkName , int newRow , int newColumn ) {
494404 Landmark landmark = landmarks .get (landmarkName .toLowerCase ());
495405 if (landmark != null ) {
@@ -501,4 +411,17 @@ public void updateMenuPosition(String landmarkName, int newRow, int newColumn) {
501411 }
502412 }
503413 }
414+
415+ // 新增一键解锁所有锚点的方法
416+ public void unlockAllLandmarks (Player player ) {
417+ if (!player .hasPermission ("landmark.unlock.all" )) {
418+ return ;
419+ }
420+ Set <String > playerUnlocked = unlockedLandmarks .computeIfAbsent (player .getUniqueId (), k -> new HashSet <>());
421+ for (String landmarkName : landmarks .keySet ()) {
422+ playerUnlocked .add (landmarkName .toLowerCase ());
423+ }
424+ savePlayerData (player .getUniqueId ());
425+ plugin .getConfigManager ().sendMessage (player , "unlock-all-success" , "<gradient:green:aqua>✧ 魔法师解开了所有锚点的封印!</gradient>" );
426+ }
504427}
0 commit comments