Skip to content

Commit

Permalink
Merge pull request Grasscutters#580 from Bwly999/development
Browse files Browse the repository at this point in the history
Fix the problem that the reference of serverHook in Plugin object is null
  • Loading branch information
KingRainbow44 committed May 7, 2022
2 parents 4455072 + 2171668 commit 6ad0a1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/main/java/emu/grasscutter/Grasscutter.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ public static void main(String[] args) throws Exception {
// 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) {
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/emu/grasscutter/server/game/GameServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
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;

Expand Down Expand Up @@ -79,19 +82,6 @@ public GameServer(InetSocketAddress address) {
this.dropManager = new DropManager(this);
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));
Expand Down Expand Up @@ -229,6 +219,24 @@ public void deregisterWorld(World world) {

}

@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"));
Expand Down

0 comments on commit 6ad0a1f

Please sign in to comment.