Skip to content

feat: Adds Minecraft Run Command and Reload World on Restart Option #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
{
"command": "minecraft-debugger.minecraftReload",
"title": "Minecraft Reload"
},
{
"command": "minecraft-debugger.runMinecraftCommand",
"enablement": "inDebugMode",
"title": "Minecraft Run Command"
}
],
"keybindings": [
Expand Down
29 changes: 17 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,30 @@ export function activate(context: vscode.ExtensionContext): void {
eventEmitter.emit('run-minecraft-command', 'reload');
});

// Create a command to allow keyboard shortcuts to run Minecraft commands
const runMinecraftCommand = vscode.commands.registerCommand(
'minecraft-debugger.runMinecraftCommand',
(...args: unknown[]) => {
if (args.length === 0) {
const runMinecraftCommand = vscode.commands.registerCommand('minecraft-debugger.runMinecraftCommand', () => {
if (!vscode.debug.activeDebugSession) {
vscode.window.showErrorMessage('Error running command: No active Minecraft Debugger session.');
return;
}

vscode.window.showInputBox({
placeHolder: 'Please enter the command to run.',
value: '',
}).then(command => {
if (!command) {
vscode.window.showErrorMessage('No command provided.');
return;
}
const command = args[0]; // Use only the first argument
if (typeof command !== 'string') {
vscode.window.showErrorMessage('Command must be a string.');
return;
}

// Check for active session again in case the session closed while the prompt was open
if (!vscode.debug.activeDebugSession) {
vscode.window.showErrorMessage('Error running command: No active Minecraft Debugger session.');
return;
}

eventEmitter.emit('run-minecraft-command', command);
}
);
});
});

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