Commands follow the world's Allow Commands (#372)
The single-player owner was always at permission level 4. Like IntegratedServer.getProfilePermissions, the owner now gets OWNER (4) only when the world allows commands, else ALL (0): /gamemode, /give and friends answer "Unknown or incomplete command" and are not suggested (the client's tree only holds usable nodes, Commands.sendCommands). allowCommands is read from level.dat, set by World Options, and worlds made without the Create New World screen take its default (Creative only). The server console, the command harness and horizon-ctl `command` keep the owner's level. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -941,8 +941,12 @@ impl Dispatcher {
|
||||
let start = start.min(cursor);
|
||||
let truncated = &parse.input[..cursor.min(parse.input.len())];
|
||||
let mut all = Vec::new();
|
||||
// Brigadier lists every child, whatever its requirement.
|
||||
// Brigadier lists every child, but the client's tree only holds the
|
||||
// nodes the player may use (Commands.sendCommands prunes by canUse).
|
||||
for &child in &self.nodes[parent].children {
|
||||
if self.nodes[child].permission > reg.permission {
|
||||
continue;
|
||||
}
|
||||
let mut builder = SuggestionsBuilder::new(truncated, start);
|
||||
match &self.nodes[child].kind {
|
||||
NodeKind::Literal(l) => {
|
||||
|
||||
@@ -185,6 +185,34 @@ fn vanilla_error_messages() {
|
||||
assert_eq!(e.message.plain(), "argument.block.property.invalid");
|
||||
}
|
||||
#[test]
|
||||
fn commands_need_allow_commands() {
|
||||
// IntegratedServer.getProfilePermissions: the owner of a world without
|
||||
// Allow Commands is at LevelBasedPermissionSet.ALL.
|
||||
let reg = Registries {
|
||||
permission: 0,
|
||||
..reg()
|
||||
};
|
||||
let d = vanilla::game_dispatcher();
|
||||
let e = d.parse("gamemode creative", ®).executable().unwrap_err();
|
||||
assert_eq!(e.message.plain(), "command.unknown.command");
|
||||
assert!(d.parse("me waves", ®).executable().is_ok());
|
||||
let parse = d.parse("", ®);
|
||||
let root: Vec<String> = d
|
||||
.suggestions(&parse, 0, ®)
|
||||
.1
|
||||
.into_iter()
|
||||
.map(|s| s.text)
|
||||
.collect();
|
||||
// Commands.java with CommandSelection.INTEGRATED: seed and version need no level.
|
||||
assert_eq!(
|
||||
root,
|
||||
[
|
||||
"help", "list", "me", "msg", "random", "seed", "teammsg", "tell", "tm", "trigger",
|
||||
"version", "w"
|
||||
]
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn suggestions_like_vanilla() {
|
||||
let root = suggestions("");
|
||||
assert!(root.contains(&"gamemode".to_owned()) && root.contains(&"tp".to_owned()));
|
||||
|
||||
Reference in New Issue
Block a user