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

Fix the problem that the reference of serverHook in Plugin object is null #580

Merged
merged 4 commits into from
May 7, 2022

Conversation

Bwly999
Copy link
Contributor

@Bwly999 Bwly999 commented May 6, 2022

When PluginManager loading the plugins, the Serverhook has not been initialized, which will cause the ServerHook in the plugin object to be null

@4Benj 4Benj requested a review from KingRainbow44 May 6, 2022 10:34
@Override
public synchronized void start() {
// Schedule game loop.
ScheduledExecutorService gameLoop = Executors.newScheduledThreadPool(2);
Copy link

Choose a reason for hiding this comment

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

Why did you move the game loop and why is it in a thread pool..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because onTick function in game loop will call Grasscutter.getPluginManager().invokeEvent(this);,
but after moving the order of creating plugin manager, it will cause a null point exception because it is not instantiated in this time。As for thread pool, it's the recommendation of IDEA....

Copy link

Choose a reason for hiding this comment

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

Makes sense but theres no need to put the gameloop in a thread pool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, I've rolled it back

// Create server instances.
dispatchServer = new DispatchServer();
gameServer = new GameServer(new InetSocketAddress(getConfig().getGameServerOptions().Ip, getConfig().getGameServerOptions().Port));
// Create a server hook instance with both servers.
new ServerHook(gameServer, dispatchServer);
// Create plugin manager instance.
pluginManager = new PluginManager();
Copy link
Member

Choose a reason for hiding this comment

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

I think there might have been a reason for plugins to be initialized before the dispatch or game server.
I'm guessing it's to prevent people from editing the server's functions from onLoad and to force people to do it in onEnable but I'm not exactly sure.
@KingRainbow44 can tell you if this was intentional or not and if it is safe to move.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Every plugin will be instantiated in plugin manager constructor, and in the time, if ServerHook.instance is still null, private final ServerHook server = ServerHook.getInstance(); in Plugin seems a little unless. Maybe need a new proper position to call this statement.

Copy link
Member

@4Benj 4Benj May 6, 2022

Choose a reason for hiding this comment

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

Ohhhhh okay, I haven't had the chance of play with hooks yet, mb.
I just thought you were trying to call getDispatchServer or getGameServer from onLoad or something.
ik the PR is about the serverHook but I didn't know it worked like that

@KingRainbow44 KingRainbow44 merged commit 6ad0a1f into Grasscutters:development May 7, 2022
Birdulon pushed a commit to Birdulon/Grasscutter that referenced this pull request Aug 21, 2022
Fix the problem that the reference of serverHook in Plugin object is null
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.

None yet

3 participants