Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions resources/tips.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
tips:
- 不要挖直上或直下!
- 使用!!etp back death返回死亡点
- 新人在晚上建议挖三填一
- text: "不要挖直上或直下!/n小心掉进岩浆!"
weight: 20
- text: "使用!!etp back death返回死亡点"
weight: 20
- text: "新人在晚上建议挖三填一"
weight: 50
- text: "Star Platinum!The World!"
weight: 10
command:
- "tick freeze"
- 'execute as @a unless entity @s[nbt={active_effects:[{id:"minecraft:jump_boost"}]}] run effect give @s minecraft:jump_boost 1000000 255 true'
- 'execute as @a unless entity @s[nbt={active_effects:[{id:"minecraft:slowness"}]}] run effect give @s minecraft:slowness 1000000 255 true'
- 'execute as @a unless entity @s[nbt={active_effects:[{id:"minecraft:mining_fatigue"}]}] run effect give @s minecraft:mining_fatigue 1000000 255 true'
- 'execute as @a unless entity @s[nbt={active_effects:[{id:"minecraft:weakness"}]}] run effect give @s minecraft:weakness 1000000 255 true'
- "delay 5"
- 'execute as @a[nbt={active_effects:[{id:"minecraft:jump_boost",amplifier:-1b}]}] run effect clear @s minecraft:jump_boost'
- 'execute as @a[nbt={active_effects:[{id:"minecraft:slowness",amplifier:-1b}]}] run effect clear @s minecraft:slowness'
- 'execute as @a[nbt={active_effects:[{id:"minecraft:mining_fatigue",amplifier:-1b}]}] run effect clear @s minecraft:mining_fatigue'
- 'execute as @a[nbt={active_effects:[{id:"minecraft:weakness",amplifier:-1b}]}] run effect clear @s minecraft:weakness'
- "tick unfreeze"
- 'tellraw @a {"text":"[事件] §5时间开始流动!"}'
prefix: "[事件]"
48 changes: 42 additions & 6 deletions tips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,48 @@ def send_tips():
if tips is not None:
with tLock:
while Task:
tip = random.choice(tips)
try:
tip = RText.from_json_object(tip)
except ValueError:
tip = str(tip)
psi.broadcast(RText.join(" ", [prefixRText, tip]))

# 计算权重
total_weight = sum(tip.get('weight', 0) for tip in tips)

if total_weight != 0:

# 权重分配
rand = random.randint(1, total_weight)
current = 0
selected_tip = None
commands = {}

# 抽取tip
for one_tip in tips:
current += one_tip.get('weight', 0)
if rand <= current:
selected_tip = one_tip.get('text', None)
commands = one_tip.get('command', {})
prefixRText = one_tip.get('prefix', prefixRText)
break

if selected_tip is not None:

# 执行tip附带的命令
def execute_command():
for command in commands:
# 添加命令delay的延时执行功能
if command.startswith("delay"):
delay_time = float(command.split()[1])
time.sleep(delay_time)
else:
psi.execute(command)

# 用/n分行
lines = selected_tip.split('/n')
for tip in lines:
try:
tip = RText.from_json_object(tip)
except ValueError:
tip = str(tip)
psi.broadcast(RText.join(" " if prefixRText is not "" and prefixRText is not None else "", [prefixRText if prefixRText is not None else "", tip]))
execute_command()
time.sleep(interval)


Expand Down