mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-10 17:53:21 +08:00
Merge pull request #580 from Bwly999/development
Fix the problem that the reference of serverHook in Plugin object is null
This commit is contained in:
commit
a65823d24e
@ -96,14 +96,13 @@ public final class Grasscutter {
|
||||
// Database
|
||||
DatabaseManager.initialize();
|
||||
|
||||
// Create plugin manager instance.
|
||||
pluginManager = new PluginManager();
|
||||
|
||||
// Create server instances.
|
||||
dispatchServer = new DispatchServer();
|
||||
gameServer = new GameServer();
|
||||
// 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) {
|
||||
|
@ -29,6 +29,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;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
@ -80,19 +83,6 @@ public final class GameServer extends KcpServer {
|
||||
this.expeditionManager = new ExpeditionManager(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(translate("messages.game.game_update_error"), e);
|
||||
}
|
||||
}
|
||||
}, new Date(), 1000L);
|
||||
|
||||
// Hook into shutdown event.
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(this::onServerShutdown));
|
||||
}
|
||||
@ -229,6 +219,24 @@ public final class GameServer extends KcpServer {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void start() {
|
||||
// Schedule game loop.
|
||||
Timer gameLoop = new Timer();
|
||||
gameLoop.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
onTick();
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().error(translate("messages.game.game_update_error"), e);
|
||||
}
|
||||
}
|
||||
}, new Date(), 1000L);
|
||||
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartFinish() {
|
||||
Grasscutter.getLogger().info(translate("messages.status.free_software"));
|
||||
|
Loading…
Reference in New Issue
Block a user