-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Conversation
@Override | ||
public synchronized void start() { | ||
// Schedule game loop. | ||
ScheduledExecutorService gameLoop = Executors.newScheduledThreadPool(2); |
There was a problem hiding this comment.
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..?
There was a problem hiding this comment.
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....
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Fix the problem that the reference of serverHook in Plugin object is null
When PluginManager loading the plugins, the Serverhook has not been initialized, which will cause the ServerHook in the plugin object to be null