Commit c442039f authored by Magix's avatar Magix Committed by GitHub
Browse files

Implement a plugin API for developers

Add a developer-friendly API to Grasscutter
parents d133e556 a82ec3e3
package emu.grasscutter.server.event.internal;
import emu.grasscutter.server.event.ServerEvent;
import emu.grasscutter.server.event.types.ServerEvent;
import java.time.OffsetDateTime;
......
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);
}
}
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);
}
}
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;
}
}
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
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;
}
}
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.
......
......@@ -17,7 +17,7 @@ import emu.grasscutter.game.world.World;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
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.internal.ServerStartEvent;
import emu.grasscutter.server.event.internal.ServerStopEvent;
......
......@@ -13,6 +13,7 @@ import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetPlayerBornDataReqOuterClass.SetPlayerBornDataReq;
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.SessionState;
......@@ -27,7 +28,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
// Sanity checks
int avatarId = req.getAvatarId();
int startingSkillDepot = 0;
int startingSkillDepot;
if (avatarId == GameConstants.MAIN_CHARACTER_MALE) {
startingSkillDepot = 504;
} else if (avatarId == GameConstants.MAIN_CHARACTER_FEMALE) {
......@@ -41,8 +42,10 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
nickname = "Traveler";
}
// Create character
Player player = new Player(session);
// Call creation event.
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);
try {
......@@ -92,5 +95,4 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
session.close();
}
}
}
......@@ -3,24 +3,12 @@ package emu.grasscutter.task;
import org.quartz.*;
@PersistJobDataAfterExecution
public class TaskHandler implements Job {
public abstract class TaskHandler implements Job {
public void restartExecute() throws JobExecutionException {
execute(null);
}
public void onEnable() {
}
public void onDisable() {
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
// TODO Auto-generated method stub
}
public abstract void onEnable();
public abstract void onDisable();
}
......@@ -4,22 +4,21 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.task.Task;
import emu.grasscutter.task.TaskHandler;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
@Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger")
// 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
public void onEnable() {
Grasscutter.getLogger().info("[Task] MoonCard task enabled.");
Grasscutter.getLogger().debug("[Task] MoonCard task enabled.");
}
@Override
public void onDisable() {
Grasscutter.getLogger().info("[Task] MoonCard task disabled.");
Grasscutter.getLogger().debug("[Task] MoonCard task disabled.");
}
@Override
......
package emu.grasscutter.utils;
import emu.grasscutter.server.event.Event;
public interface EventConsumer<T extends Event> {
void consume(T event);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment