refactor some bits

This commit is contained in:
len
2021-05-12 10:43:30 +02:00
parent 21a15c3817
commit b8ff6a1fb4
9 changed files with 94 additions and 256 deletions
@@ -1,6 +1,7 @@
package com.alttd.chat.handlers;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.api.PrivateMessageEvent;
import com.alttd.chat.config.Config;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
@@ -46,6 +47,35 @@ public class ChatHandler {
return Collections.unmodifiableList(chatPlayers);
}
public void privateMessage(PrivateMessageEvent event) {
String senderName;
String receiverName;
CommandSource commandSource = event.getSender();
if (commandSource instanceof Player) {
Player sender = (Player) event.getSender();
senderName = sender.getUsername();
//plugin.getChatHandler().getChatPlayer(sender.getUniqueId()).setReplyTarget(event.getRecipient().getUniqueId()); // TODO this needs to be cleaner
} else {
senderName = "Console"; // TODO console name from config
}
receiverName = event.getRecipient().getUsername();
MiniMessage miniMessage = MiniMessage.get();
Map<String, String> map = new HashMap<>();
map.put("sender", senderName);
map.put("receiver", receiverName);
map.put("message", event.getMessage());
map.put("server", event.getRecipient().getCurrentServer().isPresent() ? event.getRecipient().getCurrentServer().get().getServerInfo().getName() : "Altitude");
Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, map);
Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, map);
event.getSender().sendMessage(senderMessage);
event.getRecipient().sendMessage(receiverMessage);
}
public void globalChat(CommandSource source, String message) {
String senderName, serverName, prefix;
Map<String, String> map = new HashMap<>();