Refactor method names & add / prefix

This commit is contained in:
KingRainbow44 2022-04-18 22:16:20 -04:00
parent c162632fbd
commit a4932c7557
3 changed files with 15 additions and 10 deletions

View File

@ -7,7 +7,12 @@ import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.PacketPlayerChatNotify;
import emu.grasscutter.server.packet.send.PacketPrivateChatNotify;
import java.util.Arrays;
import java.util.List;
public class ChatManager {
static final List<Character> PREFIXES = Arrays.asList('/', '!');
private final GameServer server;
public ChatManager(GameServer server) {
@ -18,14 +23,14 @@ public class ChatManager {
return server;
}
public void sendPrivChat(GenshinPlayer player, int targetUid, String message) {
public void sendPrivateMessage(GenshinPlayer player, int targetUid, String message) {
// Sanity checks
if (message == null || message.length() == 0) {
return;
}
// Check if command
if (message.charAt(0) == '!') {
if (PREFIXES.contains(message.charAt(0))) {
CommandMap.getInstance().invoke(player, message);
return;
}
@ -44,7 +49,7 @@ public class ChatManager {
target.sendPacket(packet);
}
public void sendPrivChat(GenshinPlayer player, int targetUid, int emote) {
public void sendPrivateMessage(GenshinPlayer player, int targetUid, int emote) {
// Get target
GenshinPlayer target = getServer().getPlayerById(targetUid);
@ -59,14 +64,14 @@ public class ChatManager {
target.sendPacket(packet);
}
public void sendTeamChat(GenshinPlayer player, int channel, String message) {
public void sendTeamMessage(GenshinPlayer player, int channel, String message) {
// Sanity checks
if (message == null || message.length() == 0) {
return;
}
// Check if command
if (message.charAt(0) == '!') {
if (PREFIXES.contains(message.charAt(0))) {
CommandMap.getInstance().invoke(player, message);
return;
}
@ -75,7 +80,7 @@ public class ChatManager {
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
player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, icon));
}

View File

@ -17,9 +17,9 @@ public class HandlerPlayerChatReq extends PacketHandler {
ChatInfo.ContentCase content = req.getChatInfo().getContentCase();
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) {
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());

View File

@ -15,9 +15,9 @@ public class HandlerPrivateChatReq extends PacketHandler {
PrivateChatReq.ContentCase content = req.getContentCase();
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) {
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