From c331a7f288289f6aaaace22e05b126817597e119 Mon Sep 17 00:00:00 2001 From: iTruth <58349472+iTruth@users.noreply.github.com> Date: Fri, 21 Oct 2022 19:19:48 +0800 Subject: [PATCH] Fix IllegalStateException when execute toMap (#1879) --- .../game/props/ItemUseAction/ItemUseOpenRandomChest.java | 7 +++++-- .../java/emu/grasscutter/scripts/data/SceneBlock.java | 2 +- .../java/emu/grasscutter/scripts/data/SceneGroup.java | 8 ++++---- src/main/java/emu/grasscutter/scripts/data/SceneMeta.java | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseOpenRandomChest.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseOpenRandomChest.java index 6c391d0bb..025ead770 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseOpenRandomChest.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseOpenRandomChest.java @@ -16,10 +16,13 @@ public class ItemUseOpenRandomChest extends ItemUseInt { @Override public boolean useItem(UseItemParams params) { // cash shop material bundles - var rewardItems = params.player.getServer().getShopSystem().getShopChestData(this.i).stream().map(GameItem::new).toList(); + var data = params.player.getServer().getShopSystem().getShopChestData(this.i); + if (data == null) + return false; + var rewardItems = data.stream().map(GameItem::new).toList(); if (!rewardItems.isEmpty()) { params.player.getInventory().addItems(rewardItems, ActionReason.Shop); } - return false; + return true; } } diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneBlock.java b/src/main/java/emu/grasscutter/scripts/data/SceneBlock.java index 0f88c01c7..b5bfdca2f 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneBlock.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneBlock.java @@ -62,7 +62,7 @@ public class SceneBlock { // Set groups this.groups = ScriptLoader.getSerializer().toList(SceneGroup.class, bindings.get("groups")).stream() - .collect(Collectors.toMap(x -> x.id, y -> y)); + .collect(Collectors.toMap(x -> x.id, y -> y, (a, b) -> a)); this.groups.values().forEach(g -> g.block_id = this.id); this.sceneGroupIndex = SceneIndexManager.buildIndex(3, this.groups.values(), g -> g.pos.toPoint()); diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java b/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java index 635e3698a..93527bbc4 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java @@ -96,20 +96,20 @@ public class SceneGroup { // Set this.monsters = ScriptLoader.getSerializer().toList(SceneMonster.class, this.bindings.get("monsters")).stream() - .collect(Collectors.toMap(x -> x.config_id, y -> y)); + .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); this.monsters.values().forEach(m -> m.group = this); this.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, this.bindings.get("gadgets")).stream() - .collect(Collectors.toMap(x -> x.config_id, y -> y)); + .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); this.gadgets.values().forEach(m -> m.group = this); this.triggers = ScriptLoader.getSerializer().toList(SceneTrigger.class, this.bindings.get("triggers")).stream() - .collect(Collectors.toMap(x -> x.name, y -> y)); + .collect(Collectors.toMap(x -> x.name, y -> y, (a, b) -> a)); this.triggers.values().forEach(t -> t.currentGroup = this); this.suites = ScriptLoader.getSerializer().toList(SceneSuite.class, this.bindings.get("suites")); this.regions = ScriptLoader.getSerializer().toList(SceneRegion.class, this.bindings.get("regions")).stream() - .collect(Collectors.toMap(x -> x.config_id, y -> y)); + .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); this.regions.values().forEach(m -> m.group = this); this.init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, this.bindings.get("init_config")); diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java b/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java index 885519325..4153c9ec2 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java @@ -60,7 +60,7 @@ public class SceneMeta { } - this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b)); + this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b, (a, b) -> a)); this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle); } catch (ScriptException exception) {