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
c442039f
Commit
c442039f
authored
Apr 30, 2022
by
Magix
Committed by
GitHub
Apr 30, 2022
Browse files
Implement a plugin API for developers
Add a developer-friendly API to Grasscutter
parents
d133e556
a82ec3e3
Changes
32
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java
View file @
c442039f
package
emu.grasscutter.server.event.internal
;
package
emu.grasscutter.server.event.internal
;
import
emu.grasscutter.server.event.ServerEvent
;
import
emu.grasscutter.server.event.
types.
ServerEvent
;
import
java.time.OffsetDateTime
;
import
java.time.OffsetDateTime
;
...
...
src/main/java/emu/grasscutter/server/event/player/PlayerJoinEvent.java
0 → 100644
View file @
c442039f
package
emu.grasscutter.server.event.player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.Cancellable
;
import
emu.grasscutter.server.event.types.PlayerEvent
;
public
final
class
PlayerJoinEvent
extends
PlayerEvent
implements
Cancellable
{
public
PlayerJoinEvent
(
Player
player
)
{
super
(
player
);
}
}
src/main/java/emu/grasscutter/server/event/player/PlayerQuitEvent.java
0 → 100644
View file @
c442039f
package
emu.grasscutter.server.event.player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.types.GameEvent
;
import
emu.grasscutter.server.event.types.PlayerEvent
;
public
final
class
PlayerQuitEvent
extends
PlayerEvent
{
public
PlayerQuitEvent
(
Player
player
)
{
super
(
player
);
}
}
src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java
0 → 100644
View file @
c442039f
package
emu.grasscutter.server.event.player
;
import
emu.grasscutter.game.mail.Mail
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.Cancellable
;
import
emu.grasscutter.server.event.types.PlayerEvent
;
public
final
class
PlayerReceiveMailEvent
extends
PlayerEvent
implements
Cancellable
{
private
Mail
message
;
public
PlayerReceiveMailEvent
(
Player
player
,
Mail
message
)
{
super
(
player
);
this
.
message
=
message
;
}
public
void
setMessage
(
Mail
message
)
{
this
.
message
=
message
;
}
public
Mail
getMessage
()
{
return
this
.
message
;
}
}
src/main/java/emu/grasscutter/server/event/types/GameEvent.java
0 → 100644
View file @
c442039f
package
emu.grasscutter.server.event.types
;
import
emu.grasscutter.server.event.Event
;
/**
* An event that is related to the game.
*/
public
abstract
class
GameEvent
extends
Event
{
}
\ No newline at end of file
src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java
0 → 100644
View file @
c442039f
package
emu.grasscutter.server.event.types
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.Event
;
/**
* An event that is related to player interactions.
*/
public
abstract
class
PlayerEvent
extends
Event
{
protected
final
Player
player
;
public
PlayerEvent
(
Player
player
)
{
this
.
player
=
player
;
}
public
Player
getPlayer
()
{
return
this
.
player
;
}
}
src/main/java/emu/grasscutter/server/event/ServerEvent.java
→
src/main/java/emu/grasscutter/server/event/
types/
ServerEvent.java
View file @
c442039f
package
emu.grasscutter.server.event
;
package
emu.grasscutter.server.event.types
;
import
emu.grasscutter.server.event.Event
;
/**
/**
* An event that is related to the internals of the server.
* An event that is related to the internals of the server.
...
...
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
c442039f
...
@@ -17,7 +17,7 @@ import emu.grasscutter.game.world.World;
...
@@ -17,7 +17,7 @@ import emu.grasscutter.game.world.World;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.netty.KcpServer
;
import
emu.grasscutter.netty.KcpServer
;
import
emu.grasscutter.server.event.ServerEvent
;
import
emu.grasscutter.server.event.
types.
ServerEvent
;
import
emu.grasscutter.server.event.game.ServerTickEvent
;
import
emu.grasscutter.server.event.game.ServerTickEvent
;
import
emu.grasscutter.server.event.internal.ServerStartEvent
;
import
emu.grasscutter.server.event.internal.ServerStartEvent
;
import
emu.grasscutter.server.event.internal.ServerStopEvent
;
import
emu.grasscutter.server.event.internal.ServerStopEvent
;
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java
View file @
c442039f
...
@@ -13,6 +13,7 @@ import emu.grasscutter.net.packet.Opcodes;
...
@@ -13,6 +13,7 @@ import emu.grasscutter.net.packet.Opcodes;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.SetPlayerBornDataReqOuterClass.SetPlayerBornDataReq
;
import
emu.grasscutter.net.proto.SetPlayerBornDataReqOuterClass.SetPlayerBornDataReq
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.server.event.game.PlayerCreationEvent
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession.SessionState
;
import
emu.grasscutter.server.game.GameSession.SessionState
;
...
@@ -27,7 +28,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
...
@@ -27,7 +28,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
// Sanity checks
// Sanity checks
int
avatarId
=
req
.
getAvatarId
();
int
avatarId
=
req
.
getAvatarId
();
int
startingSkillDepot
=
0
;
int
startingSkillDepot
;
if
(
avatarId
==
GameConstants
.
MAIN_CHARACTER_MALE
)
{
if
(
avatarId
==
GameConstants
.
MAIN_CHARACTER_MALE
)
{
startingSkillDepot
=
504
;
startingSkillDepot
=
504
;
}
else
if
(
avatarId
==
GameConstants
.
MAIN_CHARACTER_FEMALE
)
{
}
else
if
(
avatarId
==
GameConstants
.
MAIN_CHARACTER_FEMALE
)
{
...
@@ -41,8 +42,10 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
...
@@ -41,8 +42,10 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
nickname
=
"Traveler"
;
nickname
=
"Traveler"
;
}
}
// Create character
// Call creation event.
Player
player
=
new
Player
(
session
);
PlayerCreationEvent
event
=
new
PlayerCreationEvent
(
session
,
Player
.
class
);
event
.
call
();
// Create player instance from event.
Player
player
=
event
.
getPlayerClass
().
getDeclaredConstructor
(
GameSession
.
class
).
newInstance
(
session
);
player
.
setNickname
(
nickname
);
player
.
setNickname
(
nickname
);
try
{
try
{
...
@@ -92,5 +95,4 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
...
@@ -92,5 +95,4 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
session
.
close
();
session
.
close
();
}
}
}
}
}
}
src/main/java/emu/grasscutter/task/TaskHandler.java
View file @
c442039f
...
@@ -3,24 +3,12 @@ package emu.grasscutter.task;
...
@@ -3,24 +3,12 @@ package emu.grasscutter.task;
import
org.quartz.*
;
import
org.quartz.*
;
@PersistJobDataAfterExecution
@PersistJobDataAfterExecution
public
class
TaskHandler
implements
Job
{
public
abstract
class
TaskHandler
implements
Job
{
public
void
restartExecute
()
throws
JobExecutionException
{
public
void
restartExecute
()
throws
JobExecutionException
{
execute
(
null
);
execute
(
null
);
}
}
public
void
onEnable
()
{
public
abstract
void
onEnable
();
}
public
void
onDisable
()
{
}
@Override
public
void
execute
(
JobExecutionContext
context
)
throws
JobExecutionException
{
// TODO Auto-generated method stub
}
public
abstract
void
onDisable
();
}
}
src/main/java/emu/grasscutter/task/tasks/MoonCard.java
View file @
c442039f
...
@@ -4,22 +4,21 @@ import emu.grasscutter.Grasscutter;
...
@@ -4,22 +4,21 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.task.Task
;
import
emu.grasscutter.task.Task
;
import
emu.grasscutter.task.TaskHandler
;
import
emu.grasscutter.task.TaskHandler
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionException
;
import
org.quartz.JobExecutionException
;
@Task
(
taskName
=
"MoonCard"
,
taskCronExpression
=
"0 0 0 * * ?"
,
triggerName
=
"MoonCardTrigger"
)
@Task
(
taskName
=
"MoonCard"
,
taskCronExpression
=
"0 0 0 * * ?"
,
triggerName
=
"MoonCardTrigger"
)
// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system)
// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system)
public
class
MoonCard
extends
TaskHandler
{
public
final
class
MoonCard
extends
TaskHandler
{
@Override
@Override
public
void
onEnable
()
{
public
void
onEnable
()
{
Grasscutter
.
getLogger
().
info
(
"[Task] MoonCard task enabled."
);
Grasscutter
.
getLogger
().
debug
(
"[Task] MoonCard task enabled."
);
}
}
@Override
@Override
public
void
onDisable
()
{
public
void
onDisable
()
{
Grasscutter
.
getLogger
().
info
(
"[Task] MoonCard task disabled."
);
Grasscutter
.
getLogger
().
debug
(
"[Task] MoonCard task disabled."
);
}
}
@Override
@Override
...
...
src/main/java/emu/grasscutter/utils/EventConsumer.java
0 → 100644
View file @
c442039f
package
emu.grasscutter.utils
;
import
emu.grasscutter.server.event.Event
;
public
interface
EventConsumer
<
T
extends
Event
>
{
void
consume
(
T
event
);
}
Prev
1
2
Next
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