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
74929335
Commit
74929335
authored
Apr 26, 2022
by
KingRainbow44
Browse files
Add dispatch to server hook & create instance
parent
88bdaf15
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Grasscutter.java
View file @
74929335
...
@@ -9,6 +9,7 @@ import java.net.InetSocketAddress;
...
@@ -9,6 +9,7 @@ import java.net.InetSocketAddress;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.plugin.PluginManager
;
import
emu.grasscutter.plugin.PluginManager
;
import
emu.grasscutter.plugin.api.ServerHook
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
import
org.reflections.Reflections
;
import
org.reflections.Reflections
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -77,6 +78,9 @@ public final class Grasscutter {
...
@@ -77,6 +78,9 @@ public final class Grasscutter {
dispatchServer
=
new
DispatchServer
();
dispatchServer
=
new
DispatchServer
();
gameServer
=
new
GameServer
(
new
InetSocketAddress
(
getConfig
().
getGameServerOptions
().
Ip
,
getConfig
().
getGameServerOptions
().
Port
));
gameServer
=
new
GameServer
(
new
InetSocketAddress
(
getConfig
().
getGameServerOptions
().
Ip
,
getConfig
().
getGameServerOptions
().
Port
));
// Create server hook instance.
new
ServerHook
(
gameServer
,
dispatchServer
);
// Start servers.
// Start servers.
if
(
getConfig
().
RunMode
.
equalsIgnoreCase
(
"HYBRID"
))
{
if
(
getConfig
().
RunMode
.
equalsIgnoreCase
(
"HYBRID"
))
{
dispatchServer
.
start
();
dispatchServer
.
start
();
...
...
src/main/java/emu/grasscutter/plugin/api/ServerHook.java
View file @
74929335
package
emu.grasscutter.plugin.api
;
package
emu.grasscutter.plugin.api
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.server.dispatch.DispatchServer
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.game.GameServer
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
...
@@ -11,7 +12,8 @@ import java.util.List;
...
@@ -11,7 +12,8 @@ import java.util.List;
*/
*/
public
final
class
ServerHook
{
public
final
class
ServerHook
{
private
static
ServerHook
instance
;
private
static
ServerHook
instance
;
private
final
GameServer
server
;
private
final
GameServer
gameServer
;
private
final
DispatchServer
dispatchServer
;
/**
/**
* Gets the server hook instance.
* Gets the server hook instance.
...
@@ -23,10 +25,12 @@ public final class ServerHook {
...
@@ -23,10 +25,12 @@ public final class ServerHook {
/**
/**
* Hooks into a server.
* Hooks into a server.
* @param server The server to hook into.
* @param gameServer The game server to hook into.
* @param dispatchServer The dispatch server to hook into.
*/
*/
public
ServerHook
(
GameServer
server
)
{
public
ServerHook
(
GameServer
gameServer
,
DispatchServer
dispatchServer
)
{
this
.
server
=
server
;
this
.
gameServer
=
gameServer
;
this
.
dispatchServer
=
dispatchServer
;
instance
=
this
;
instance
=
this
;
}
}
...
@@ -36,6 +40,6 @@ public final class ServerHook {
...
@@ -36,6 +40,6 @@ public final class ServerHook {
* @return Players connected to the server.
* @return Players connected to the server.
*/
*/
public
List
<
GenshinPlayer
>
getOnlinePlayers
()
{
public
List
<
GenshinPlayer
>
getOnlinePlayers
()
{
return
new
LinkedList
<>(
this
.
s
erver
.
getPlayers
().
values
());
return
new
LinkedList
<>(
this
.
gameS
erver
.
getPlayers
().
values
());
}
}
}
}
\ No newline at end of file
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