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

Use modules instead of moduleInstances.values() to access modules #5069

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PoTheMagicDragon
Copy link

Type of change

  • Bug fix
  • New feature

Description

A rework of #5026 due to mangled git history

Related issues

N/A

How Has This Been Tested?

Running an instance and making sure that modules load correctly

Checklist:

  • My code follows the style guidelines of this project.
  • I have added comments to my code in more complex areas.
  • I have tested the code in both development and production environments.

@RacoonDog
Copy link
Contributor

rather than calling

if (modules.removeIf(module1 -> {
    if (module1.name.equals(module.name)) ...
})) {
    getGroup(...).remove(...);
}

if (moduleInstances.values().removeIf(module1 -> {
    if (module1.name.equals(module.name)) ...
})) {
    getGroup(...).remove(...);
}

it should be safe to assume that, since the moduleInstances map should always be a subset of modules, we can simplify it as so:

AtomicReference<Module> removedModule = new AtomicReference<>();
if (modules.removeIf(module1 -> {
    if (module1.name.equals(module.name)) {
        removedModule.set(module1);
        module1.settings.unregisterColorSettings();

        return true;
    }

    return false;
})) {
    moduleInstances.remove(removedModule.getClass(), removedModule);
    getGroup(removedModule.get().category).remove(removedModule.get());
}

@PoTheMagicDragon
Copy link
Author

Good point. I copied what you suggested, but changed

    moduleInstances.remove(removedModule.getClass(), removedModule);

to

    moduleInstances.remove(removedModule.getClass(), removedModule.get());

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