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
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ public void onCommandDefine(GeyserDefineCommandsEvent event) {
source.sendMessage("MCXboxBroadcast Extension " + BuildData.VERSION);
})
.build());

event.register(Command.builder(this)
.source(CommandSource.class)
.name("invite")
.description("Invite a friend to the current session.")
.executor((source, command, args) -> {
if (!source.isConsole()) {
source.sendMessage("This command can only be ran from the console.");
return;
}

if (args.length == 0) {
source.sendMessage("Usage: invite <gamertag or xuid>");
return;
}

sessionManager.inviteFriend(args[0]);
})
.build());
}

private void restart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ protected void runCommand(String command) {
String[] args = Arrays.copyOfRange(parts, offset + 1, parts.length);

try {
if (offset == 0 && commandNode.equals("invite")) {
warn("Use '/mcxboxbroadcast invite' instead");
return;
}

switch (commandNode) {
case "stop", "exit" -> System.exit(0);
case "restart" -> StandaloneMain.restart();
Expand All @@ -99,6 +104,14 @@ protected void runCommand(String command) {
default -> warn("Unknown accounts command: " + args[0]);
}
}
case "invite" -> {
if (args.length == 0) {
warn("Usage: invite <gamertag or xuid>");
return;
}

StandaloneMain.sessionManager.inviteFriend(args[0]);
}
case "version" -> info("MCXboxBroadcast Standalone " + BuildData.VERSION);
case "help" -> {
info("Available commands:");
Expand All @@ -108,6 +121,7 @@ protected void runCommand(String command) {
info("accounts list - List sub-accounts");
info("accounts add <sub-session-id> - Add a sub-account");
info("accounts remove <sub-session-id> - Remove a sub-account");
info("invite <gamertag or xuid> - Invite a friend to the current session");
info("version - Display the version");
}
default -> warn("Unknown command: " + commandNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,29 @@ public void restart() {
logger.error("No restart callback set");
}
}

/**
* Invite a friend to the current session by gamertag or XUID
*
* @param gamertagOrXuid The gamertag or XUID of the friend to invite
*/
public void inviteFriend(String gamertagOrXuid) {
try {
var friends = friendManager().lastFriendCache();
var friend = friends.stream()
.filter(f -> f.gamertag.equalsIgnoreCase(gamertagOrXuid) || f.xuid.equals(gamertagOrXuid))
.findFirst();

if (friend.isEmpty()) {
coreLogger.warn("Friend not found: " + gamertagOrXuid);
return;
}

var foundFriend = friend.get();
friendManager().sendInvite(foundFriend.xuid);
coreLogger.info("Sent invite to " + foundFriend.gamertag + " (" + foundFriend.xuid + ")");
} catch (Exception e) {
coreLogger.error("Failed to invite friend", e);
}
}
}