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
6175e957
Commit
6175e957
authored
Jun 22, 2022
by
KingRainbow44
Browse files
Fix issue when exiting server when plugin manager hasn't loaded
parent
91d232d6
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Grasscutter.java
View file @
6175e957
package
emu.grasscutter
;
package
emu.grasscutter
;
import
java.io.*
;
import
ch.qos.logback.classic.Logger
;
import
java.util.Calendar
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
emu.grasscutter.auth.AuthenticationSystem
;
import
emu.grasscutter.auth.AuthenticationSystem
;
import
emu.grasscutter.auth.DefaultAuthentication
;
import
emu.grasscutter.auth.DefaultAuthentication
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.command.DefaultPermissionHandler
;
import
emu.grasscutter.command.DefaultPermissionHandler
;
import
emu.grasscutter.command.PermissionHandler
;
import
emu.grasscutter.command.PermissionHandler
;
import
emu.grasscutter.game.dungeons.challenge.DungeonChallenge
;
import
emu.grasscutter.game.dungeons.challenge.DungeonChallenge
;
import
emu.grasscutter.data.ResourceLoader
;
import
emu.grasscutter.database.DatabaseManager
;
import
emu.grasscutter.game.managers.energy.EnergyManager
;
import
emu.grasscutter.game.managers.energy.EnergyManager
;
import
emu.grasscutter.game.managers.stamina.StaminaManager
;
import
emu.grasscutter.game.managers.stamina.StaminaManager
;
import
emu.grasscutter.plugin.PluginManager
;
import
emu.grasscutter.plugin.PluginManager
;
import
emu.grasscutter.plugin.api.ServerHook
;
import
emu.grasscutter.plugin.api.ServerHook
;
import
emu.grasscutter.scripts.ScriptLoader
;
import
emu.grasscutter.scripts.ScriptLoader
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.http.HttpServer
;
import
emu.grasscutter.server.http.HttpServer
;
import
emu.grasscutter.server.http.dispatch.DispatchHandler
;
import
emu.grasscutter.server.http.dispatch.DispatchHandler
;
import
emu.grasscutter.server.http.handlers.*
;
import
emu.grasscutter.server.http.dispatch.RegionHandler
;
import
emu.grasscutter.server.http.dispatch.RegionHandler
;
import
emu.grasscutter.server.http.documentation.DocumentationServerHandler
;
import
emu.grasscutter.server.http.documentation.DocumentationServerHandler
;
import
emu.grasscutter.server.http.handlers.AnnouncementsHandler
;
import
emu.grasscutter.server.http.handlers.GachaHandler
;
import
emu.grasscutter.server.http.handlers.GenericHandler
;
import
emu.grasscutter.server.http.handlers.LogHandler
;
import
emu.grasscutter.tools.Tools
;
import
emu.grasscutter.utils.ConfigContainer
;
import
emu.grasscutter.utils.ConfigContainer
;
import
emu.grasscutter.utils.Crypto
;
import
emu.grasscutter.utils.Language
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
import
org.jline.reader.EndOfFileException
;
import
org.jline.reader.EndOfFileException
;
import
org.jline.reader.LineReader
;
import
org.jline.reader.LineReader
;
...
@@ -30,21 +39,13 @@ import org.jline.terminal.TerminalBuilder;
...
@@ -30,21 +39,13 @@ import org.jline.terminal.TerminalBuilder;
import
org.reflections.Reflections
;
import
org.reflections.Reflections
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
ch.qos.logback.classic.Logger
;
import
emu.grasscutter.data.ResourceLoader
;
import
emu.grasscutter.database.DatabaseManager
;
import
emu.grasscutter.utils.Language
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.tools.Tools
;
import
emu.grasscutter.utils.Crypto
;
import
javax.annotation.Nullable
;
import
javax.annotation.Nullable
;
import
java.io.*
;
import
java.util.Calendar
;
import
static
emu
.
grasscutter
.
Configuration
.
DATA
;
import
static
emu
.
grasscutter
.
Configuration
.
SERVER
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
Configuration
.*;
public
final
class
Grasscutter
{
public
final
class
Grasscutter
{
private
static
final
Logger
log
=
(
Logger
)
LoggerFactory
.
getLogger
(
Grasscutter
.
class
);
private
static
final
Logger
log
=
(
Logger
)
LoggerFactory
.
getLogger
(
Grasscutter
.
class
);
...
@@ -90,19 +91,22 @@ public final class Grasscutter {
...
@@ -90,19 +91,22 @@ public final class Grasscutter {
for
(
String
arg
:
args
)
{
for
(
String
arg
:
args
)
{
switch
(
arg
.
toLowerCase
())
{
switch
(
arg
.
toLowerCase
())
{
case
"-handbook"
->
{
case
"-handbook"
->
{
Tools
.
createGmHandbook
();
exitEarly
=
true
;
Tools
.
createGmHandbook
();
exitEarly
=
true
;
}
}
case
"-gachamap"
->
{
case
"-gachamap"
->
{
Tools
.
createGachaMapping
(
DATA
(
"gacha_mappings.js"
));
exitEarly
=
true
;
Tools
.
createGachaMapping
(
DATA
(
"gacha_mappings.js"
));
exitEarly
=
true
;
}
}
case
"-version"
->
{
case
"-version"
->
{
System
.
out
.
println
(
"Grasscutter version: "
+
BuildConfig
.
VERSION
+
"-"
+
BuildConfig
.
GIT_HASH
);
exitEarly
=
true
;
System
.
out
.
println
(
"Grasscutter version: "
+
BuildConfig
.
VERSION
+
"-"
+
BuildConfig
.
GIT_HASH
);
exitEarly
=
true
;
}
}
}
}
}
}
// Exit early if argument sets it.
// Exit early if argument sets it.
if
(
exitEarly
)
System
.
exit
(
0
);
if
(
exitEarly
)
System
.
exit
(
0
);
// Initialize server.
// Initialize server.
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.status.starting"
));
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.status.starting"
));
...
@@ -113,8 +117,6 @@ public final class Grasscutter {
...
@@ -113,8 +117,6 @@ public final class Grasscutter {
Grasscutter
.
updateDayOfWeek
();
Grasscutter
.
updateDayOfWeek
();
ResourceLoader
.
loadAll
();
ResourceLoader
.
loadAll
();
ScriptLoader
.
init
();
ScriptLoader
.
init
();
EnergyManager
.
initialize
();
DungeonChallenge
.
initialize
();
// Initialize database.
// Initialize database.
DatabaseManager
.
initialize
();
DatabaseManager
.
initialize
();
...
@@ -142,9 +144,6 @@ public final class Grasscutter {
...
@@ -142,9 +144,6 @@ public final class Grasscutter {
httpServer
.
addRouter
(
GachaHandler
.
class
);
httpServer
.
addRouter
(
GachaHandler
.
class
);
httpServer
.
addRouter
(
DocumentationServerHandler
.
class
);
httpServer
.
addRouter
(
DocumentationServerHandler
.
class
);
// TODO: find a better place?
StaminaManager
.
initialize
();
// Start servers.
// Start servers.
var
runMode
=
SERVER
.
runMode
;
var
runMode
=
SERVER
.
runMode
;
if
(
runMode
==
ServerRunMode
.
HYBRID
)
{
if
(
runMode
==
ServerRunMode
.
HYBRID
)
{
...
@@ -176,6 +175,7 @@ public final class Grasscutter {
...
@@ -176,6 +175,7 @@ public final class Grasscutter {
*/
*/
private
static
void
onShutdown
()
{
private
static
void
onShutdown
()
{
// Disable all plugins.
// Disable all plugins.
if
(
pluginManager
!=
null
)
pluginManager
.
disablePlugins
();
pluginManager
.
disablePlugins
();
}
}
...
@@ -215,10 +215,11 @@ public final class Grasscutter {
...
@@ -215,10 +215,11 @@ public final class Grasscutter {
/**
/**
* Saves the provided server configuration.
* Saves the provided server configuration.
*
* @param config The configuration to save, or null for a new one.
* @param config The configuration to save, or null for a new one.
*/
*/
public
static
void
saveConfig
(
@Nullable
ConfigContainer
config
)
{
public
static
void
saveConfig
(
@Nullable
ConfigContainer
config
)
{
if
(
config
==
null
)
config
=
new
ConfigContainer
();
if
(
config
==
null
)
config
=
new
ConfigContainer
();
try
(
FileWriter
file
=
new
FileWriter
(
configFile
))
{
try
(
FileWriter
file
=
new
FileWriter
(
configFile
))
{
file
.
write
(
gson
.
toJson
(
config
));
file
.
write
(
gson
.
toJson
(
config
));
...
@@ -350,6 +351,7 @@ public final class Grasscutter {
...
@@ -350,6 +351,7 @@ public final class Grasscutter {
/**
/**
* Sets the authentication system for the server.
* Sets the authentication system for the server.
*
* @param authenticationSystem The authentication system to use.
* @param authenticationSystem The authentication system to use.
*/
*/
public
static
void
setAuthenticationSystem
(
AuthenticationSystem
authenticationSystem
)
{
public
static
void
setAuthenticationSystem
(
AuthenticationSystem
authenticationSystem
)
{
...
@@ -358,6 +360,7 @@ public final class Grasscutter {
...
@@ -358,6 +360,7 @@ public final class Grasscutter {
/**
/**
* Sets the permission handler for the server.
* Sets the permission handler for the server.
*
* @param permissionHandler The permission handler to use.
* @param permissionHandler The permission handler to use.
*/
*/
public
static
void
setPermissionHandler
(
PermissionHandler
permissionHandler
)
{
public
static
void
setPermissionHandler
(
PermissionHandler
permissionHandler
)
{
...
...
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