Skip to content

Commit 1e533fe

Browse files
Copilotci010
andauthored
fix: Support --quickPlayMultiplayer options for newer Minecraft versions (#321)
* Initial plan * Initial exploration and planning for quickPlayMultiplayer support Co-authored-by: ci010 <[email protected]> * Implement quickPlayMultiplayer support for Minecraft launcher - Add quickPlayMultiplayer option to LaunchOption interface - Update generateArguments to handle quickPlayMultiplayer over legacy server/port options - Add createQuickPlayMultiplayer helper function for easy migration - Add comprehensive tests for new functionality - Maintain backward compatibility with existing server option Co-authored-by: ci010 <[email protected]> * Add documentation for quickPlayMultiplayer feature - Update README with usage examples for quickPlayMultiplayer option - Include helper function documentation - Show backward compatibility examples - Explain precedence when both options are provided Co-authored-by: ci010 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: ci010 <[email protected]>
1 parent a255c84 commit 1e533fe

File tree

4 files changed

+109
-10
lines changed

4 files changed

+109
-10
lines changed

packages/core/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,41 @@ Detach from the parent process. So your launcher's exit/crash won't affact the M
6666
```ts
6767
const proc: Promise<ChildProcess> = Launcher.launch({ gamePath, javaPath, version, extraExecOption: { detached: true } });
6868
```
69+
70+
#### Launching with Server Connection
71+
72+
For newer Minecraft versions, use the `quickPlayMultiplayer` option to directly connect to a server:
73+
74+
```ts
75+
import { launch, createQuickPlayMultiplayer } from "@xmcl/core"
76+
77+
// Option 1: Use quickPlayMultiplayer directly
78+
const proc = launch({
79+
gamePath,
80+
javaPath,
81+
version,
82+
quickPlayMultiplayer: 'play.hypixel.net:25565'
83+
});
84+
85+
// Option 2: Use helper function
86+
const proc = launch({
87+
gamePath,
88+
javaPath,
89+
version,
90+
quickPlayMultiplayer: createQuickPlayMultiplayer('mc.example.com', 8080)
91+
});
92+
```
93+
94+
For backward compatibility, the legacy `server` option is still supported:
95+
96+
```ts
97+
// Legacy server option (still works)
98+
const proc = launch({
99+
gamePath,
100+
javaPath,
101+
version,
102+
server: { ip: 'play.hypixel.net', port: 25565 }
103+
});
104+
```
105+
106+
**Note:** When both `quickPlayMultiplayer` and `server` options are provided, `quickPlayMultiplayer` takes precedence.

packages/core/launch.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from 'assert'
22
import { spawnSync } from 'child_process'
33
import { EOL } from 'os'
44
import * as path from 'path'
5-
import { DEFAULT_EXTRA_JVM_ARGS, generateArguments, generateArgumentsServer } from './launch'
5+
import { DEFAULT_EXTRA_JVM_ARGS, generateArguments, generateArgumentsServer, createQuickPlayMultiplayer } from './launch'
66
import { describe, test, expect } from 'vitest'
77

88
function getJavaVersion(javaPath: string) {
@@ -281,5 +281,48 @@ describe('Launcher', () => {
281281
expect(args[args.indexOf('--server') + 1]).toEqual(server.ip)
282282
expect(args[args.indexOf('--port') + 1]).toEqual(server.port.toString())
283283
})
284+
test('should generate correct command with quickPlayMultiplayer', async ({ mock }) => {
285+
const args = await generateArguments({
286+
version: '1.14.4', gamePath: mock, javaPath: '/test/java', quickPlayMultiplayer: '127.0.0.1:25565',
287+
})
288+
expect(args[args.indexOf('--quickPlayMultiplayer') + 1]).toEqual('127.0.0.1:25565')
289+
// Should not contain old server arguments
290+
expect(args.indexOf('--server')).toBe(-1)
291+
expect(args.indexOf('--port')).toBe(-1)
292+
})
293+
test('should prefer quickPlayMultiplayer over server option', async ({ mock }) => {
294+
const server = {
295+
ip: '192.168.1.1',
296+
port: 25565,
297+
}
298+
const args = await generateArguments({
299+
version: '1.14.4',
300+
gamePath: mock,
301+
javaPath: '/test/java',
302+
server,
303+
quickPlayMultiplayer: '127.0.0.1:25565',
304+
})
305+
expect(args[args.indexOf('--quickPlayMultiplayer') + 1]).toEqual('127.0.0.1:25565')
306+
// Should not contain old server arguments when quickPlayMultiplayer is present
307+
expect(args.indexOf('--server')).toBe(-1)
308+
expect(args.indexOf('--port')).toBe(-1)
309+
})
310+
})
311+
312+
describe('#createQuickPlayMultiplayer', () => {
313+
test('should create quickPlayMultiplayer string with IP only', () => {
314+
const result = createQuickPlayMultiplayer('127.0.0.1')
315+
expect(result).toEqual('127.0.0.1')
316+
})
317+
318+
test('should create quickPlayMultiplayer string with IP and port', () => {
319+
const result = createQuickPlayMultiplayer('127.0.0.1', 25565)
320+
expect(result).toEqual('127.0.0.1:25565')
321+
})
322+
323+
test('should create quickPlayMultiplayer string with custom port', () => {
324+
const result = createQuickPlayMultiplayer('play.example.com', 8080)
325+
expect(result).toEqual('play.example.com:8080')
326+
})
284327
})
285328
})

packages/core/launch.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ export interface LaunchOption {
106106
* Directly launch to a server
107107
*/
108108
server?: { ip: string; port?: number }
109+
/**
110+
* Directly launch to a server using quickPlayMultiplayer option (for newer Minecraft versions)
111+
* This will use --quickPlayMultiplayer instead of --server and --port
112+
*/
113+
quickPlayMultiplayer?: string
109114
/**
110115
* Resolution. This will add --height & --width or --fullscreen to the java arguments
111116
*/
@@ -805,7 +810,9 @@ export async function generateArguments(options: LaunchOption) {
805810
if (options.extraMCArgs) {
806811
cmd.push(...options.extraMCArgs)
807812
}
808-
if (options.server) {
813+
if (options.quickPlayMultiplayer) {
814+
cmd.push('--quickPlayMultiplayer', options.quickPlayMultiplayer)
815+
} else if (options.server) {
809816
cmd.push('--server', options.server.ip)
810817
if (options.server.port) {
811818
cmd.push('--port', options.server.port.toString())
@@ -854,3 +861,13 @@ function normalizeArguments(args: Version.LaunchArgument[], platform: Platform,
854861
return result
855862
}, [])
856863
}
864+
865+
/**
866+
* Create a quickPlayMultiplayer string from server IP and optional port
867+
* @param ip The server IP address
868+
* @param port The server port (optional, defaults to 25565 if not specified)
869+
* @returns A formatted string for quickPlayMultiplayer option
870+
*/
871+
export function createQuickPlayMultiplayer(ip: string, port?: number): string {
872+
return port ? `${ip}:${port}` : ip
873+
}

pnpm-lock.yaml

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)