WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@DevSolaris
Copy link

@DevSolaris DevSolaris commented Jun 9, 2025

Adds PlotSquared flag to ChestShop.

The Async task is neccesary because the GlobalFlagContainer gets constructed later in PlotSquared. We load dependencies in onLoad, but the container isn't available before the onEnable in PlotSquared.

The file is called ChestshopAllowShopFlag because the name of the flag is constructed from the name of the class. There's no possibilty to override this.
The name of the flag in game is chestshop-allow-shop.

PlotSquared can be compiled from source from https://github.com/IntellectualSites/PlotSquared


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


Copy link
Member

@Phoenix616 Phoenix616 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR!

A couple of things:

  • I'm not fond of the thread sleeping to register the flag, see the comment on that for potential other approaches to solve that.
  • Generally speaking I think it would be a bit cleaner if the flag's class was an inner-class of the PlotSquared class or at least named after PlotSquared. That way it is clear from the class-name or location which plugin it belongs to. (Seeing as both classes are rather small I would definitely prefer the inner-class approach if PlotSquared is able to handle such a setup)
  • Please try to format the code like the rest of the project. It seems to be missing spaces between the keyword and the parenthesis. (It should look like if (...)) Sorry for there not being an editerconfig or similar to auto-setup that, it's on my (too long) to-do :S

Comment on lines +16 to +34
static {
// This is a workaround for the fact that PlotSquared's GlobalFlagContainer is not initialized at the time of plugin load.

ChestShop.runInAsyncThread(() -> {
com.plotsquared.core.plot.flag.GlobalFlagContainer flagContainer = com.plotsquared.core.plot.flag.GlobalFlagContainer.getInstance();

while (flagContainer == null) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
flagContainer = com.plotsquared.core.plot.flag.GlobalFlagContainer.getInstance();
if(flagContainer == null) continue;

flagContainer.addFlag(ALLOW_SHOP_FLAG_TRUE);
}
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to just use the ChestShop#loadPlugin method which is called in the onEnable instead of the ChestShop#initializePlugin method from onLoad. Or is there a reason this needs to be done in onLoad? (If so you could also just call some kind of ChestshopAllowShopFlag#enable method to run this from ChestShop#loadPlugin)

I definitely don't like this hacky approach with sleeping a thread. Even just using a listener for the PluginEnableEvent would be cleaner but running the code from ChestShop#loadPlugin would still be my preferred approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants