Skip to content

Commit 2170800

Browse files
Implemented Minecraft Run Command
1 parent 8c21d3c commit 2170800

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
{
6565
"command": "minecraft-debugger.minecraftReload",
6666
"title": "Minecraft Reload"
67+
},
68+
{
69+
"command": "minecraft-debugger.runMinecraftCommand",
70+
"enablement": "inDebugMode",
71+
"title": "Minecraft Run Command"
6772
}
6873
],
6974
"keybindings": [

src/extension.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,30 @@ export function activate(context: vscode.ExtensionContext): void {
4848
eventEmitter.emit('run-minecraft-command', 'reload');
4949
});
5050

51-
// Create a command to allow keyboard shortcuts to run Minecraft commands
52-
const runMinecraftCommand = vscode.commands.registerCommand(
53-
'minecraft-debugger.runMinecraftCommand',
54-
(...args: unknown[]) => {
55-
if (args.length === 0) {
51+
const runMinecraftCommand = vscode.commands.registerCommand('minecraft-debugger.runMinecraftCommand', () => {
52+
if (!vscode.debug.activeDebugSession) {
53+
vscode.window.showErrorMessage('Error running command: No active Minecraft Debugger session.');
54+
return;
55+
}
56+
57+
vscode.window.showInputBox({
58+
placeHolder: 'Please enter the command to run.',
59+
value: '',
60+
}).then(command => {
61+
if (!command) {
5662
vscode.window.showErrorMessage('No command provided.');
5763
return;
5864
}
59-
const command = args[0]; // Use only the first argument
60-
if (typeof command !== 'string') {
61-
vscode.window.showErrorMessage('Command must be a string.');
62-
return;
63-
}
65+
66+
// Check for active session again in case the session closed while the prompt was open
6467
if (!vscode.debug.activeDebugSession) {
6568
vscode.window.showErrorMessage('Error running command: No active Minecraft Debugger session.');
69+
return;
6670
}
71+
6772
eventEmitter.emit('run-minecraft-command', command);
68-
}
69-
);
73+
});
74+
});
7075

7176
const liveDiagnosticsCommand = vscode.commands.registerCommand('minecraft-debugger.liveDiagnostics', () => {
7277
MinecraftDiagnosticsPanel.render(context.extensionUri, liveStatsProvider);

0 commit comments

Comments
 (0)