2021-05-13 12:11:59 +00:00
|
|
|
package com.alttd.chat.handlers;
|
2021-05-10 08:01:35 +00:00
|
|
|
|
2021-05-22 18:34:32 +00:00
|
|
|
import com.alttd.chat.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-06-02 17:55:55 +00:00
|
|
|
import com.alttd.chat.managers.RegexManager;
|
2021-06-23 19:16:48 +00:00
|
|
|
import com.alttd.chat.objects.ChatUser;
|
2021-05-22 18:34:32 +00:00
|
|
|
import com.alttd.chat.util.Utility;
|
2021-05-10 08:01:35 +00:00
|
|
|
import com.velocitypowered.api.command.CommandSource;
|
|
|
|
|
import com.velocitypowered.api.proxy.Player;
|
|
|
|
|
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
|
|
|
MiniMessage miniMessage = MiniMessage.get();
|
2021-05-22 18:34:32 +00:00
|
|
|
|
2021-06-23 19:16:48 +00:00
|
|
|
List<Template> templates = new ArrayList<>(List.of(
|
|
|
|
|
Template.of("sender", senderUser.getDisplayName()),
|
|
|
|
|
Template.of("receiver", targetUser.getDisplayName()),
|
|
|
|
|
Template.of("message", message),
|
|
|
|
|
Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
|
2021-05-12 08:43:30 +00:00
|
|
|
|
2021-06-23 19:16:48 +00:00
|
|
|
Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, templates);
|
|
|
|
|
Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, templates);
|
2021-05-12 08:43:30 +00:00
|
|
|
|
2021-06-23 19:16:48 +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) {
|
|
|
|
|
String senderName = Config.CONSOLENAME;
|
|
|
|
|
String serverName = "Altitude";
|
|
|
|
|
if (commandSource instanceof Player) {
|
|
|
|
|
Player sender = (Player) commandSource;
|
|
|
|
|
senderName = sender.getUsername();
|
|
|
|
|
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MiniMessage miniMessage = MiniMessage.get();
|
|
|
|
|
|
|
|
|
|
message = Utility.parseColors(message);
|
|
|
|
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
map.put("sender", senderName);
|
|
|
|
|
//map.put("message", event.getMessage());
|
|
|
|
|
map.put("message", Utility.parseColors(message));
|
|
|
|
|
map.put("server", serverName);
|
|
|
|
|
|
|
|
|
|
Component component = miniMessage.parse(Config.GACFORMAT, map);
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
// todo construct the mail and notify the player if online?
|
2021-05-22 18:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param message the messaged to be parsed by the chatfilter
|
|
|
|
|
* @param player the player invoking the message
|
|
|
|
|
* @return the message altered by the filters
|
|
|
|
|
*/
|
|
|
|
|
public String applyChatFilters(String message, Player player) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
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-05-10 08:01:35 +00:00
|
|
|
}
|