[MD]
```yaml
DarkSouls_AutoClose_Door:
type: world
events:
# 监听玩家右键点击铁门
on player right clicks iron_door:
# 阻止原版的交互事件(防止其他插件冲突)
- determine passively cancelled
# 获取被点击的门的坐标
- define door_loc <context.location>
# 【防连点判定】:如果门已经是开着的状态(switched 为 true),则直接停止脚本,什么也不做
- if <[door_loc].material.switched>:
- stop
# ==========================
# 1. 执行开门逻辑
# ==========================
# 强制将门的状态设为开启
- switch <[door_loc]> state:on
# 播放黑魂那种沉重的开门音效 (pitch 小于 1 会让声音变低沉)
- playsound <[door_loc]> sound:BLOCK_IRON_DOOR_OPEN pitch:0.6 volume:1.0
# 在玩家快捷栏上方提示
- actionbar "<&7>机关门已开启..." targets:<player>
# ==========================
# 2. 延时等待 (自动关门的核心)
# ==========================
# 等待 3 秒 (你可以根据需要改成 5s, 10s 等)
- wait 3s
# ==========================
# 3. 执行关门逻辑
# ==========================
# 安全校验:确保这 3 秒内门没有被破坏或变成其他方块
- if <[door_loc].material.name> == iron_door:
# 强制将门的状态设为关闭
- switch <[door_loc]> state:off
# 播放沉重的关门音效
- playsound <[door_loc]> sound:BLOCK_IRON_DOOR_CLOSE pitch:0.5 volume:1.0
```
[/MD]