@@ -3157,11 +3157,11 @@ Local<Value> PlayerClass::getAllItems(const Arguments& args) {
31573157 Player* player = get ();
31583158 if (!player) return Local<Value>();
31593159
3160- const ItemStack& hand = player->getCarriedItem ();
3161- const ItemStack& offHand = player->getOffhandSlot ();
3162- vector<const ItemStack*> inventory = player->getInventory ().getSlots ();
3163- vector<const ItemStack*> armor = player->getArmorContainer ().getSlots ();
3164- vector<const ItemStack*> endChest = player->getEnderChestContainer ()->getSlots ();
3160+ const ItemStack& hand = player->getCarriedItem ();
3161+ const ItemStack& offHand = player->getOffhandSlot ();
3162+ std:: vector<const ItemStack*> inventory = player->getInventory ().getSlots ();
3163+ std:: vector<const ItemStack*> armor = player->getArmorContainer ().getSlots ();
3164+ std:: vector<const ItemStack*> endChest = player->getEnderChestContainer ()->getSlots ();
31653165
31663166 Local<Object> result = Object::newObject ();
31673167
@@ -3174,21 +3174,27 @@ Local<Value> PlayerClass::getAllItems(const Arguments& args) {
31743174 // inventory
31753175 Local<Array> inventoryArr = Array::newArray ();
31763176 for (const ItemStack* item : inventory) {
3177- inventoryArr.add (ItemClass::newItem ((ItemStack*)item, false ));
3177+ if (item) {
3178+ inventoryArr.add (ItemClass::newItem (const_cast <ItemStack*>(item), false ));
3179+ }
31783180 }
31793181 result.set (" inventory" , inventoryArr);
31803182
31813183 // armor
31823184 Local<Array> armorArr = Array::newArray ();
31833185 for (const ItemStack* item : armor) {
3184- armorArr.add (ItemClass::newItem ((ItemStack*)item, false ));
3186+ if (item) {
3187+ armorArr.add (ItemClass::newItem (const_cast <ItemStack*>(item), false ));
3188+ }
31853189 }
31863190 result.set (" armor" , armorArr);
31873191
31883192 // endChest
31893193 Local<Array> endChestArr = Array::newArray ();
31903194 for (const ItemStack* item : endChest) {
3191- endChestArr.add (ItemClass::newItem ((ItemStack*)item, false ));
3195+ if (item) {
3196+ endChestArr.add (ItemClass::newItem (const_cast <ItemStack*>(item), false ));
3197+ }
31923198 }
31933199 result.set (" endChest" , endChestArr);
31943200
0 commit comments