Unverified Commit be8fbcbc authored by iTruth's avatar iTruth Committed by GitHub
Browse files

Fix StackOverFlow when execute /give all (#1878)

* Fix StackOverFlow when execute /give all

* Use more proper code
parent c5d30c44
......@@ -140,7 +140,14 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
List<GameItem> changedItems = new ArrayList<>();
for (var item : items) {
if (item.getItemId() == 0) continue;
GameItem result = putItem(item);
GameItem result = null;
try {
// putItem might throws exception
// ignore that exception and continue
result = putItem(item);
} catch (Exception e) {
e.printStackTrace();
}
if (result != null) {
getPlayer().getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_OBTAIN_MATERIAL_NUM, result.getItemId(), result.getCount());
changedItems.add(result);
......
......@@ -2,6 +2,8 @@ package emu.grasscutter.game.props.ItemUseAction;
import emu.grasscutter.game.props.ItemUseOp;
import emu.grasscutter.data.GameData;
public class ItemUseGainCostume extends ItemUseInt {
@Override
public ItemUseOp getItemUseOp() {
......@@ -14,7 +16,9 @@ public class ItemUseGainCostume extends ItemUseInt {
@Override
public boolean useItem(UseItemParams params) {
params.player.getInventory().addItem(this.i); // TODO: Currently this returns false for all virtual items - need to have a proper success/fail
if (GameData.getAvatarCostumeDataMap().containsKey(this.i)) {
params.player.addCostume(this.i);
}
return true;
}
}
......@@ -2,6 +2,8 @@ package emu.grasscutter.game.props.ItemUseAction;
import emu.grasscutter.game.props.ItemUseOp;
import emu.grasscutter.data.GameData;
public class ItemUseGainFlycloak extends ItemUseInt {
@Override
public ItemUseOp getItemUseOp() {
......@@ -14,7 +16,9 @@ public class ItemUseGainFlycloak extends ItemUseInt {
@Override
public boolean useItem(UseItemParams params) {
params.player.getInventory().addItem(this.i); // TODO: Currently this returns false for all virtual items - need to have a proper success/fail
if (GameData.getAvatarFlycloakDataMap().containsKey(this.i)) {
params.player.addFlycloak(this.i);
}
return true;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment