Commit 0421d912 authored by mingjun97's avatar mingjun97 Committed by Melledy
Browse files

Enable plugins to hook server message response

* Add message handler so that the plugin can hook inside the `dropMessage` method for `Player` instance.
parent 5b6da381
...@@ -46,6 +46,7 @@ import emu.grasscutter.server.game.GameSession; ...@@ -46,6 +46,7 @@ import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.DateHelper; import emu.grasscutter.utils.DateHelper;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.MessageHandler;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
...@@ -80,7 +81,8 @@ public class Player { ...@@ -80,7 +81,8 @@ public class Player {
@Transient private Inventory inventory; @Transient private Inventory inventory;
@Transient private FriendsList friendsList; @Transient private FriendsList friendsList;
@Transient private MailHandler mailHandler; @Transient private MailHandler mailHandler;
@Transient private MessageHandler messageHandler;
private TeamManager teamManager; private TeamManager teamManager;
private PlayerGachaInfo gachaInfo; private PlayerGachaInfo gachaInfo;
private PlayerProfile playerProfile; private PlayerProfile playerProfile;
...@@ -149,6 +151,7 @@ public class Player { ...@@ -149,6 +151,7 @@ public class Player {
this.moonCardGetTimes = new HashSet<>(); this.moonCardGetTimes = new HashSet<>();
this.shopLimit = new ArrayList<>(); this.shopLimit = new ArrayList<>();
this.messageHandler = null;
} }
// On player creation // On player creation
...@@ -173,6 +176,7 @@ public class Player { ...@@ -173,6 +176,7 @@ public class Player {
this.getNameCardList().add(210001); this.getNameCardList().add(210001);
this.getPos().set(GameConstants.START_POSITION); this.getPos().set(GameConstants.START_POSITION);
this.getRotation().set(0, 307, 0); this.getRotation().set(0, 307, 0);
this.messageHandler = null;
} }
public int getUid() { public int getUid() {
...@@ -714,6 +718,10 @@ public class Player { ...@@ -714,6 +718,10 @@ public class Player {
} }
public void dropMessage(Object message) { public void dropMessage(Object message) {
if (this.messageHandler != null) {
this.messageHandler.append(message.toString());
return;
}
this.sendPacket(new PacketPrivateChatNotify(GameConstants.SERVER_CONSOLE_UID, getUid(), message.toString())); this.sendPacket(new PacketPrivateChatNotify(GameConstants.SERVER_CONSOLE_UID, getUid(), message.toString()));
} }
...@@ -1067,4 +1075,8 @@ public class Player { ...@@ -1067,4 +1075,8 @@ public class Player {
return this.value; return this.value;
} }
} }
public void setMessageHandler(MessageHandler messageHandler) {
this.messageHandler = messageHandler;
}
} }
package emu.grasscutter.utils;
public class MessageHandler {
private String message;
public MessageHandler(){
this.message = "";
}
public void append(String message){
this.message += message;
}
public String getMessage(){
return this.message;
}
public void setMessage(String message){
this.message = message;
}
}
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