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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ picked_up, used, mined, broken, crafted 的 <统计内容> 为物品/方块id

custom 的 <统计内容> 详见统计信息的json文件,或 [MC Wiki](https://minecraft.fandom.com/zh/wiki/%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF)

上述内容无需带minecraft前缀
上述内容可省略 `minecraft:` 前缀

[<-uuid>]: 用uuid替换玩家名; (-bot): 统计bot与cam; [<-tell>]: 仅自己可见

Expand Down
4 changes: 3 additions & 1 deletion stats_helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ def build_scoreboard(source: CommandSource, cls: str, target: str, title: Option
title = get_display_text(cls, target)
else:
title = RTextBase.from_any(title)
server.execute('scoreboard objectives add {} minecraft.{}:minecraft.{} {}'.format(constants.ScoreboardName, cls, target, title.to_json_str()))
cls_name = "minecraft." + cls if ":" not in cls else cls.replace(":", ".")
target_name = "minecraft." + target if ":" not in target else target.replace(":", ".")
server.execute('scoreboard objectives add {} {}:{} {}'.format(constants.ScoreboardName, cls_name, target_name, title.to_json_str()))
for name, uuid in player_list:
value = utils.get_stat_data(uuid, cls, target)
if value is not None:
Expand Down
6 changes: 4 additions & 2 deletions stats_helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def isBot(name: str):
def get_stat_data(uuid: str, cls: str, target: str) -> Optional[int]:
try:
with open(os.path.join(Config.get_instance().get_world_path(), 'stats', uuid + '.json'), 'r') as f:
target_data: Dict[str, int] = json.load(f)['stats']['minecraft:' + cls]
cls_name = "minecraft:" + cls if ":" not in cls else cls
target_data: Dict[str, int] = json.load(f)['stats'][cls_name]
if target == constants.AllTargetTag:
return sum(target_data.values())
return target_data['minecraft:' + target]
target_name = "minecraft:" + target if ":" not in target else target
return target_data[target_name]
except:
return None

Expand Down