From 6b3f19e5881318518ab7b7741f422869c39d7616 Mon Sep 17 00:00:00 2001 From: pfyy <112098515+pfyy@users.noreply.github.com> Date: Sat, 17 Jun 2023 02:05:33 +0800 Subject: [PATCH] fix giveall doesn't give everything (#2210) * fix giveall doesn't give everything * avoid unnecessary failure to add items by catching exception earlier * switch to use grasscutter logger * use debug() --- .../grasscutter/game/inventory/Inventory.java | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/inventory/Inventory.java b/src/main/java/emu/grasscutter/game/inventory/Inventory.java index 1fd24beea..31447388d 100644 --- a/src/main/java/emu/grasscutter/game/inventory/Inventory.java +++ b/src/main/java/emu/grasscutter/game/inventory/Inventory.java @@ -133,13 +133,9 @@ public class Inventory extends BasePlayerManager implements Iterable { for (var item : items) { if (item.getItemId() == 0) continue; GameItem result = null; - try { - // putItem might throw exception - // ignore that exception and continue - result = putItem(item); - } catch (Exception e) { - e.printStackTrace(); - } + + result = putItem(item); + if (result != null) { this.triggerAddItemEvents(result); changedItems.add(result); @@ -155,22 +151,30 @@ public class Inventory extends BasePlayerManager implements Iterable { } private void triggerAddItemEvents(GameItem result) { - getPlayer() - .getBattlePassManager() - .triggerMission( - WatcherTriggerType.TRIGGER_OBTAIN_MATERIAL_NUM, result.getItemId(), result.getCount()); - getPlayer() - .getQuestManager() - .queueEvent(QuestContent.QUEST_CONTENT_OBTAIN_ITEM, result.getItemId(), result.getCount()); + try { + getPlayer() + .getBattlePassManager() + .triggerMission( + WatcherTriggerType.TRIGGER_OBTAIN_MATERIAL_NUM, result.getItemId(), result.getCount()); + getPlayer() + .getQuestManager() + .queueEvent(QuestContent.QUEST_CONTENT_OBTAIN_ITEM, result.getItemId(), result.getCount()); + } catch (Exception e) { + Grasscutter.getLogger().debug("triggerAddItemEvents failed", e); + } } private void triggerRemItemEvents(GameItem item, int removeCount) { - getPlayer() - .getBattlePassManager() - .triggerMission(WatcherTriggerType.TRIGGER_COST_MATERIAL, item.getItemId(), removeCount); - getPlayer() - .getQuestManager() - .queueEvent(QuestContent.QUEST_CONTENT_ITEM_LESS_THAN, item.getItemId(), item.getCount()); + try { + getPlayer() + .getBattlePassManager() + .triggerMission(WatcherTriggerType.TRIGGER_COST_MATERIAL, item.getItemId(), removeCount); + getPlayer() + .getQuestManager() + .queueEvent(QuestContent.QUEST_CONTENT_ITEM_LESS_THAN, item.getItemId(), item.getCount()); + } catch (Exception e) { + Grasscutter.getLogger().debug("triggerRemItemEvents failed", e); + } } public void addItemParams(Collection items) { @@ -193,8 +197,11 @@ public class Inventory extends BasePlayerManager implements Iterable { // Dont add items that dont have a valid item definition. var data = item.getItemData(); if (data == null) return null; - - this.player.getProgressManager().addItemObtainedHistory(item.getItemId(), item.getCount()); + try { + this.player.getProgressManager().addItemObtainedHistory(item.getItemId(), item.getCount()); + } catch (Exception e) { + Grasscutter.getLogger().debug("addItemObtainedHistory failed", e); + } if (data.isUseOnGain()) { var params = new UseItemParams(this.player, data.getUseTarget());