ScoreFixer
一个强大的 Minecraft 数据包库,可防止玩家改名后计分板数值丢失。
如有咨询,请在 Discord 上联系 @silicatYT。
下载:Modrinth
问题追踪器:GitHub
为什么需要这个?
在 Minecraft 中,分数与用户名绑定而非 UUID。因此,更改你的名称会重置你之前持有的分数(这可能会破坏数据包或导致进度丢失),任何使用你旧名称加入的玩家都可以接管你之前的分数。
ScoreFixer 解决了这个问题,让你能够自动将分数转移到新名称而不会产生冲突。
功能
- 在名称变更时,自动将特定计分板目标对象的数值转移给新玩家名称
- 使用 UUID 或特定的计分板数值(例如 ID 分数)作为选择器来读取/写入离线玩家的分数
- 事件(函数标签):
#score_fixer:changed_name、#score_fixer:joined_game和#score_fixer:left_game
使用方法
使分数在改名时转移
要使 ScoreFixer 在名称变更时自动转移目标对象(例如 "foo" 和 "bar"),请运行 /function score_fixer:util/track_objectives {Objectives:["foo", "bar"]}。
若要取消跟踪目标对象,请运行 /function score_fixer:util/untrack_objectives {Objectives:["foo", "bar"]}。
或者,你可以直接向数据存储 score_fixer:objectives List 中添加或删除 {Name:"foo"}。
访问离线玩家的分数
加载
你可以通过运行 /function score_fixer:util/load_with_uuid {UUID:...}(支持十六进制和整数数组格式)并使用其 UUID 来访问离线玩家的分数。如果找到该玩家,其数据将被复制到 score_fixer:loaded Players。从这里,你可以进行修改(调整分数值、从列表中移除目标对象以重置它们等)。
或者,你可以手动复制符合自定义条件的每个玩家的数据,如下所示:
/data modify storage score_fixer:loaded Players append from storage score_fixer:zprivate Maps[{Objectives:[{Name:"foo",Value:10}]}]
保存
在对 score_fixer:loaded Players 中的目标对象应用更改后,运行 /function score_fixer:util/save 以一次性保存所有已加载玩家的数据。
事件
#score_fixer:changed_name: 当玩家使用新名称加入时,此函数标签将作为该玩家执行。数据存储score_fixer:event Data包含Name、OldName和UUID。#score_fixer:joined_game: 当玩家加入时,此函数标签将作为该玩家执行。数据存储score_fixer:event Data包含Name和UUID。#score_fixer:left_game: 当玩家离开时,此函数标签将执行。数据存储score_fixer:event Data包含Name和UUID。
score_fixer:event Data 内部的数据也可以通过宏直接访问。
升级或卸载 ScoreFixer
- 卸载: 运行
/function score_fixer:uninstall。 - 升级:
- 卸载当前版本(保留相关数据),用新版本替换数据包,然后运行
/reload。 - (v1.2.0+) 从 v1.2.0 升级到更高版本无需先卸载当前版本。
- 卸载当前版本(保留相关数据),用新版本替换数据包,然后运行
须知
已知错误(仅限单人游戏)
- 在崩溃后立即加入单人世界时,无法检测是否经过了任何时间。因此,除非发生了名称变更,否则如果在玩家离线期间没有经过时间,加入和离开事件将不会触发。
- 在非常特殊的情况下,分数无法转移:
- 玩家(John)通过停止服务器、离开单人世界或使其崩溃而离开
- John 或另一名玩家(Steve)使用 John 的名称但大小写不同在单人世界中加入世界
- 在与上一个错误类似的条件下(但必须是不同的玩家),John 的下一次加入将无法被检测到
无法在崩溃后检测先前在线玩家的加入的原因是他们会从服务器中移除,且其 leave_game 分数未增加。这是单人游戏独有的,因为只要玩家因崩溃离开和重新加入之间至少经过 1 个刻,就可以修复此问题,这在服务器上是有保证的。
当名称仅在大写上不同时无法转移分数的原因是 /scoreboard 命令会自动将名称的大小写转换为匹配在线玩家名称的大小写。这使得无法获取或设置离线玩家的分数,如果有人使用相同名称(但大小写不同)在线。这是单人游戏独有的,因为只要玩家离开和使用相同名称但大小写不同的玩家加入之间至少经过 1 个刻,就可以修复此问题,这在服务器上是有保证的。
ScoreFixer 的注意事项
- 在玩家离线时手动设置的分数(例如
/scoreboard players set SilicatYT foo 1)如果玩家使用新名称加入,则无法转移。请改用load和save工具。- 原因:当玩家离线时,游戏对该名称不区分大小写,使得如果玩家仅更改了名称的大小写,则无法将分数从前一个名称复制到新名称。
Lantern Load
ScoreFixer 支持 Lantern Load,这是一种约定,允许你指定依赖项(包括版本)并控制数据包的运行顺序。务必确保 ScoreFixer 在你的数据包之前加载和刻执行,这样你的数据包在检查分数时,分数已经分配给了新的玩家名称。
- 让 ScoreFixer 在你的数据包之前加载和刻执行: 将 ScoreFixer 指定为 Lantern Load 的依赖项(使其优先加载),并使你的
load函数启动一个自调度的tick函数,而不是使用#minecraft:tick。 #ScoreFixer load.status: 此分数在 ScoreFixer 加载后设置一次。其值告诉你 ScoreFixer 是否已加载。负值为错误代码:- 1: ScoreFixer 正确加载且可以使用
- <unset>: ScoreFixer 无法加载(例如未安装)
- -1: 安装了多个不兼容的 ScoreFixer 版本
- -2: 尝试加载某个版本的 ScoreFixer,而之前已安装了一个更新版本且未手动卸载
- -3: 尝试加载某个版本的 ScoreFixer,而之前已安装了另一个未知版本且未手动卸载
#ScoreFixer.Version load.status: 此分数在 ScoreFixer 加载后设置一次。其值告诉你 当前安装的 ScoreFixer 版本。它是一个整数,每当进行潜在的破坏性更改时(例如行为更改、工具函数重命名等),该整数值就会递增。如果该值没有变化(例如仅进行了优化),那么任何使用 ScoreFixer 的数据包也无需进行任何更改。
致谢
来自 CMDred:
- SilicatYT
额外帮助:
- Leinad677YT (咨询与创意)
许可证
根据 MIT 许可证,只要你注明原始作品的出处,你就可以重新分发、修改和使用 ScoreFixer。
ScoreFixer
A robust Minecraft Data Pack library that prevents scoreboard values from getting lost after a player name change.
For inquiries, please contact @silicatYT on Discord.
Download: Modrinth
Issue tracker: GitHub
Why is this necessary?
In Minecraft, scores are tied to usernames rather than UUIDs. As such, changing your name resets your previously held scores (which can break Data Packs or lose progress), and anyone joining with your old name can take over your previous scores.
ScoreFixer tackles this issue and lets you automatically transfer scores to your new name without conflicts.
Features
- Automatically transfer certain scoreboard objectives' values to the new player name upon a name change
- Read/write offline players' scores using their UUID or specific scoreboard values (e.g. ID score) as selectors
- Events (function tags):
#score_fixer:changed_name,#score_fixer:joined_game&#score_fixer:left_game
How to use
Make scores transfer on name change
To make ScoreFixer automatically transfer objectives (e.g. "foo" & "bar") on name changes, run /function score_fixer:util/track_objectives {Objectives:["foo", "bar"]}.
To untrack objectives again, run /function score_fixer:util/untrack_objectives {Objectives:["foo", "bar"]}.
Alternatively, you can directly add or remove {Name:"foo"} to/from the score_fixer:objectives List data storage.
Access offline players' scores
Load
You can access offline players' scores with their UUID by running /function score_fixer:util/load_with_uuid {UUID:...} (accepts hexadecimal and int array format). If a player is found, their data is copied to score_fixer:loaded Players. From there, you can make changes (adjust score values, remove objectives from the list to reset them, etc).
Alternatively, you can manually copy data from every player that matches your custom condition like so:
/data modify storage score_fixer:loaded Players append from storage score_fixer:zprivate Maps[{Objectives:[{Name:"foo",Value:10}]}]
Save
After applying changes to the objectives in score_fixer:loaded Players, run /function score_fixer:util/save to save the data for all loaded players at once.
Events
#score_fixer:changed_name: When a player joins with a new name, this function tag is executed as that player. The data storagescore_fixer:event DatacontainsName,OldNameandUUID.#score_fixer:joined_game: When a player joins, this function tag is executed as that player. The data storagescore_fixer:event DatacontainsNameandUUID.#score_fixer:left_game: When a player leaves, this function tag is executed. The data storagescore_fixer:event DatacontainsNameandUUID.
The data inside score_fixer:event Data is also directly accessible using macros.
Upgrade or uninstall ScoreFixer
- Uninstall: Run
/function score_fixer:uninstall. - Upgrade:
- Uninstall the current version (keep the associated data), replace the Data Pack with the new version, then
/reload. - (v1.2.0+) Upgrading from v1.2.0 to a higher version can be done without uninstalling the current version first.
- Uninstall the current version (keep the associated data), replace the Data Pack with the new version, then
Good to know
Known bugs (Singleplayer exclusive)
- When joining a singleplayer world immediately after a crash, it is impossible to detect that any time has passed at all. Therefore, unless a name change happened, join and leave events will not play if no time has passed where the player was offline
- Under very specific circumstances, scores cannot carry over:
- A player (John) is leaves by stopping the server, leaving a singleplayer world or crashing it
- John or a different player (Steve) joins the world in singleplayer using John's name but different capitalization
- Under similar conditions as the previous bug (But it needs to be different players), John's next join will not be detected
The reason for not being able to detect joins of previously online players after a crash is that they will be removed from the server without their leave_game score increasing. It is singleplayer exclusive due to it being fixable as long as at least 1 tick passes between a player leaving due to a crash and them rejoining, which is guaranteed on servers.
The reason for not being able to carry over scores when names only differ in their capitalization is that /scoreboard commands automatically convert a name's capitalization to a matching online player name's capitalization. This makes it impossible to fetch or set an offline player's score if someone else with the same name (but different capitalization) is online. It is singleplayer exclusive due to it being fixable as long as at least 1 tick passes between a player leaving and a player with the same name but different capitalization joining, which is guaranteed on servers.
Caveats to ScoreFixer
- Scores manually set while the player is offline (e.g.
/scoreboard players set SilicatYT foo 1) cannot be transferred if they join with a new name. Use theloadandsaveutilities instead.- Reason: While a player is offline, the game becomes case insensitive to that name, making it impossible to copy scores from the previous name to the new name if a player only changed their name capitalization.
Lantern Load
ScoreFixer supports Lantern Load, a convention that lets you specify dependencies (incl. versions) and control the order in which Data Packs run. It is vital that ScoreFixer loads and ticks before your Data Pack, so that scores can be assigned to the new player names before your Data Pack checks them.
- Make ScoreFixer load and tick before your Data Pack: Specify ScoreFixer as a Lantern Load dependency (makes it load first), and make your
loadfunction start a self-scheduledtickfunction instead of using#minecraft:tick. #ScoreFixer load.status: This score is set once ScoreFixer loads. Its value tells you whether ScoreFixer has loaded already. Negative values are error codes:- 1: ScoreFixer loaded correctly and can be used
- <unset>: ScoreFixer could not load (e.g. not installed)
- -1: Multiple incompatible ScoreFixer versions installed
- -2: Tried to load a ScoreFixer version while a newer one was previously installed and not manually uninstalled
- -3: Tried to load a ScoreFixer version while a different unknown version was previously installed and not manually uninstalled
#ScoreFixer.Version load.status: This score is set once ScoreFixer loads. Its value tells you what ScoreFixer version is installed. It's a single integer that increments whenever a potentially breaking change is made (e.g. behaviour change, utility function renamed etc). If the value does not change (e.g. only optimizations were made), any Data Packs that use ScoreFixer should not require any changes either.
Credit
From CMDred:
- SilicatYT
Additional help:
- Leinad677YT (Consulting & ideas)
License
As per the MIT License, you are allowed to redistribute, modify and use ScoreFixer as long as you provide credit for the original work.
下载 ScoreFixer
下载 ScoreFixer
下载 ScoreFixer
下载 ScoreFixer
下载 ScoreFixer
下载 ScoreFixer
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 ScoreFixer
下载 ScoreFixer
下载 ScoreFixer
下载 ScoreFixer
注意:随着本次更新,我发现了 3 个仅影响单人游戏且影响 ScoreFixer 所有现有版本的错误。这些错误的触发条件非常具体,由于技术原因,修复它们几乎不可能,因此希望这是可以接受的。
错误修复:
- 当名称冲突时加入游戏会导致
join(加入)和leave(离开)事件被执行两次 - 在以下罕见情况下,无法检测到加入与名称变更:
- 一名玩家(John)在线后离开,但未被检测到(服务器或单人世界崩溃)
- 另一名玩家(Steve)在单人游戏中将名称改为 John 并加入世界,期间没有任何世界运行时间
更改:
- 内部代码的轻微调整
已知错误(仅限单人游戏):
- 在崩溃后立即加入单人世界时,根本无法检测到任何时间的流逝。因此,除非发生了名称变更,否则如果玩家在离线期间没有经过任何时间,
join和leave事件将不会触发 - 在非常特定的情况下,分数无法继承:
- 一名玩家(John)通过停止服务器、退出单人世界或导致其崩溃的方式离开
- John 或另一名玩家(Steve)使用 John 的名称但大小写不同,在单人游戏中加入世界
- 在与上一个错误类似的条件下(但需要是不同的玩家),John 的下一次加入将无法被检测到
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
数据包
此数据包添加了属于阿瓦里海盗的独特结构,将他们的独特风格带入你的 Minecraft 世界!兼容性:1.20 至 26.3
数据包
一个 Minecraft 光线投射库,能够精确检测玩家正在查看的方块,包括像台阶和楼梯这样的特殊方块形状。
数据包
此数据包添加了新的“祝福模式”难度。
数据包
允许服务器管理员方便地禁用 Xaero's Map 系列模组中的实体雷达、小地图等功能,使竞技游戏更加公平。
数据包
手持潜影盒时可直接打开,无需将其放置在地面上。只需按住 Shift 并右键点击即可访问你的潜影盒。
数据包
为你的 Minecraft 世界添加了超过 900 个新的进度
评论 0
登录后参与评分
还没有评论,来抢沙发吧