Skip to content

Commit

Permalink
4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alex3236 authored May 10, 2021
1 parent b738f89 commit da15dfe
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions daycount.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
# -----------------------------------------
nbt_file = 'server/world/level.dat' # NBT 文件位置,设置为 -1 以使用日期模式
start_date = '2021-01-01' # 开服日期
day_text = '这是服务器开服的第 $day 天' # 显示文字
# -----------------------------------------

PLUGIN_METADATA = {
'id': 'daycount_nbt',
'version': '4.0',
'version': '4.1',
'name': 'DayCount-NBT',
'description': '通过读取 NBT 文件,获取服务器总运行时间。',
'author': 'Alex3236',
Expand All @@ -18,18 +19,18 @@

def getday():
try:
global nbt_file, start_date
if isinstance(nbt_file, str):
import nbtlib
return floor(nbtlib.load(nbt_file)['']['Data']['Time'] / 1728000)
return (datetime.now() - datetime.strptime(start_date, '%Y-%m-%d')).days
except Exception:
return 0

def get_day_text():
return day_text.replace('$day', str(getday()))

def display_days(source: CommandSource):
source.reply(f'这是服务器开服的第 {getday()} 天')

source.reply(get_day_text())

def on_load(server: ServerInterface, old):
server.register_command(Literal('!!day').runs(display_days))
Expand Down

0 comments on commit da15dfe

Please sign in to comment.