Commit a4932c75 authored by KingRainbow44's avatar KingRainbow44
Browse files

Refactor method names & add `/` prefix

parent c162632f
...@@ -7,7 +7,12 @@ import emu.grasscutter.server.game.GameServer; ...@@ -7,7 +7,12 @@ import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.PacketPlayerChatNotify; import emu.grasscutter.server.packet.send.PacketPlayerChatNotify;
import emu.grasscutter.server.packet.send.PacketPrivateChatNotify; import emu.grasscutter.server.packet.send.PacketPrivateChatNotify;
import java.util.Arrays;
import java.util.List;
public class ChatManager { public class ChatManager {
static final List<Character> PREFIXES = Arrays.asList('/', '!');
private final GameServer server; private final GameServer server;
public ChatManager(GameServer server) { public ChatManager(GameServer server) {
...@@ -18,14 +23,14 @@ public class ChatManager { ...@@ -18,14 +23,14 @@ public class ChatManager {
return server; return server;
} }
public void sendPrivChat(GenshinPlayer player, int targetUid, String message) { public void sendPrivateMessage(GenshinPlayer player, int targetUid, String message) {
// Sanity checks // Sanity checks
if (message == null || message.length() == 0) { if (message == null || message.length() == 0) {
return; return;
} }
// Check if command // Check if command
if (message.charAt(0) == '!') { if (PREFIXES.contains(message.charAt(0))) {
CommandMap.getInstance().invoke(player, message); CommandMap.getInstance().invoke(player, message);
return; return;
} }
...@@ -44,7 +49,7 @@ public class ChatManager { ...@@ -44,7 +49,7 @@ public class ChatManager {
target.sendPacket(packet); target.sendPacket(packet);
} }
public void sendPrivChat(GenshinPlayer player, int targetUid, int emote) { public void sendPrivateMessage(GenshinPlayer player, int targetUid, int emote) {
// Get target // Get target
GenshinPlayer target = getServer().getPlayerById(targetUid); GenshinPlayer target = getServer().getPlayerById(targetUid);
...@@ -59,14 +64,14 @@ public class ChatManager { ...@@ -59,14 +64,14 @@ public class ChatManager {
target.sendPacket(packet); target.sendPacket(packet);
} }
public void sendTeamChat(GenshinPlayer player, int channel, String message) { public void sendTeamMessage(GenshinPlayer player, int channel, String message) {
// Sanity checks // Sanity checks
if (message == null || message.length() == 0) { if (message == null || message.length() == 0) {
return; return;
} }
// Check if command // Check if command
if (message.charAt(0) == '!') { if (PREFIXES.contains(message.charAt(0))) {
CommandMap.getInstance().invoke(player, message); CommandMap.getInstance().invoke(player, message);
return; return;
} }
...@@ -75,7 +80,7 @@ public class ChatManager { ...@@ -75,7 +80,7 @@ public class ChatManager {
player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, message)); player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, message));
} }
public void sendTeamChat(GenshinPlayer player, int channel, int icon) { public void sendTeamMessage(GenshinPlayer player, int channel, int icon) {
// Create and send chat packet // Create and send chat packet
player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, icon)); player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, icon));
} }
......
...@@ -17,9 +17,9 @@ public class HandlerPlayerChatReq extends PacketHandler { ...@@ -17,9 +17,9 @@ public class HandlerPlayerChatReq extends PacketHandler {
ChatInfo.ContentCase content = req.getChatInfo().getContentCase(); ChatInfo.ContentCase content = req.getChatInfo().getContentCase();
if (content == ChatInfo.ContentCase.TEXT) { if (content == ChatInfo.ContentCase.TEXT) {
session.getServer().getChatManager().sendTeamChat(session.getPlayer(), req.getChannelId(), req.getChatInfo().getText()); session.getServer().getChatManager().sendTeamMessage(session.getPlayer(), req.getChannelId(), req.getChatInfo().getText());
} else if (content == ChatInfo.ContentCase.ICON) { } else if (content == ChatInfo.ContentCase.ICON) {
session.getServer().getChatManager().sendTeamChat(session.getPlayer(), req.getChannelId(), req.getChatInfo().getIcon()); session.getServer().getChatManager().sendTeamMessage(session.getPlayer(), req.getChannelId(), req.getChatInfo().getIcon());
} }
session.send(new PacketPlayerChatRsp()); session.send(new PacketPlayerChatRsp());
......
...@@ -15,9 +15,9 @@ public class HandlerPrivateChatReq extends PacketHandler { ...@@ -15,9 +15,9 @@ public class HandlerPrivateChatReq extends PacketHandler {
PrivateChatReq.ContentCase content = req.getContentCase(); PrivateChatReq.ContentCase content = req.getContentCase();
if (content == PrivateChatReq.ContentCase.TEXT) { if (content == PrivateChatReq.ContentCase.TEXT) {
session.getServer().getChatManager().sendPrivChat(session.getPlayer(), req.getTargetUid(), req.getText()); session.getServer().getChatManager().sendPrivateMessage(session.getPlayer(), req.getTargetUid(), req.getText());
} else if (content == PrivateChatReq.ContentCase.ICON) { } else if (content == PrivateChatReq.ContentCase.ICON) {
session.getServer().getChatManager().sendPrivChat(session.getPlayer(), req.getTargetUid(), req.getIcon()); session.getServer().getChatManager().sendPrivateMessage(session.getPlayer(), req.getTargetUid(), req.getIcon());
} }
//session.send(new GenshinPacket(PacketOpcodes.PrivateChatRsp)); // Unused by server //session.send(new GenshinPacket(PacketOpcodes.PrivateChatRsp)); // Unused by server
......
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