@@ -186,32 +186,35 @@ Local<Value> McClass::runcmd(const Arguments& args) {
186186Local<Value> McClass::runcmdEx (const Arguments& args) {
187187 CHECK_ARGS_COUNT (args, 1 )
188188 CHECK_ARG_TYPE (args[0 ], ValueKind::kString )
189- auto origin =
190- ServerCommandOrigin (" Server" , ll::service::getLevel ()->asServer (), CommandPermissionLevel::Internal, 0 );
191- auto command = ll::service::getMinecraft ()->getCommands ().compileCommand (
192- args[0 ].asString ().toString (),
193- origin,
194- (CurrentCmdVersion)CommandVersion::CurrentVersion,
195- [](std::string const & err) {}
196- );
197- CommandOutput output (CommandOutputType::AllOutput);
198- std::string outputStr;
199- Local<Object> resObj = Object::newObject ();
200189 try {
190+ std::string outputStr;
191+ auto origin =
192+ ServerCommandOrigin (" Server" , ll::service::getLevel ()->asServer (), CommandPermissionLevel::Internal, 0 );
193+ auto command = ll::service::getMinecraft ()->getCommands ().compileCommand (
194+ args[0 ].asString ().toString (),
195+ origin,
196+ (CurrentCmdVersion)CommandVersion::CurrentVersion,
197+ [&](std::string const & err) { outputStr.append (err).append (" \n " ); }
198+ );
199+ Local<Object> resObj = Object::newObject ();
201200 if (command) {
201+ CommandOutput output (CommandOutputType::AllOutput);
202202 command->run (origin, output);
203203 for (auto msg : output.getMessages ()) {
204204 std::string temp;
205205 getI18n ().getCurrentLanguage ()->get (msg.getMessageId (), temp, msg.getParams ());
206206 outputStr += temp.append (" \n " );
207207 }
208- if (output. getMessages (). size ( )) {
208+ if (outputStr. ends_with ( ' \n ' )) {
209209 outputStr.pop_back ();
210210 }
211211 resObj.set (" success" , output.getSuccessCount () ? true : false );
212212 resObj.set (" output" , outputStr);
213213 return resObj;
214214 }
215+ if (outputStr.ends_with (' \n ' )) {
216+ outputStr.pop_back ();
217+ }
215218 resObj.set (" success" , false );
216219 return resObj;
217220 }
0 commit comments