MockBukkit / MockBukkit

MockBukkit is a mocking framework for Bukkit/PaperMC to allow the easy unit testing of Bukkit plugins.
https://mockbukkit.org/
MIT License
597 stars 135 forks source link

BossBar#viewers always return an empty list #1002

Closed GoodestEnglish closed 1 month ago

GoodestEnglish commented 6 months ago

Is there an existing issue for this?

Are you using the latest version of MockBukkit?

Minecraft Version

1.20

Describe the bug

So if you try to use BossBar#viewers to loop the current viewers and remove viewers from the BossBar, it doesn't produce the excepted result.

Reproducible Test

Just try to use this code to test, and you will be able to reproduce the unexcepted result.

    @Test
    void test() {
        PlayerMock player = server.addPlayer();
        BossBar bossBar = BossBar.bossBar(Component.text("hello world"),1, BossBar.Color.RED, BossBar.Overlay.PROGRESS);

        bossBar.addViewer(player);

        assertTrue(player.getBossBars().contains(bossBar)); //Passed :D

        bossBar.viewers().forEach(viewer -> {
            if (viewer instanceof Player p) {
                bossBar.removeViewer(p);
            }
        });

        assertFalse(player.getBossBars().contains(bossBar)); //Failed :(
    }

Anything else?

No response

Thorinwasher commented 5 months ago

I can reproduce this.

We need to register a service for this to work properly