UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

116 lines (115 loc) 5.38 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Log_1 = __importDefault(require("../core/Log")); const CommandRegistry_1 = __importStar(require("./CommandRegistry")); const ICommand_1 = require("./ICommand"); class CreatorToolsCommands { static async debugProjectInformation(context, name, args) { if (!context.project) { return { status: ICommand_1.CommandStatus.invalidArguments }; } let message = "N: " + context.project.name; if (context.project.projectFolder) { message += " PF: " + context.project.projectFolder.fullPath; } Log_1.default.message(message); return { status: ICommand_1.CommandStatus.completed }; } static async debugMinecraft(context, name, args) { let message = "LAM: " + context.creatorTools.lastActiveMinecraftFlavor; if (context.creatorTools.remoteServerUrl) { message += " RSURL: " + context.creatorTools.remoteServerUrl; } if (context.creatorTools.remoteServerPort) { message += " RSP: " + context.creatorTools.remoteServerPort; } if (context.creatorTools.dedicatedServerMode) { message += " DSM: " + context.creatorTools.dedicatedServerMode; } if (context.creatorTools.dedicatedServerPath) { message += " DSP: " + context.creatorTools.dedicatedServerPath; } if (context.creatorTools.dedicatedServerSlotCount) { message += " DSS: " + context.creatorTools.dedicatedServerSlotCount; } Log_1.default.message(message); return { status: ICommand_1.CommandStatus.completed }; } static async startMinecraft(context, name, args) { if (!context.minecraft && !context.creatorTools.lastActiveMinecraftFlavor) { return { status: ICommand_1.CommandStatus.invalidEnvironment }; } let mc = context.minecraft; if (!mc && context.creatorTools.lastActiveMinecraftFlavor) { mc = context.creatorTools.ensureMinecraft(context.creatorTools.lastActiveMinecraftFlavor); } if (!mc) { return { status: ICommand_1.CommandStatus.invalidEnvironment }; } Log_1.default.message("Starting server."); await mc.prepareAndStart({ project: context.project, }); return { status: ICommand_1.CommandStatus.completed }; } static async stopMinecraft(context, name, args) { if (!context.minecraft) { return { status: ICommand_1.CommandStatus.invalidEnvironment }; } Log_1.default.message("Stopping server."); await context.minecraft.stop(); return { status: ICommand_1.CommandStatus.completed }; } static async updateMinecraft(context, name, args) { if (context.minecraft) { context.minecraft.prepare(true); } return { status: ICommand_1.CommandStatus.completed }; } static registerCommonCommands() { CommandRegistry_1.default.main.registerCommand("dbgproj", CommandRegistry_1.CommandScope.debug, CreatorToolsCommands.debugProjectInformation); CommandRegistry_1.default.main.registerCommand("dbgmc", CommandRegistry_1.CommandScope.debug, CreatorToolsCommands.debugMinecraft); CommandRegistry_1.default.main.registerCommand("startmc", CommandRegistry_1.CommandScope.any, CreatorToolsCommands.startMinecraft); CommandRegistry_1.default.main.registerCommand("stopmc", CommandRegistry_1.CommandScope.minecraft, CreatorToolsCommands.stopMinecraft); CommandRegistry_1.default.main.registerCommand("updatemc", CommandRegistry_1.CommandScope.minecraft, CreatorToolsCommands.updateMinecraft); } } exports.default = CreatorToolsCommands;