GlowstoneMC / Glowstone

A fast, customizable and compatible open source server for Minecraft: Java Edition
https://glowstone.net
Other
1.89k stars 272 forks source link

Use synchronizedSet #1072

Closed PayDevD closed 4 years ago

PayDevD commented 4 years ago

For issue #1071

GlowDoubleChest extends GlowSuperInventory and its field, parents' GlowInventory viewers are unmodifiable.

protected void initialize(List<GlowInventory> parents, InventoryHolder owner,
        InventoryType type, String title) {
        SuperList<GlowInventorySlot> slots = new SuperList<>();
        SuperSet<HumanEntity> viewers = new SuperSet<>();

        for (GlowInventory parent : parents) {
            slots.getParents().add(parent.getSlots());
            viewers.getParents().add(parent.getViewersSet());
        }

        initialize(slots, viewers, owner, type, title);
        this.parents = parents;
    }

However, viewers should be modifiable because openInventory logic modifies its viewers. UnmodifiableSet could occur UnsupportedOperationException. We can use synchronizedSet instead of unmodifiableSet.

claassistantio commented 4 years ago

CLA assistant check
All committers have signed the CLA.

PayDevD commented 4 years ago

@mastercoms I would appreciate if you could merge this branch. Thanks for your review!