Fabric 玩家角色
这是一个简单的实现,允许通过类似 Discord 的“角色”为玩家分配自定义权限。 角色及其权限在 JSON 文件中定义,可以在运行时轻松修改和重载,以便快速迭代。
roles.json 文件位于配置目录中(<root>/config/roles.json)。一个示例配置可能如下所示:
{
"admin": {
"level": 100,
"overrides": {
"name_decoration": {
"style": ["red", "bold"],
"suffix": {"text": "*"}
},
"permission_level": 4,
"command_feedback": true,
"commands": {
".*": "allow"
}
}
},
"spectator": {
"level": 10,
"overrides": {
"commands": {
"gamemode (spectator|adventure)": "allow"
}
}
},
"mute": {
"level": 1,
"overrides": {
"mute": true
}
},
"everyone": {
"overrides": {
"commands": {
"help": "allow",
".*": "deny"
}
}
}
}
但这里发生了什么?这个 JSON 文件声明了三个角色:admin、spectator 和 everyone。
everyone 是默认角色:每个玩家都将拥有这个角色,且无法移除。
其他指定的角色作为对 everyone 角色的覆盖层起作用。
覆盖项
在每个角色声明中,我们列出了一组覆盖项。覆盖项是该模组用来根据角色更改游戏行为的通用系统。
目前支持的覆盖类型有 commands、name_decoration、chat_type、mute、command_feedback、permission_level 和 entity_selectors。
重要的是要考虑当多个角色针对相同内容时如何应用覆盖项。此类冲突始终通过选择具有最高级别的角色来解决。
因此,在示例的情况下:虽然 everyone 声明除了 help 之外的所有命令都不被允许,但由于 admin 和 spectator 具有更高的级别,它们将覆盖此行为。
命令
commands 覆盖项用于操纵玩家可以使用的命令。
每个覆盖项条目指定一个正则表达式模式进行匹配,然后指定当模组遇到该模式时的响应策略。
例如,模式 .* 匹配所有可能的命令,而 gamemode (spectator|adventure) 仅匹配带有 spectator 和 adventure 模式的 gamemode 命令。
随后可以与这些模式一起使用的策略有 allow 和 deny:
allow 确保允许玩家使用此命令,而 deny 则阻止玩家使用此命令。
例如:
"commands": {
"gamemode (spectator|adventure)": "allow"
}
命令覆盖项还可以利用 hidden 规则结果,这将允许使用该命令,
同时将其从命令建议中隐藏。
名称装饰
name_decoration 覆盖项修改具有特定角色的玩家名称的显示方式。这可用于覆盖名称颜色以及前置或后置文本。
其优先级低于计分板队伍颜色。
名称装饰可能声明如下:
"name_decoration": {
"prefix": {"text": "[Prefix] ", "color": "green"},
"suffix": {"text": "-Suffix"},
"style": ["#ff0000", "bold", "underline"],
"contexts": ["chat", "tab_list"]
}
可以可选地声明三个字段:
style:接受文本格式化类型列表或十六进制颜色prefix:接受在名称之前添加的文本组件suffix:接受在名称之后附加的文本组件contexts:接受一组可能的上下文,定义应在何处应用此装饰- 接受:
chat和tab_list - 默认值:适用于所有可能的上下文
- 接受:
聊天类型
chat_type 覆盖项允许替换具有特定角色的所有玩家的聊天消息装饰。
这与原版的 minecraft:chat_type 注册表集成,可以通过数据包进行修改。
chat_type 覆盖项仅声明应使用的 chat_type:
"chat_type": "minecraft:say_command"
此示例将把具有给定角色的所有消息替换为应用 say_command 样式。
需要注意的是,原版聊天类型注册表是在服务器启动时从数据包加载的,不能像玩家角色配置那样热重载。
声明自定义聊天类型
可以使用自定义数据包在 data/<namespace>/chat_type/<name> 中声明自定义聊天类型。
例如,我们可能会声明一个 data/mydatapack/chat_type/admin.json:
{
"chat": {
"decoration": {
"parameters": ["sender", "content"],
"style": {},
"translation_key": "%s: %s <- an admin said this!"
}
},
"narration": {
"decoration": {
"parameters": ["sender", "content"],
"style": {},
"translation_key": "chat.type.text.narrate"
},
"priority": "chat"
}
}
然后可以在覆盖项中引用它,例如:
"chat_type": "mydatapack:admin"
权限等级
permission_level 覆盖项设置分配给玩家的 原版权限等级。
这对于与其他模组交互以及与此模组不支持的原版功能交互非常有用。
权限等级声明如下:
"permission_level": 4
禁言
mute 覆盖项的功能非常简单,即阻止分配的玩家在聊天中输入。
禁言声明如下:
"mute": true
命令反馈
默认情况下,所有操作员在其他玩家运行命令时会收到全局反馈。
command_feedback 覆盖项允许特定角色接收这种类型的反馈。
命令反馈声明如下:
"command_feedback": true
实体选择器
通常情况下,只有权限等级为 2 或更高的命令源才能使用实体选择器。
entity_selectors 覆盖配置允许特定角色使用实体选择器。
可以像这样允许使用实体选择器:
"entity_selectors": true
其他配置
还可以通过配置文件将角色应用于命令方块或函数执行者。 例如:
{
"commands": {
"apply": {
"command_block": true,
"function": true
},
"overrides": {
}
}
}
让一个角色继承另一个角色的覆盖配置可能也很有用。
这可以通过 includes 声明实现,引用具有较低层级的其他角色。
例如:
{
"foo": {
"includes": ["bar"],
"overrides": {
"commands": {
".*": "allow"
}
}
},
"bar": {
"overrides": {
"name_decoration": {
"style": "red"
}
}
}
}
通过此配置,foo 角色将继承红色的 name_decoration。
在游戏中应用角色
修改 roles.json 文件后,你可以使用 /role reload 命令重新加载它。
所有的角色管理都通过这个 role 命令的各种子命令进行。例如:
role assign Gegy admin: 将admin角色分配给Gegyrole remove Gegy admin: 从Gegy移除admin角色role list Gegy: 列出已应用于Gegy的所有角色role reload: 重新加载roles.json配置文件
Player Roles for Fabric
This is a simple implementation allowing for custom permissions to be assigned to players via Discord-like "roles". Roles and their permissions are defined within a JSON file, which can be easily modified and reloaded at runtime for rapid iteration.
The roles.json file is located in the config directory (<root>/config/roles.json). An example configuration may look like:
{
"admin": {
"level": 100,
"overrides": {
"name_decoration": {
"style": ["red", "bold"],
"suffix": {"text": "*"}
},
"permission_level": 4,
"command_feedback": true,
"commands": {
".*": "allow"
}
}
},
"spectator": {
"level": 10,
"overrides": {
"commands": {
"gamemode (spectator|adventure)": "allow"
}
}
},
"mute": {
"level": 1,
"overrides": {
"mute": true
}
},
"everyone": {
"overrides": {
"commands": {
"help": "allow",
".*": "deny"
}
}
}
}
But what's going on here? This JSON file is declaring three roles: admin, spectator and everyone.
everyone is the default role: every player will have this role, and it cannot be removed.
The other roles that are specified function as overrides on top of the everyone role.
Overrides
Within each role declaration, we list a set of overrides. Overrides are the generic system that this mod uses to change game behavior based on roles.
Currently, the supported override types are commands, name_decoration, chat_type, mute, command_feedback, permission_level and entity_selectors.
It is important to consider how overrides are applied when multiple roles target the same things. Conflicts like this are resolved by always choosing the role with the highest level.
So, in the case of the example: although everyone declares every command except help to be disallowed, because admin and spectator have higher levels, they will override this behaviour.
Commands
The commands override is used to manipulate the commands that a player is able to use.
Each override entry specifies a regular expression pattern to match, and then a strategy for how to respond when the mod encounters that pattern.
For example, the pattern .* matches every possible command, while gamemode (spectator|adventure) would match the gamemode command only with spectator and adventure mode.
The strategies that can then be used alongside these patterns are allow and deny:
allow will make sure that the player is allowed to use this command, while deny will prevent the player from using this command.
For example:
"commands": {
"gamemode (spectator|adventure)": "allow"
}
The commands override can additionally make use of the hidden rule result, which will allow the command to be used,
while hiding it from command suggestions.
Name Decoration
The name_decoration override modifies how the names of players with a role are displayed. This can be used to override name colors as well as prepend or append text.
This has lower priority than scoreboard team colors.
Name decoration might be declared like:
"name_decoration": {
"prefix": {"text": "[Prefix] ", "color": "green"},
"suffix": {"text": "-Suffix"},
"style": ["#ff0000", "bold", "underline"],
"contexts": ["chat", "tab_list"]
}
Three fields can be optionally declared:
style: accepts a list of text formatting types or hex colorsprefix: accepts a text component that is prepended before the namesuffix: accepts a text component that is appended after the namecontexts: accepts a set of possible contexts defining where this decoration should be applied- Accepts:
chatandtab_list - Default: applies to all possible contexts
- Accepts:
Chat Types
The chat_type override allows the chat message decorations to be replaced for all players with a role.
This integrates with the Vanilla minecraft:chat_type registry, which can be altered with a datapack.
The chat_type override declares simply the chat_type that should be used:
"chat_type": "minecraft:say_command"
This example will replace all messages for players with a given role to apply the say_command style.
It is important to note that Vanilla chat type registry is loaded from the datapack on server start, and cannot be hot-reloaded like the player roles config.
Declaring custom chat types
Custom chat types can be declared with a custom datapack in data/<namespace>/chat_type/<name>.
For example, we might declare a data/mydatapack/chat_type/admin.json:
{
"chat": {
"decoration": {
"parameters": ["sender", "content"],
"style": {},
"translation_key": "%s: %s <- an admin said this!"
}
},
"narration": {
"decoration": {
"parameters": ["sender", "content"],
"style": {},
"translation_key": "chat.type.text.narrate"
},
"priority": "chat"
}
}
Which can be then referenced in an override like:
"chat_type": "mydatapack:admin"
Permission Level
The permission_level override sets the vanilla permission level for assigned players.
This is useful for interacting with other mods, as well as with vanilla features that aren't supported by this mod.
Permission level is declared like:
"permission_level": 4
Mute
The mute override functions very simply by preventing assigned players from typing in chat.
Mute is declared like:
"mute": true
Command Feedback
By default, all operators receive global feedback when another player runs a command.
The command_feedback override allows specific roles to receive this same kind of feedback.
Command feedback is declared like:
"command_feedback": true
Entity Selectors
Normally, only command sources with a permission level of two or higher can use entity selectors.
The entity_selectors override allows specific roles to use entity selectors.
Entity selectors can be allowed like:
"entity_selectors": true
Other configuration
Roles can additionally be applied to command blocks or function executors through the configuration file. For example:
{
"commands": {
"apply": {
"command_block": true,
"function": true
},
"overrides": {
}
}
}
It may also be useful for a role to inherit the overrides from another role.
This can be done with the includes declaration by referencing other roles with a lower level.
For example:
{
"foo": {
"includes": ["bar"],
"overrides": {
"commands": {
".*": "allow"
}
}
},
"bar": {
"overrides": {
"name_decoration": {
"style": "red"
}
}
}
}
With this configuration, the foo role will inherit the red name_decoration.
Applying roles in-game
Once you've made modifications to the roles.json file, you can reload it by using the /role reload.
All role management goes through this role command via various subcommands. For example:
role assign Gegy admin: assigns theadminrole toGegyrole remove Gegy admin: removes theadminrole fromGegyrole list Gegy: lists all the roles that have been applied toGegyrole reload: reloads theroles.jsonconfiguration file
下载 Player Roles
下载 Player Roles
下载 Player Roles
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Roles
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Roles
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Roles
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Roles
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Roles
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Roles
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Roles
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
暂无更新日志
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
AE2:一款流行的自动化与存储模组
模组
那是什么?一个 Waila/Hwyla 的分支。
评论 0
登录后参与评分
还没有评论,来抢沙发吧