Skip to content

Commit e77d186

Browse files
add playerIndex option to spawn command (#2808)
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
1 parent 5865b5c commit e77d186

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/server/command/_command.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub const Target = struct {
102102
source.sendMessage("#ff0000Too few arguments for command", .{});
103103
return error.TooFewArguments;
104104
};
105-
if (userIndex[0] == '@') {
105+
if (userIndex.len > 0 and userIndex[0] == '@') {
106106
const user = parsePlayerIndexAndIncreaseRefCount(userIndex, source) catch return error.InvalidArgs;
107107
increasedRefCount = true;
108108
_ = split.next();

src/server/command/spawn.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ const User = main.server.User;
55

66
const command = @import("_command.zig");
77

8-
pub const description = "Get or set the player / world spawn point";
8+
pub const description = "Get or set a player's / the world spawn point";
99
pub const usage =
1010
\\/spawn
1111
\\/spawn <x> <y> <z>
12+
\\/spawn @<playerIndex>
13+
\\/spawn @<playerIndex> <x> <y> <z>
1214
\\/spawn world
1315
\\/spawn world <x> <y> <z>
1416
;
1517

1618
pub fn execute(args: []const u8, source: *User) void {
1719
var split = std.mem.splitScalar(u8, args, ' ');
18-
if (split.peek().?.len > 0) {
20+
const target = command.Target.init(&split, source) catch return;
21+
defer target.deinit();
22+
if (split.peek() != null and split.peek().?.len > 0) {
1923
if (std.mem.eql(u8, split.peek().?, "world")) {
2024
_ = split.next();
2125
if (split.peek() == null or split.peek().?.len == 0) {
@@ -38,8 +42,8 @@ pub fn execute(args: []const u8, source: *User) void {
3842
source.sendMessage("#ff0000Too many arguments for command /spawn", .{});
3943
return;
4044
}
41-
source.spawnPos = pos;
45+
target.user.spawnPos = pos;
4246
} else {
43-
source.sendMessage("#ffff00{}", .{source.getSpawnPos()});
47+
source.sendMessage("#ffff00{}", .{target.user.getSpawnPos()});
4448
}
4549
}

0 commit comments

Comments
 (0)