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-02 17:55:55 +00:00
|
|
|
import com.alttd.chat.managers.ChatUserManager;
|
|
|
|
|
import com.alttd.chat.managers.RegexManager;
|
|
|
|
|
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-05-22 18:34:32 +00:00
|
|
|
import net.kyori.adventure.text.minimessage.Template;
|
2021-05-10 08:01:35 +00:00
|
|
|
|
2021-05-24 07:53:45 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
2021-05-10 08:01:35 +00:00
|
|
|
|
|
|
|
|
public class ChatHandler {
|
|
|
|
|
|
2021-05-22 18:34:32 +00:00
|
|
|
public void globalChat(Player player, String message) {
|
|
|
|
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
|
|
|
|
if(user == null) return;
|
|
|
|
|
MiniMessage miniMessage = MiniMessage.get();
|
|
|
|
|
if(!user.isGcOn()) {
|
|
|
|
|
player.sendMessage(miniMessage.parse(Config.GCNOTENABLED));// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message = Utility.parseColors(message);
|
|
|
|
|
if(!player.hasPermission("chat.format")) // Todo PR fix for '<3' to minimessage
|
|
|
|
|
message = miniMessage.stripTokens(message);
|
|
|
|
|
|
|
|
|
|
message = RegexManager.replaceText(message); // this filters the message TODO should staff be able to bypass filters?
|
|
|
|
|
|
|
|
|
|
List<Template> templates = new ArrayList<>(List.of(
|
|
|
|
|
Template.of("sender", user.getDisplayName()),
|
|
|
|
|
Template.of("prefix", user.getPrefix()),
|
|
|
|
|
Template.of("message", message),
|
|
|
|
|
Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")
|
|
|
|
|
/*,Template.of("[i]", itemComponent(sender.getInventory().getItemInMainHand()))*/ //Todo move this into ChatFilters
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
Component component = miniMessage.parse(Config.GCFORMAT, templates);
|
|
|
|
|
|
|
|
|
|
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(component);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void privateMessage(CommandSource commandSource, Player recipient, String message) {
|
|
|
|
|
// todo get the chatUserinstance of both players and or console - @teri should console be able to /msg?
|
2021-05-12 08:43:30 +00:00
|
|
|
String senderName;
|
|
|
|
|
String receiverName;
|
|
|
|
|
if (commandSource instanceof Player) {
|
2021-05-22 18:34:32 +00:00
|
|
|
Player sender = (Player) commandSource;
|
2021-05-12 08:43:30 +00:00
|
|
|
senderName = sender.getUsername();
|
|
|
|
|
//plugin.getChatHandler().getChatPlayer(sender.getUniqueId()).setReplyTarget(event.getRecipient().getUniqueId()); // TODO this needs to be cleaner
|
|
|
|
|
} else {
|
2021-05-13 22:06:21 +00:00
|
|
|
senderName = Config.CONSOLENAME;
|
2021-05-12 08:43:30 +00:00
|
|
|
}
|
2021-05-22 18:34:32 +00:00
|
|
|
receiverName = recipient.getUsername();
|
2021-05-12 08:43:30 +00:00
|
|
|
|
|
|
|
|
MiniMessage miniMessage = MiniMessage.get();
|
|
|
|
|
|
2021-05-22 18:34:32 +00:00
|
|
|
message = Utility.parseColors(message);
|
|
|
|
|
if(!commandSource.hasPermission("chat.format")) // Todo PR fix for '<3' to minimessage
|
|
|
|
|
message = miniMessage.stripTokens(message);
|
|
|
|
|
|
|
|
|
|
message = RegexManager.replaceText(message); // this filters the message TODO should staff be able to bypass filters?
|
|
|
|
|
|
|
|
|
|
// List<Template> templates = new ArrayList<>(List.of(
|
|
|
|
|
// Template.of("sender", user.getDisplayName()),
|
|
|
|
|
// Template.of("prefix", user.getPrefix()),
|
|
|
|
|
// Template.of("message", message),
|
|
|
|
|
// Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")
|
2021-06-06 19:32:13 +00:00
|
|
|
// /*,Template.of("[i]" , itemComponent(sender.getInventory().getItemInMainHand()))*/ //Todo move this into ChatFilters
|
2021-05-22 18:34:32 +00:00
|
|
|
// ));
|
|
|
|
|
|
2021-05-12 08:43:30 +00:00
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
map.put("sender", senderName);
|
|
|
|
|
map.put("receiver", receiverName);
|
2021-05-22 18:34:32 +00:00
|
|
|
map.put("message", message);
|
|
|
|
|
// map.put("server", event.getRecipient().getCurrentServer().isPresent() ? event.getRecipient().getCurrentServer().get().getServerInfo().getName() : "Altitude");
|
2021-05-12 08:43:30 +00:00
|
|
|
|
|
|
|
|
Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, map);
|
|
|
|
|
Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, map);
|
|
|
|
|
|
2021-05-22 18:34:32 +00:00
|
|
|
commandSource.sendMessage(senderMessage);
|
|
|
|
|
recipient.sendMessage(receiverMessage);
|
2021-05-12 08:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 19:32:13 +00:00
|
|
|
public void globalAdminChat(String message) {
|
|
|
|
|
MiniMessage miniMessage = MiniMessage.get();
|
|
|
|
|
|
|
|
|
|
Component component = miniMessage.parse(Config.GACFORMAT);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|