@@ -272,69 +272,74 @@ void RegCommand()
272
272
auto action = results[" MapsEnum" ].get <std::string>();
273
273
string str = " " ;
274
274
ServerPlayer* sp = origin.getPlayer ();
275
- switch (do_hash (action.c_str ()))
276
- {
277
- case do_hash (" add" ): {
278
- auto picfile = results[" MapSoftEnum" ].get <std::string>();
279
- if (!picfile.empty ()) {
280
- auto [data, w, h] = Helper::Png2Pix (" .\\ plugins\\ CustomMapX\\ picture\\ " + picfile);
281
- if (data.size () == 0 ) return ;
282
- vector<mce::Color> Colorlist;
283
- for (int y = 0 ; y < h; y++)
284
- {
285
- for (int x = 0 ; x < w; x++)
275
+ if (sp) {
276
+ switch (do_hash (action.c_str ()))
277
+ {
278
+ case do_hash (" add" ): {
279
+ auto picfile = results[" MapSoftEnum" ].get <std::string>();
280
+ if (!picfile.empty ()) {
281
+ auto [data, w, h] = Helper::Png2Pix (" .\\ plugins\\ CustomMapX\\ picture\\ " + picfile);
282
+ if (data.size () == 0 ) return ;
283
+ vector<mce::Color> Colorlist;
284
+ for (int y = 0 ; y < h; y++)
286
285
{
287
- mce::Color img ((float )data[(y * w + x) * 4 + 0 ] / 255 , (float )data[(y * w + x) * 4 + 1 ] / 255 , (float )data[(y * w + x) * 4 + 2 ] / 255 , (float )data[(y * w + x) * 4 + 3 ] / 255 );
288
- Colorlist.push_back (img);
286
+ for (int x = 0 ; x < w; x++)
287
+ {
288
+ mce::Color img ((float )data[(y * w + x) * 4 + 0 ] / 255 , (float )data[(y * w + x) * 4 + 1 ] / 255 , (float )data[(y * w + x) * 4 + 2 ] / 255 , (float )data[(y * w + x) * 4 + 3 ] / 255 );
289
+ Colorlist.push_back (img);
290
+ }
289
291
}
290
- }
291
- auto datalist = Helper::CuttingImages (Colorlist,w, h);
292
- int xtemp = 0 ;
293
- int ytemp = 0 ;
294
- for (auto data : datalist) {
295
- auto mapitem = ItemStack::create (" minecraft:filled_map" );
296
- auto MapIndex = sp->getMapIndex ();
297
- sp->setMapIndex (MapIndex + 1 );
298
- MapItem::setMapNameIndex (*mapitem, MapIndex);
299
- auto & mapdate = Global<Level>->_createMapSavedData (MapIndex);
300
- mapdate.setLocked ();
301
- for (int x = 0 ; x < 128 ; x++)
302
- for (int y= 0 ; y < 128 ; y++) {
303
- mapdate.setPixel (data.rawColor [y + x * 128 ].toABGR (), y, x);
292
+ auto datalist = Helper::CuttingImages (Colorlist, w, h);
293
+ int xtemp = 0 ;
294
+ int ytemp = 0 ;
295
+ for (auto data : datalist) {
296
+ auto mapitem = ItemStack::create (" minecraft:filled_map" );
297
+ auto MapIndex = sp->getMapIndex ();
298
+ sp->setMapIndex (MapIndex + 1 );
299
+ MapItem::setMapNameIndex (*mapitem, MapIndex);
300
+ auto & mapdate = Global<Level>->_createMapSavedData (MapIndex);
301
+ mapdate.setLocked ();
302
+ for (int x = 0 ; x < 128 ; x++)
303
+ for (int y = 0 ; y < 128 ; y++) {
304
+ mapdate.setPixel (data.rawColor [y + x * 128 ].toABGR (), y, x);
305
+ }
306
+ mapdate.save (*Global<LevelStorage>);
307
+ MapItem::setItemInstanceInfo (*mapitem, mapdate);
308
+ auto sizetest = sqrt (datalist.size ());
309
+ mapitem->setCustomName (picfile + " -" + std::to_string (xtemp) + " _" + std::to_string (ytemp));
310
+ Level::spawnItem (sp->getPos (), sp->getDimensionId (), mapitem);
311
+ delete mapitem;
312
+ ytemp++;
313
+ if (ytemp == sizetest) {
314
+ xtemp++;
315
+ ytemp = 0 ;
304
316
}
305
- mapdate.save (*Global<LevelStorage>);
306
- MapItem::setItemInstanceInfo (*mapitem,mapdate);
307
- auto sizetest = sqrt (datalist.size ());
308
- mapitem->setCustomName (picfile +" -" + std::to_string (xtemp) + " _" + std::to_string (ytemp));
309
- Level::spawnItem (sp->getPos (), sp->getDimensionId (), mapitem);
310
- delete mapitem;
311
- ytemp++;
312
- if (ytemp == sizetest) {
313
- xtemp++;
314
- ytemp = 0 ;
315
317
}
318
+ output.success (" §l§6[CustomMapX] §aAdd Map Success!(" + std::to_string (datalist.size ()) + " )" );
316
319
}
317
- output.success (" §l§6[CustomMapX] §aAdd Map Success!(" + std::to_string (datalist.size ()) + " )" );
320
+ break ;
321
+ }
322
+ case do_hash (" reload" ): {
323
+ vector<string> out;
324
+ getAllFiles (" .\\ plugins\\ CustomMapX\\ picture" , out);
325
+ command.getInstance ()->setSoftEnum (" MapENameList" , out);
326
+ break ;
327
+ }
328
+ case do_hash (" help" ): {
329
+ output.success (
330
+ " §l§e>§6CustomMapX§e<\n "
331
+ " §b/map add §l§a<mapfile> §l§gAdd maps\n "
332
+ " §b/map reload §l§gRefresh picture path\n "
333
+ " §b/map help\n "
334
+ " §l§e>§6CustomMapX§e<" );
335
+ break ;
336
+ }
337
+ default :
338
+ break ;
318
339
}
319
- break ;
320
- }
321
- case do_hash (" reload" ): {
322
- vector<string> out;
323
- getAllFiles (" .\\ plugins\\ CustomMapX\\ picture" , out);
324
- command.getInstance ()->setSoftEnum (" MapENameList" , out);
325
- break ;
326
- }
327
- case do_hash (" help" ): {
328
- output.success (
329
- " §l§e>§6CustomMapX§e<\n "
330
- " §b/map add §l§a<mapfile> §l§gAdd maps\n "
331
- " §b/map reload §l§gRefresh picture path\n "
332
- " §b/map help\n "
333
- " §l§e>§6CustomMapX§e<" );
334
- break ;
335
340
}
336
- default :
337
- break ;
341
+ else {
342
+ output. error ( " §l§6[CustomMapX] §cYou are not in the game! " ) ;
338
343
}
339
344
});
340
345
DynamicCommand::setup (std::move (command));
0 commit comments