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
e27bdd9b
Commit
e27bdd9b
authored
Apr 26, 2022
by
KingRainbow44
Browse files
Add more events
parent
502fe7ed
Changes
8
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Grasscutter.java
View file @
e27bdd9b
...
...
@@ -70,13 +70,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 plugin manager instance.
pluginManager
=
new
PluginManager
();
// Start servers.
if
(
getConfig
().
RunMode
.
equalsIgnoreCase
(
"HYBRID"
))
{
dispatchServer
.
start
();
...
...
src/main/java/emu/grasscutter/game/gacha/GachaManager.java
View file @
e27bdd9b
...
...
@@ -286,8 +286,6 @@ public class GachaManager {
this
.
watchService
=
FileSystems
.
getDefault
().
newWatchService
();
Path
path
=
new
File
(
Grasscutter
.
getConfig
().
DATA_FOLDER
).
toPath
();
path
.
register
(
watchService
,
new
WatchEvent
.
Kind
[]{
StandardWatchEventKinds
.
ENTRY_MODIFY
},
SensitivityWatchEventModifier
.
HIGH
);
server
.
OnGameServerTick
.
register
(
this
);
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"Unable to load the Gacha Manager Watch Service. If ServerOptions.watchGacha is true it will not auto-reload"
);
e
.
printStackTrace
();
...
...
src/main/java/emu/grasscutter/plugin/api/ServerHook.java
0 → 100644
View file @
e27bdd9b
package
emu.grasscutter.plugin.api
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.server.game.GameServer
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* Hooks into the {@link GameServer} class, adding convenient ways to do certain things.
*/
public
final
class
ServerHook
{
private
static
ServerHook
instance
;
private
final
GameServer
server
;
/**
* Gets the server hook instance.
* @return A {@link ServerHook} singleton.
*/
public
static
ServerHook
getInstance
()
{
return
instance
;
}
/**
* Hooks into a server.
* @param server The server to hook into.
*/
public
ServerHook
(
GameServer
server
)
{
this
.
server
=
server
;
instance
=
this
;
}
/**
* Gets all online players.
* @return Players connected to the server.
*/
public
List
<
GenshinPlayer
>
getOnlinePlayers
()
{
return
new
LinkedList
<>(
this
.
server
.
getPlayers
().
values
());
}
}
\ No newline at end of file
src/main/java/emu/grasscutter/server/event/ServerEvent.java
View file @
e27bdd9b
...
...
@@ -10,6 +10,10 @@ public abstract class ServerEvent extends Event {
this
.
type
=
type
;
}
public
Type
getServerType
()
{
return
this
.
type
;
}
public
enum
Type
{
DISPATCH
,
GAME
...
...
src/main/java/emu/grasscutter/server/event/game/ServerTickEvent.java
0 → 100644
View file @
e27bdd9b
package
emu.grasscutter.server.event.game
;
import
emu.grasscutter.server.event.ServerEvent
;
public
final
class
ServerTickEvent
extends
ServerEvent
{
public
ServerTickEvent
()
{
super
(
Type
.
GAME
);
}
}
src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java
0 → 100644
View file @
e27bdd9b
package
emu.grasscutter.server.event.internal
;
import
emu.grasscutter.server.event.ServerEvent
;
import
java.time.OffsetDateTime
;
public
final
class
ServerStartEvent
extends
ServerEvent
{
private
final
OffsetDateTime
startTime
;
public
ServerStartEvent
(
Type
type
,
OffsetDateTime
startTime
)
{
super
(
type
);
this
.
startTime
=
startTime
;
}
public
OffsetDateTime
getStartTime
()
{
return
this
.
startTime
;
}
}
src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java
0 → 100644
View file @
e27bdd9b
package
emu.grasscutter.server.event.internal
;
import
emu.grasscutter.server.event.ServerEvent
;
import
java.time.OffsetDateTime
;
public
final
class
ServerStopEvent
extends
ServerEvent
{
private
final
OffsetDateTime
stopTime
;
public
ServerStopEvent
(
Type
type
,
OffsetDateTime
stopTime
)
{
super
(
type
);
this
.
stopTime
=
stopTime
;
}
public
OffsetDateTime
getStopTime
()
{
return
this
.
stopTime
;
}
}
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
e27bdd9b
package
emu.grasscutter.server.game
;
import
java.net.InetSocketAddress
;
import
java.time.OffsetDateTime
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -19,7 +20,10 @@ import emu.grasscutter.game.shop.ShopManager;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.netty.MihoyoKcpServer
;
import
org.greenrobot.eventbus.EventBus
;
import
emu.grasscutter.server.event.ServerEvent
;
import
emu.grasscutter.server.event.game.ServerTickEvent
;
import
emu.grasscutter.server.event.internal.ServerStartEvent
;
import
emu.grasscutter.server.event.internal.ServerStopEvent
;
public
final
class
GameServer
extends
MihoyoKcpServer
{
private
final
InetSocketAddress
address
;
...
...
@@ -35,17 +39,9 @@ public final class GameServer extends MihoyoKcpServer {
private
final
DungeonManager
dungeonManager
;
private
final
CommandMap
commandMap
;
public
EventBus
OnGameServerStartFinish
;
public
EventBus
OnGameServerTick
;
public
EventBus
OnGameServerStop
;
public
GameServer
(
InetSocketAddress
address
)
{
super
(
address
);
OnGameServerStartFinish
=
EventBus
.
builder
().
throwSubscriberException
(
true
).
logNoSubscriberMessages
(
false
).
build
();
OnGameServerTick
=
EventBus
.
builder
().
throwSubscriberException
(
true
).
logNoSubscriberMessages
(
false
).
build
();
OnGameServerStop
=
EventBus
.
builder
().
throwSubscriberException
(
true
).
logNoSubscriberMessages
(
false
).
build
();
this
.
setServerInitializer
(
new
GameServerInitializer
(
this
));
this
.
address
=
address
;
this
.
packetHandler
=
new
GameServerPacketHandler
(
PacketHandler
.
class
);
...
...
@@ -160,23 +156,22 @@ public final class GameServer extends MihoyoKcpServer {
return
DatabaseHelper
.
getAccountByName
(
username
);
}
public
void
onTick
()
throws
Exception
{
public
void
onTick
()
{
for
(
GenshinPlayer
player
:
this
.
getPlayers
().
values
())
{
player
.
onTick
();
}
OnGame
ServerTick
.
post
(
new
Game
ServerTickEvent
());
ServerTick
Event
event
=
new
ServerTickEvent
()
;
event
.
call
(
);
}
@Override
public
void
onStartFinish
()
{
Grasscutter
.
getLogger
().
info
(
"Game Server started on port "
+
address
.
getPort
());
OnGameServerStartFinish
.
post
(
new
GameServerStartFinishEvent
());
ServerStartEvent
event
=
new
ServerStartEvent
(
ServerEvent
.
Type
.
GAME
,
OffsetDateTime
.
now
());
event
.
call
();
}
public
void
onServerShutdown
()
{
OnGame
ServerStop
.
post
(
new
GameServerStopEvent
()
);
ServerStop
Event
event
=
new
ServerStopEvent
(
ServerEvent
.
Type
.
GAME
,
OffsetDateTime
.
now
());
event
.
call
(
);
// Kick and save all players
List
<
GenshinPlayer
>
list
=
new
ArrayList
<>(
this
.
getPlayers
().
size
());
...
...
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