2021-12-11 18:35:35 +00:00
|
|
|
package com.alttd.velocitychat.handlers;
|
2021-05-10 08:01:35 +00:00
|
|
|
|
2022-01-27 20:05:50 +00:00
|
|
|
import com.alttd.chat.util.Utility;
|
2021-12-11 18:35:35 +00:00
|
|
|
import com.alttd.velocitychat.VelocityChat;
|
2021-05-10 08:01:35 +00:00
|
|
|
import com.alttd.chat.config.Config;
|
2021-06-23 19:16:48 +00:00
|
|
|
import com.alttd.chat.managers.ChatUserManager;
|
2021-08-08 09:36:06 +00:00
|
|
|
import com.alttd.chat.managers.PartyManager;
|
2021-06-23 19:16:48 +00:00
|
|
|
import com.alttd.chat.objects.ChatUser;
|
2021-08-08 09:36:06 +00:00
|
|
|
import com.alttd.chat.objects.Party;
|
|
|
|
|
import com.alttd.chat.util.ALogger;
|
2021-07-27 16:46:58 +00:00
|
|
|
import com.google.common.io.ByteArrayDataOutput;
|
|
|
|
|
import com.google.common.io.ByteStreams;
|
2021-05-10 08:01:35 +00:00
|
|
|
import com.velocitypowered.api.command.CommandSource;
|
|
|
|
|
import com.velocitypowered.api.proxy.Player;
|
2021-07-27 16:46:58 +00:00
|
|
|
import com.velocitypowered.api.proxy.ServerConnection;
|
2021-05-10 08:01:35 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
2021-06-23 19:16:48 +00:00
|
|
|
import net.kyori.adventure.text.minimessage.Template;
|
2021-06-13 11:53:49 +00:00
|
|
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
2021-05-10 08:01:35 +00:00
|
|
|
|
2021-06-23 19:16:48 +00:00
|
|
|
import java.util.*;
|
2021-05-10 08:01:35 +00:00
|
|
|
|
|
|
|
|
public class ChatHandler {
|
|
|
|
|
|
2021-06-23 19:16:48 +00:00
|
|
|
public void privateMessage(String sender, String target, String message) {
|
|
|
|
|
UUID uuid = UUID.fromString(sender);
|
|
|
|
|
ChatUser senderUser = ChatUserManager.getChatUser(uuid);
|
|
|
|
|
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
|
|
|
|
if(optionalPlayer.isEmpty()) return;
|
|
|
|
|
Player player = optionalPlayer.get();
|
2021-05-12 08:43:30 +00:00
|
|
|
|
2021-06-23 19:16:48 +00:00
|
|
|
Optional<Player> optionalPlayer2 = VelocityChat.getPlugin().getProxy().getPlayer(target);
|
|
|
|
|
if(optionalPlayer2.isEmpty()) return;
|
|
|
|
|
Player player2 = optionalPlayer2.get();
|
|
|
|
|
ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
|
2021-05-22 18:34:32 +00:00
|
|
|
|
2021-06-23 19:16:48 +00:00
|
|
|
List<Template> templates = new ArrayList<>(List.of(
|
2022-01-27 20:05:50 +00:00
|
|
|
Template.template("sender", senderUser.getDisplayName()),
|
|
|
|
|
Template.template("sendername", player.getUsername()),
|
|
|
|
|
Template.template("receiver", targetUser.getDisplayName()),
|
|
|
|
|
Template.template("receivername", player2.getUsername()),
|
|
|
|
|
Template.template("message", GsonComponentSerializer.gson().deserialize(message)),
|
|
|
|
|
Template.template("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
|
2021-05-12 08:43:30 +00:00
|
|
|
|
2021-07-27 16:46:58 +00:00
|
|
|
ServerConnection serverConnection;
|
|
|
|
|
if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
|
|
|
|
|
// redirect to the sender
|
|
|
|
|
serverConnection = player.getCurrentServer().get();
|
2022-01-27 20:05:50 +00:00
|
|
|
Component component = Utility.parseMiniMessage(Config.MESSAGESENDER, templates);
|
2021-07-27 16:46:58 +00:00
|
|
|
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
2021-08-20 21:03:58 +00:00
|
|
|
buf.writeUTF("privatemessageout");
|
2021-07-27 16:46:58 +00:00
|
|
|
buf.writeUTF(player.getUniqueId().toString());
|
|
|
|
|
buf.writeUTF(player2.getUsername());
|
|
|
|
|
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
2021-08-23 09:56:31 +00:00
|
|
|
buf.writeUTF(player2.getUniqueId().toString());
|
2021-07-27 16:46:58 +00:00
|
|
|
serverConnection.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray());
|
|
|
|
|
|
|
|
|
|
//redirect to the receiver
|
|
|
|
|
serverConnection = player2.getCurrentServer().get();
|
2022-01-27 20:05:50 +00:00
|
|
|
component = Utility.parseMiniMessage(Config.MESSAGERECIEVER, templates);
|
2021-07-27 16:46:58 +00:00
|
|
|
buf = ByteStreams.newDataOutput();
|
2021-08-20 21:03:58 +00:00
|
|
|
buf.writeUTF("privatemessagein");
|
2021-07-27 16:46:58 +00:00
|
|
|
buf.writeUTF(player2.getUniqueId().toString());
|
|
|
|
|
buf.writeUTF(player.getUsername());
|
2021-07-30 01:16:41 +00:00
|
|
|
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
2021-08-23 09:56:31 +00:00
|
|
|
buf.writeUTF(player.getUniqueId().toString());
|
2021-07-27 16:46:58 +00:00
|
|
|
serverConnection.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray());
|
|
|
|
|
}
|
2021-05-12 08:43:30 +00:00
|
|
|
|
2021-07-27 16:46:58 +00:00
|
|
|
// ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
|
|
|
|
|
//
|
|
|
|
|
// List<Template> templates = new ArrayList<>(List.of(
|
2022-01-27 20:05:50 +00:00
|
|
|
// Template.template("sender", senderUser.getDisplayName()),
|
|
|
|
|
// Template.template("receiver", targetUser.getDisplayName()),
|
|
|
|
|
// Template.template("message", message),
|
|
|
|
|
// Template.template("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
|
2021-07-27 16:46:58 +00:00
|
|
|
//
|
2022-01-27 20:05:50 +00:00
|
|
|
// Component senderMessage = Utility.parseMiniMessage(Config.MESSAGESENDER, templates);
|
|
|
|
|
// Component receiverMessage = Utility.parseMiniMessage(Config.MESSAGERECIEVER, templates);
|
2021-07-27 16:46:58 +00:00
|
|
|
//
|
|
|
|
|
// player.sendMessage(senderMessage);
|
|
|
|
|
// player2.sendMessage(receiverMessage);
|
2021-05-12 08:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 19:32:13 +00:00
|
|
|
public void globalAdminChat(String message) {
|
2021-06-13 11:53:49 +00:00
|
|
|
Component component = GsonComponentSerializer.gson().deserialize(message);
|
2021-06-06 19:32:13 +00:00
|
|
|
|
|
|
|
|
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")/*TODO permission*/).forEach(target -> {
|
|
|
|
|
target.sendMessage(component);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 13:14:11 +00:00
|
|
|
public void globalAdminChat(CommandSource commandSource, String message) {
|
2021-07-17 22:48:55 +00:00
|
|
|
Component senderName = Component.text(Config.CONSOLENAME);
|
2021-05-24 13:14:11 +00:00
|
|
|
String serverName = "Altitude";
|
|
|
|
|
if (commandSource instanceof Player) {
|
|
|
|
|
Player sender = (Player) commandSource;
|
2021-07-17 22:48:55 +00:00
|
|
|
ChatUser user = ChatUserManager.getChatUser(sender.getUniqueId());
|
|
|
|
|
if(user == null) return;
|
|
|
|
|
senderName = user.getDisplayName();
|
2021-05-24 13:14:11 +00:00
|
|
|
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-17 22:48:55 +00:00
|
|
|
List<Template> templates = new ArrayList<>(List.of(
|
2022-01-27 20:05:50 +00:00
|
|
|
Template.template("message", message),
|
|
|
|
|
Template.template("sender", senderName),
|
|
|
|
|
Template.template("server", serverName)));
|
2021-05-24 13:14:11 +00:00
|
|
|
|
2022-01-27 20:05:50 +00:00
|
|
|
Component component = Utility.parseMiniMessage(Config.GACFORMAT, templates);
|
2021-05-24 13:14:11 +00:00
|
|
|
|
|
|
|
|
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")/*TODO permission*/).forEach(target -> {
|
|
|
|
|
target.sendMessage(component);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-22 18:34:32 +00:00
|
|
|
/**
|
|
|
|
|
* constructs a mail object and notifies all involved players about it
|
|
|
|
|
* / mail send playerA,playerB,playerC message
|
|
|
|
|
*/
|
2021-05-24 07:53:45 +00:00
|
|
|
public void sendMail(CommandSource commandSource, String recipient, String message) {
|
2021-07-27 16:46:58 +00:00
|
|
|
UUID uuid;
|
|
|
|
|
if (commandSource instanceof Player) {
|
|
|
|
|
uuid = ((Player) commandSource).getUniqueId();
|
|
|
|
|
} else {
|
|
|
|
|
uuid = Config.CONSOLEUUID;
|
|
|
|
|
}
|
|
|
|
|
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(recipient);
|
|
|
|
|
|
|
|
|
|
//Mail mail = new Mail()
|
2021-05-24 07:53:45 +00:00
|
|
|
// todo construct the mail and notify the player if online?
|
2021-05-22 18:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
2021-05-24 07:53:45 +00:00
|
|
|
public void readMail(CommandSource commandSource, String targetPlayer, boolean unread) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readMail(CommandSource commandSource, boolean unread) {
|
|
|
|
|
|
2021-05-22 18:34:32 +00:00
|
|
|
}
|
2021-05-24 07:53:45 +00:00
|
|
|
|
2021-08-08 09:36:06 +00:00
|
|
|
public void partyChat(String partyId, UUID uuid, Component message) {
|
|
|
|
|
Party party = PartyManager.getParty(Integer.parseInt(partyId));
|
|
|
|
|
if (party == null) {
|
|
|
|
|
ALogger.warn("Received a non existent party");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<UUID> ignoredPlayers = ChatUserManager.getChatUser(uuid).getIgnoredPlayers();
|
|
|
|
|
List<UUID> partyUsersUuid = party.getPartyUsersUuid();
|
|
|
|
|
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
|
|
|
|
|
.filter(p -> partyUsersUuid.contains(p.getUniqueId()))
|
|
|
|
|
.filter(p -> !ignoredPlayers.contains(p.getUniqueId()))
|
|
|
|
|
.forEach(p -> p.sendMessage(message));
|
|
|
|
|
}
|
2022-01-05 14:25:17 +00:00
|
|
|
|
|
|
|
|
public void mutePlayer(String uuid, boolean muted) {
|
|
|
|
|
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
|
|
|
|
buf.writeUTF("chatpunishments");
|
|
|
|
|
buf.writeUTF(uuid);
|
|
|
|
|
buf.writeBoolean(muted);
|
|
|
|
|
}
|
2021-06-27 17:58:34 +00:00
|
|
|
}
|