Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per player display shared between players #160

Open
BeefDev opened this issue Jun 10, 2023 · 2 comments
Open

Per player display shared between players #160

BeefDev opened this issue Jun 10, 2023 · 2 comments
Labels
A. bug Issue is caused by a bug in BKCommonLib

Comments

@BeefDev
Copy link

BeefDev commented Jun 10, 2023

BkCommonLib version: 1.19.4-v2
Spigot version: 1.19.4

Problem or bug: When spawning a map inside an item frame (with the display set to be non global) the map display is shared between players that view the map when it's spawned. If only one players views the map when it's spawned and the others come near it later, it works as expected and creates a new instance of the map display. (Theres a video)

Code

public final class TestMapDisplay extends MapDisplay {

    private static int COUNTER = 1;

    private final int id;

    public TestMapDisplay() {
        this.id = COUNTER++;
    }

    @Override
    public void onAttached() {
        this.setGlobal(false);
        this.getLayer().fill(MapColorPalette.COLOR_WHITE);
        this.getLayer().next().draw(MapFont.MINECRAFT, 10, 10, MapColorPalette.COLOR_RED, String.valueOf(this.id));
    }
}
ItemFrame frame = (ItemFrame) rayTraceResult.getHitEntity();
frame.setItem(MapDisplay.createMapItem(this, TestMapDisplay.class));

Expected behaviour: A different instance is created for all players near the map

Steps to reproduce: Make a map display which is not global and draws something unique to each instance on the map, then spawn it in an item frame next to multiple players.

@bbayu123
Copy link
Collaborator

I want to check something with you.
I want to make sure it's not a race condition messing things up, where both instances try to update the counter at the same time, and just happened to get the same value (it's a common concurrent issue)
Try replacing the counter with an atomic integer (from java.util.concurrent.atomic.AtomicInteger), so it looks like

private static AtomicInteger COUNTER = new AtomicInteger(1);

public TestMapDisplay() {
    this.id = COUNTER.getAndIncrement();
}

@bbayu123 bbayu123 added the A. invalid Issue is invalid or does not exist label Jun 10, 2023
@BeefDev
Copy link
Author

BeefDev commented Jun 11, 2023

Tested this just incase but the issue still happens. Before submitting I had also tested different displays (like drawing stuff on click, printing the viewers onTick() and other stuff). I can assure you it's the same display. (Also sorry for the late response)

@bbayu123 bbayu123 added A. bug Issue is caused by a bug in BKCommonLib and removed A. invalid Issue is invalid or does not exist labels Jun 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A. bug Issue is caused by a bug in BKCommonLib
Projects
None yet
Development

No branches or pull requests

2 participants