progress
This commit is contained in:
@@ -2,52 +2,19 @@ package com.alttd.chat.handlers;
|
||||
|
||||
import com.alttd.chat.VelocityChat;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
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;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChatHandler {
|
||||
|
||||
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?
|
||||
String senderName;
|
||||
@@ -92,9 +59,7 @@ public class ChatHandler {
|
||||
}
|
||||
|
||||
public void globalAdminChat(String message) {
|
||||
MiniMessage miniMessage = MiniMessage.get();
|
||||
|
||||
Component component = miniMessage.parse(Config.GACFORMAT);
|
||||
Component component = GsonComponentSerializer.gson().deserialize(message);
|
||||
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")/*TODO permission*/).forEach(target -> {
|
||||
target.sendMessage(component);
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.alttd.chat.data.ServerWrapper;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -36,10 +37,12 @@ public class ServerHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendGlobalChat(Component message) {
|
||||
public void sendGlobalChat(String message) {
|
||||
Component component = GsonComponentSerializer.gson().deserialize(message);
|
||||
|
||||
servers.stream()
|
||||
.filter(serverWrapper -> serverWrapper.globalChat())
|
||||
.forEach(serverWrapper -> serverWrapper.getRegisteredServer().sendMessage(message));
|
||||
.forEach(serverWrapper -> serverWrapper.getRegisteredServer().sendMessage(component));
|
||||
}
|
||||
|
||||
public List<ServerWrapper> getServers()
|
||||
|
||||
Reference in New Issue
Block a user