Commit f04035da authored by Luke H-W's avatar Luke H-W Committed by GitHub
Browse files

Merge branch 'development' into Weather

parents b2e62055 1c9a9599
package emu.grasscutter.server.event; package emu.grasscutter.server.event;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.plugin.Plugin;
import emu.grasscutter.utils.EventConsumer; import emu.grasscutter.utils.EventConsumer;
public final class EventHandler<T extends Event> { public final class EventHandler<T extends Event> {
...@@ -75,7 +76,7 @@ public final class EventHandler<T extends Event> { ...@@ -75,7 +76,7 @@ public final class EventHandler<T extends Event> {
/** /**
* Registers the handler into the PluginManager. * Registers the handler into the PluginManager.
*/ */
public void register() { public void register(Plugin plugin) {
Grasscutter.getPluginManager().registerListener(this); Grasscutter.getPluginManager().registerListener(plugin, this);
} }
} }
\ No newline at end of file
...@@ -11,24 +11,23 @@ import emu.grasscutter.net.packet.PacketOpcodes; ...@@ -11,24 +11,23 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetPlayerTokenReqOuterClass.GetPlayerTokenReq; import emu.grasscutter.net.proto.GetPlayerTokenReqOuterClass.GetPlayerTokenReq;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.event.game.PlayerCreationEvent; import emu.grasscutter.server.event.game.PlayerCreationEvent;
import emu.grasscutter.server.game.GameServer;
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;
import emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp; import emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp;
@Opcodes(PacketOpcodes.GetPlayerTokenReq) @Opcodes(PacketOpcodes.GetPlayerTokenReq)
public class HandlerGetPlayerTokenReq extends PacketHandler { public class HandlerGetPlayerTokenReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
GetPlayerTokenReq req = GetPlayerTokenReq.parseFrom(payload); GetPlayerTokenReq req = GetPlayerTokenReq.parseFrom(payload);
// Authenticate // Authenticate
Account account = DatabaseHelper.getAccountById(req.getAccountUid()); Account account = DatabaseHelper.getAccountById(req.getAccountUid());
if (account == null || !account.getToken().equals(req.getAccountToken())) { if (account == null || !account.getToken().equals(req.getAccountToken())) {
return; return;
} }
// Set account // Set account
session.setAccount(account); session.setAccount(account);
...@@ -58,25 +57,25 @@ public class HandlerGetPlayerTokenReq extends PacketHandler { ...@@ -58,25 +57,25 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
} }
} }
// Get player // Call creation event.
Player player = DatabaseHelper.getPlayerByAccount(account); PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call();
// Get player.
Player player = DatabaseHelper.getPlayerByAccount(account, event.getPlayerClass());
if (player == null) { if (player == null) {
int nextPlayerUid = DatabaseHelper.getNextPlayerId(session.getAccount().getReservedPlayerUid()); int nextPlayerUid = DatabaseHelper.getNextPlayerId(session.getAccount().getReservedPlayerUid());
// Call creation event.
PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call();
// Create player instance from event. // Create player instance from event.
player = event.getPlayerClass().getDeclaredConstructor(GameSession.class).newInstance(session); player = event.getPlayerClass().getDeclaredConstructor(GameSession.class).newInstance(session);
// Save to db // Save to db
DatabaseHelper.generatePlayerUid(player, nextPlayerUid); DatabaseHelper.generatePlayerUid(player, nextPlayerUid);
} }
// Set player object for session // Set player object for session
session.setPlayer(player); session.setPlayer(player);
// Checks if the player is banned // Checks if the player is banned
if (session.getAccount().isBanned()) { if (session.getAccount().isBanned()) {
session.send(new PacketGetPlayerTokenRsp(session, 21, "FORBID_CHEATING_PLUGINS", session.getAccount().getBanEndTime())); session.send(new PacketGetPlayerTokenRsp(session, 21, "FORBID_CHEATING_PLUGINS", session.getAccount().getBanEndTime()));
...@@ -86,7 +85,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler { ...@@ -86,7 +85,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
// Load player from database // Load player from database
player.loadFromDatabase(); player.loadFromDatabase();
// Set session state // Set session state
session.setUseSecretKey(true); session.setUseSecretKey(true);
session.setState(SessionState.WAITING_FOR_LOGIN); session.setState(SessionState.WAITING_FOR_LOGIN);
......
...@@ -131,5 +131,293 @@ ...@@ -131,5 +131,293 @@
"count": 1 "count": 1
} }
] ]
},
{
"objNames": [
"SceneObj_Chest_Default_Lv3",
"SceneObj_Chest_Locked_Lv3",
"SceneObj_Chest_Bramble_Lv3",
"SceneObj_Chest_Frozen_Lv3"
],
"advExp": 200,
"resin": 20,
"mora": 8888,
"sigil": 20,
"content": [
{
"itemId": 104012,
"count": 3
},
{
"itemId": 223,
"count": 10
},
{
"itemId": 104002,
"count": 1
}
],
"randomCount": 4,
"randomContent": [
{
"itemId": 11509,
"count": 1
},
{
"itemId": 13501,
"count": 1
},
{
"itemId": 12201,
"count": 1
},
{
"itemId": 12301,
"count": 1
},
{
"itemId": 13201,
"count": 1
},
{
"itemId": 13301,
"count": 1
},
{
"itemId": 14201,
"count": 1
},
{
"itemId": 14301,
"count": 1
},
{
"itemId": 15201,
"count": 1
},
{
"itemId": 15301,
"count": 1
}
]
},
{
"objNames": [
"SceneObj_Chest_Default_Lv4",
"SceneObj_Chest_Locked_Lv4",
"SceneObj_Chest_Bramble_Lv4",
"SceneObj_Chest_Frozen_Lv4"
],
"advExp": 20000,
"resin": 2,
"mora": 88888,
"sigil": 2,
"content": [
{
"itemId": 104012,
"count": 3
},
{
"itemId": 223,
"count": 50
},
{
"itemId": 104002,
"count": 1
}
],
"randomCount": 4,
"randomContent": [
{
"itemId": 13501,
"count": 1
},
{
"itemId": 11301,
"count": 1
},
{
"itemId": 12201,
"count": 1
},
{
"itemId": 12301,
"count": 1
},
{
"itemId": 13201,
"count": 1
},
{
"itemId": 13301,
"count": 1
},
{
"itemId": 14201,
"count": 1
},
{
"itemId": 14301,
"count": 1
},
{
"itemId": 15201,
"count": 1
},
{
"itemId": 15301,
"count": 1
}
]
},
{
"objNames": [
"SceneObj_Chest_Default_Lv5",
"SceneObj_Chest_Locked_Lv5",
"SceneObj_Chest_Bramble_Lv5",
"SceneObj_Chest_Frozen_Lv5"
],
"advExp": 20000,
"resin": 2,
"mora": 88888,
"sigil": 2,
"content": [
{
"itemId": 104012,
"count": 3
},
{
"itemId": 223,
"count": 100
},
{
"itemId": 104002,
"count": 1
}
],
"randomCount": 5,
"randomContent": [
{
"itemId": 13501,
"count": 1
},
{
"itemId": 11301,
"count": 1
},
{
"itemId": 13509,
"count": 1
},
{
"itemId": 12301,
"count": 1
},
{
"itemId": 14509,
"count": 1
},
{
"itemId": 15507,
"count": 1
},
{
"itemId": 15509,
"count": 1
},
{
"itemId": 11509,
"count": 1
},
{
"itemId": 11503,
"count": 1
},
{
"itemId": 15301,
"count": 1
}
]
},
{
"objNames": [
"SceneObj_Area_Common_Property_Ani_Prop_MoonlitBox_01"
],
"advExp": 20000,
"resin": 2,
"mora": 88888,
"sigil": 2,
"content": [
{
"itemId": 104012,
"count": 3
},
{
"itemId": 223,
"count": 100
},
{
"itemId": 104002,
"count": 1
}
],
"randomCount": 5,
"randomContent": [
{
"itemId": 13501,
"count": 1
},
{
"itemId": 11301,
"count": 1
},
{
"itemId": 13509,
"count": 1
},
{
"itemId": 12301,
"count": 1
},
{
"itemId": 14509,
"count": 1
},
{
"itemId": 15507,
"count": 1
},
{
"itemId": 15509,
"count": 1
},
{
"itemId": 11509,
"count": 1
},
{
"itemId": 11503,
"count": 1
},
{
"itemId": 15301,
"count": 1
}
]
},
{
"objNames": [
"SceneObj_Area_Dq_Property_Ani_Prop_JunkChest_01",
"SceneObj_Area_Common_Property_Ani_Prop_JunkChest_02",
"SearchPoint",
"SearchPoint_OnWater"
],
"mora": 1,
"content": [
{
"itemId": 201,
"count": 114
}
]
} }
] ]
\ No newline at end of file
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