mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45:51 +00:00
Fix ConcurrentModificationException that occurred when reactor explodes.
CraftBukket's HumanEntity.closeInventory() apparently removes the human from the inventory's viewer list, resulting in an exception when we were calling closeInventory while iterating over the list of said viewers. Fixes TheBusyBiscuit/Slimefun4#364.
This commit is contained in:
parent
5dd53540ee
commit
393b4835d9
@ -1,8 +1,10 @@
|
||||
package me.mrCookieSlime.Slimefun.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ -415,11 +417,7 @@ public class BlockStorage {
|
||||
if (destroy) {
|
||||
if (storage.hasInventory(l)) storage.clearInventory(l);
|
||||
if (storage.hasUniversalInventory(l)) {
|
||||
UniversalBlockMenu menu = storage.getUniversalInventory(l);
|
||||
for (HumanEntity n: menu.toInventory().getViewers()) {
|
||||
n.closeInventory();
|
||||
}
|
||||
|
||||
storage.getUniversalInventory(l).close();
|
||||
storage.getUniversalInventory(l).save();
|
||||
}
|
||||
if (ticking_chunks.containsKey(l.getChunk().toString())) {
|
||||
@ -552,8 +550,9 @@ public class BlockStorage {
|
||||
|
||||
public void clearInventory(Location l) {
|
||||
BlockMenu menu = getInventory(l);
|
||||
for (HumanEntity n: menu.toInventory().getViewers()) {
|
||||
n.closeInventory();
|
||||
|
||||
for(HumanEntity human: new ArrayList<>(menu.toInventory().getViewers())) {
|
||||
human.closeInventory();
|
||||
}
|
||||
|
||||
inventories.get(l).delete(l);
|
||||
|
@ -1,7 +1,8 @@
|
||||
package me.mrCookieSlime.Slimefun.api.inventory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@ -131,9 +132,7 @@ public class BlockMenu extends ChestMenu {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
Iterator<HumanEntity> iterator = toInventory().getViewers().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
HumanEntity human = iterator.next();
|
||||
for(HumanEntity human: new ArrayList<>(toInventory().getViewers())) {
|
||||
human.closeInventory();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package me.mrCookieSlime.Slimefun.api.inventory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
|
||||
@ -89,7 +91,7 @@ public class UniversalBlockMenu extends ChestMenu {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
for (HumanEntity human: toInventory().getViewers()) {
|
||||
for(HumanEntity human: new ArrayList<>(toInventory().getViewers())) {
|
||||
human.closeInventory();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user