Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
2d325e18
Commit
2d325e18
authored
May 06, 2022
by
Bwly999
Browse files
fix the problem that the reference of serverHook in Plugin object is null
parent
93b3265d
Changes
2
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Grasscutter.java
View file @
2d325e18
...
...
@@ -92,14 +92,13 @@ public final class Grasscutter {
// Database
DatabaseManager
.
initialize
();
// Create plugin manager instance.
pluginManager
=
new
PluginManager
();
// 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
();
// Start servers.
if
(
getConfig
().
RunMode
==
ServerRunMode
.
HYBRID
)
{
...
...
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
2d325e18
...
...
@@ -28,6 +28,9 @@ import java.net.InetSocketAddress;
import
java.time.OffsetDateTime
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
public
final
class
GameServer
extends
KcpServer
{
private
final
InetSocketAddress
address
;
...
...
@@ -68,19 +71,6 @@ public final class GameServer extends KcpServer {
this
.
dropManager
=
new
DropManager
(
this
);
this
.
combineManger
=
new
CombineManger
(
this
);
// Schedule game loop.
Timer
gameLoop
=
new
Timer
();
gameLoop
.
scheduleAtFixedRate
(
new
TimerTask
()
{
@Override
public
void
run
()
{
try
{
onTick
();
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
Grasscutter
.
getLanguage
().
An_error_occurred_during_game_update
,
e
);
}
}
},
new
Date
(),
1000L
);
// Hook into shutdown event.
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
this
::
onServerShutdown
));
}
...
...
@@ -212,6 +202,23 @@ public final class GameServer extends KcpServer {
}
@Override
public
synchronized
void
start
()
{
// Schedule game loop.
ScheduledExecutorService
gameLoop
=
Executors
.
newScheduledThreadPool
(
2
);
gameLoop
.
scheduleAtFixedRate
(
new
TimerTask
()
{
@Override
public
void
run
()
{
try
{
onTick
();
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
Grasscutter
.
getLanguage
().
An_error_occurred_during_game_update
,
e
);
}
}
},
0L
,
1000L
,
TimeUnit
.
MILLISECONDS
);
super
.
start
();
}
@Override
public
void
onStartFinish
()
{
Grasscutter
.
getLogger
().
info
(
Grasscutter
.
getLanguage
().
Grasscutter_is_free
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment