This commit is contained in:
destro174 2021-07-30 03:16:41 +02:00
parent ead360ee1c
commit 9d8d4b3853
14 changed files with 127 additions and 97 deletions

View File

@ -68,8 +68,8 @@ public final class ServerConfig {
/** DO NOT EDIT ANYTHING ABOVE **/ /** DO NOT EDIT ANYTHING ABOVE **/
public boolean GLOBALCHAT = true; // TODO - @teri idk what servers need to have this enabled public boolean GLOBALCHAT = true;
public boolean JOINLEAVEMSSAGES = true; // TODO set to false on lobby public boolean JOINLEAVEMSSAGES = true;
private void ServerSettings() { private void ServerSettings() {
GLOBALCHAT = getBoolean("global-chat-enabled", GLOBALCHAT); GLOBALCHAT = getBoolean("global-chat-enabled", GLOBALCHAT);
JOINLEAVEMSSAGES = getBoolean("joinleave-messages-enabled", JOINLEAVEMSSAGES); JOINLEAVEMSSAGES = getBoolean("joinleave-messages-enabled", JOINLEAVEMSSAGES);

View File

@ -340,7 +340,8 @@ public class Queries {
statement.setString(1, user.getUuid().toString()); statement.setString(1, user.getUuid().toString());
statement.setInt(2, user.getPartyId()); statement.setInt(2, user.getPartyId());
statement.setInt(3, user.toggledPartyChat() ? 1 : 0); statement.setInt(3, user.toggledPartyChat() ? 1 : 0);
statement.setInt(5, user.isGcOn() ? 1 : 0); statement.setInt(4, 0);
// statement.setInt(5, user.isGcOn() ? 1 : 0);
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
@ -423,10 +424,10 @@ public class Queries {
statement.setString(1, user.getUuid().toString()); statement.setString(1, user.getUuid().toString());
statement.setInt(2, user.getPartyId()); statement.setInt(2, user.getPartyId());
statement.setInt(3, user.toggledPartyChat() ? 1 : 0); statement.setInt(3, user.toggledPartyChat() ? 1 : 0);
statement.setInt(4, user.isGcOn() ? 1 : 0); statement.setInt(4, 0);
statement.setInt(5, user.getPartyId()); statement.setInt(5, user.getPartyId());
statement.setInt(6, user.toggledPartyChat() ? 1 : 0); statement.setInt(6, user.toggledPartyChat() ? 1 : 0);
statement.setInt(7, user.isGcOn() ? 1 : 0); statement.setInt(7, 0);
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -27,7 +27,7 @@ public final class ChatUserManager {
public static ChatUser getChatUser(UUID uuid) { public static ChatUser getChatUser(UUID uuid) {
for(ChatUser user : chatUsers) { for(ChatUser user : chatUsers) {
if(uuid.compareTo(user.getUuid()) == 0) { if(uuid.equals(user.getUuid())) {
return user; return user;
} }
} }

View File

@ -17,7 +17,7 @@ public class ChatUser {
// private Component prefix; // doesn't need saving, we get this from luckperms // private Component prefix; // doesn't need saving, we get this from luckperms
// private Component staffPrefix; // doesn't need saving, we get this from luckperms // private Component staffPrefix; // doesn't need saving, we get this from luckperms
// private Component prefixAll; // doesn't need saving, we get this from luckperms // private Component prefixAll; // doesn't need saving, we get this from luckperms
private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat //private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback? private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback?
private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in
@ -41,7 +41,7 @@ public class ChatUser {
// //
// prefixAll = Utility.getPrefix(uuid, false); // prefixAll = Utility.getPrefix(uuid, false);
this.toggleGc = toggleGc; //this.toggleGc = toggleGc;
replyTarget = null; replyTarget = null;
gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this? gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this?
mails = Queries.getMails(uuid); mails = Queries.getMails(uuid);
@ -89,14 +89,6 @@ public class ChatUser {
return Utility.getPrefix(uuid, false); return Utility.getPrefix(uuid, false);
} }
public void toggleGc() {
toggleGc = !toggleGc;
}
public boolean isGcOn() {
return toggleGc;
}
public String getReplyTarget() { public String getReplyTarget() {
return replyTarget; return replyTarget;
} }

View File

@ -10,13 +10,10 @@ import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPerms;
import net.luckperms.api.model.group.Group; import net.luckperms.api.model.group.Group;
import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.User;
import org.bukkit.Bukkit; import net.luckperms.api.node.Node;
import org.bukkit.entity.Player;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.UUID;
public class Utility { public class Utility {
@ -58,22 +55,17 @@ public class Utility {
LuckPerms luckPerms = ChatAPI.get().getLuckPerms(); LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid); User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return Component.empty(); if(user == null) return Component.empty();
if(single) { if(!single) {
Group group = luckPerms.getGroupManager().getGroup(user.getPrimaryGroup()); Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
if(group != null) inheritedGroups.stream()
prefix.append(group.getCachedData().getMetaData().getPrefix()); .sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0)))
// Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions()); .forEach(group -> {
// inheritedGroups.stream() if (Config.PREFIXGROUPS.contains(group.getName())) {
// .sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0))) prefix.append(group.getCachedData().getMetaData().getPrefix());
// .distinct() }
// .forEach(group -> { });
// if (Config.PREFIXGROUPS.contains(group.getName())) {
// prefix.append("[").append(group.getCachedData().getMetaData().getPrefix()).append("]");
// }
// });
} else {
prefix.append(user.getCachedData().getMetaData().getPrefix());
} }
prefix.append(user.getCachedData().getMetaData().getPrefix());
return applyColor(prefix.toString()); return applyColor(prefix.toString());
} }
@ -98,6 +90,21 @@ public class Utility {
return user.getUsername(); return user.getUsername();
} }
public static void flipPermission(UUID uuid, String permission) {
ChatAPI.get().getLuckPerms().getUserManager().modifyUser(uuid, user -> {
// Add the permission
user.data().add(Node.builder(permission)
.value(user.getCachedData().getPermissionData().checkPermission(permission).asBoolean()).build());
});
}
public static boolean hasPermission(UUID uuid, String permission) {
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return false;
return user.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
}
public static Component applyColor(String message) { public static Component applyColor(String message) {
String hexColor1 = ""; String hexColor1 = "";
String hexColor2 = ""; String hexColor2 = "";
@ -172,23 +179,4 @@ public class Utility {
: miniMessage.parse(stringBuilder.toString()); : miniMessage.parse(stringBuilder.toString());
} }
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
MiniMessage miniMessage = MiniMessage.get();
Bukkit.getOnlinePlayers().forEach(a ->{
Component blockedNotification = miniMessage.parse("<red>[" + prefix + "] "
+ getDisplayName(player.getUniqueId())
+ (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")
+ input + "</red>");
if (a.hasPermission("chat.alert-blocked")) {
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
}
});
player.sendMessage(miniMessage.parse("<red>The language you used in your message is not allowed, " +
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
}
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
sendBlockedNotification(prefix, player, PlainComponentSerializer.plain().serialize(input), target);
}
} }

View File

@ -2,12 +2,14 @@ package com.alttd.chat;
import com.alttd.chat.commands.*; import com.alttd.chat.commands.*;
import com.alttd.chat.config.Config; import com.alttd.chat.config.Config;
import com.alttd.chat.config.ServerConfig;
import com.alttd.chat.database.DatabaseConnection; import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.handler.ChatHandler; import com.alttd.chat.handler.ChatHandler;
import com.alttd.chat.listeners.ChatListener; import com.alttd.chat.listeners.ChatListener;
import com.alttd.chat.listeners.PlayerListener; import com.alttd.chat.listeners.PlayerListener;
import com.alttd.chat.listeners.PluginMessage; import com.alttd.chat.listeners.PluginMessage;
import com.alttd.chat.util.ALogger; import com.alttd.chat.util.ALogger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -20,6 +22,7 @@ public class ChatPlugin extends JavaPlugin {
private ChatHandler chatHandler; private ChatHandler chatHandler;
private String messageChannel; private String messageChannel;
private ServerConfig serverConfig;
@Override @Override
public void onEnable() { public void onEnable() {
@ -28,9 +31,12 @@ public class ChatPlugin extends JavaPlugin {
chatAPI = new ChatImplementation(); chatAPI = new ChatImplementation();
chatHandler = new ChatHandler(); chatHandler = new ChatHandler();
DatabaseConnection.initialize(); DatabaseConnection.initialize();
serverConfig = new ServerConfig(Bukkit.getServerName());
registerListener(new PlayerListener(), new ChatListener()); registerListener(new PlayerListener(), new ChatListener());
registerCommand("globalchat", new GlobalChat()); if(serverConfig.GLOBALCHAT) {
registerCommand("toggleglobalchat", new ToggleGlobalChat()); registerCommand("globalchat", new GlobalChat());
registerCommand("toggleglobalchat", new ToggleGlobalChat());
}
registerCommand("message", new Message()); registerCommand("message", new Message());
registerCommand("reply", new Reply()); registerCommand("reply", new Reply());
registerCommand("ignore", new Ignore()); registerCommand("ignore", new Ignore());
@ -67,4 +73,8 @@ public class ChatPlugin extends JavaPlugin {
public ChatHandler getChatHandler() { public ChatHandler getChatHandler() {
return chatHandler; return chatHandler;
} }
public boolean serverGlobalChatEnabled() {
return serverConfig.GLOBALCHAT;
}
} }

View File

@ -1,9 +1,12 @@
package com.alttd.chat.commands; package com.alttd.chat.commands;
import com.alttd.chat.ChatPlugin; import com.alttd.chat.ChatPlugin;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.Queries; import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility;
import jdk.jshell.execution.Util;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -13,6 +16,7 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.Objects; import java.util.Objects;
import java.util.UUID;
public class ToggleGlobalChat implements CommandExecutor { public class ToggleGlobalChat implements CommandExecutor {
@ -24,10 +28,12 @@ public class ToggleGlobalChat implements CommandExecutor {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId()); UUID uuid = ((Player) sender).getUniqueId();
chatUser.toggleGc(); ChatUser chatUser = ChatUserManager.getChatUser(uuid);
Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid()); //chatUser.toggleGc();
sender.sendMessage(MiniMessage.get().parse("You have turned globalchat " + (chatUser.isGcOn() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage Utility.flipPermission(uuid, Config.GCPERMISSION);
//Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
sender.sendMessage(MiniMessage.get().parse("You have turned globalchat " + (Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
} }
}.runTaskAsynchronously(ChatPlugin.getInstance()); }.runTaskAsynchronously(ChatPlugin.getInstance());
return false; return false;

View File

@ -6,6 +6,7 @@ import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager; import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
import com.alttd.chat.util.Utils;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -40,7 +41,7 @@ public class ChatHandler {
user.setReplyTarget(target); user.setReplyTarget(target);
String updatedMessage = RegexManager.replaceText(message); // todo a better way for this String updatedMessage = RegexManager.replaceText(message); // todo a better way for this
if(updatedMessage == null) { if(updatedMessage == null) {
Utility.sendBlockedNotification("DM Language", player, message, target); Utils.sendBlockedNotification("DM Language", player, message, target);
return; // the message was blocked return; // the message was blocked
} }
@ -53,22 +54,29 @@ public class ChatHandler {
List<Template> templates = new ArrayList<>(List.of( List<Template> templates = new ArrayList<>(List.of(
Template.of("message", updatedMessage), Template.of("message", updatedMessage),
Template.of("sendername", player.getName()),
Template.of("receivername", target),
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand())))); Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Component component = miniMessage.parse("<message>", templates); Component component = miniMessage.parse("<message>", templates);
sendPrivateMessage(player, target, "privatemessage", component); sendPrivateMessage(player, target, "privatemessage", component);
Component spymessage = miniMessage.parse(Config.MESSAGESPY, templates);
for(Player pl : Bukkit.getOnlinePlayers()) {
if(pl.hasPermission("chat.social-spy")) { // todo add a toggle for social spy
pl.sendMessage(spymessage);
}
}
} }
public void globalChat(Player player, String message) { public void globalChat(Player player, String message) {
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId()); ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
if(user == null) return; if(!Utility.hasPermission(player.getUniqueId(), Config.GCPERMISSION)) {
if(!user.isGcOn()) {
player.sendMessage(GCNOTENABLED);// GC IS OFF INFORM THEM ABOUT THIS and cancel player.sendMessage(GCNOTENABLED);// GC IS OFF INFORM THEM ABOUT THIS and cancel
return; return;
} }
long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown()); long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown());
if(timeLeft <= Config.GCCOOLDOWN || player.hasPermission("chat.globalchat.cooldownbypass")) { // player is on cooldown and should wait x seconds if(timeLeft <= Config.GCCOOLDOWN && !player.hasPermission("chat.globalchat.cooldownbypass")) { // player is on cooldown and should wait x seconds
player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", Config.GCCOOLDOWN-timeLeft+""))); player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", Config.GCCOOLDOWN-timeLeft+"")));
return; return;
} }
@ -78,7 +86,7 @@ public class ChatHandler {
String updatedMessage = RegexManager.replaceText(message); // todo a better way for this String updatedMessage = RegexManager.replaceText(message); // todo a better way for this
if(updatedMessage == null) { if(updatedMessage == null) {
Utility.sendBlockedNotification("GC Language", player, message, ""); Utils.sendBlockedNotification("GC Language", player, message, "");
return; // the message was blocked return; // the message was blocked
} }

View File

@ -6,6 +6,7 @@ import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager; import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
import com.alttd.chat.util.Utils;
import io.papermc.paper.chat.ChatRenderer; import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent; import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
@ -39,7 +40,7 @@ public class ChatListener implements Listener, ChatRenderer {
message = RegexManager.replaceText(message); // todo a better way for this message = RegexManager.replaceText(message); // todo a better way for this
if(message == null) { if(message == null) {
event.setCancelled(true); event.setCancelled(true);
Utility.sendBlockedNotification("Language", player, input, ""); Utils.sendBlockedNotification("Language", player, input, "");
return; // the message was blocked return; // the message was blocked
} }

View File

@ -5,6 +5,7 @@ import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager; import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
import com.alttd.chat.util.Utils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -46,7 +47,7 @@ public class PlayerListener implements Listener {
message = RegexManager.replaceText(message); // todo a better way for this message = RegexManager.replaceText(message); // todo a better way for this
if (message == null) { if (message == null) {
Utility.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), ""); Utils.sendBlockedNotification("Sign Language" ,event.getPlayer(), PlainComponentSerializer.plain().serialize(component), "");
} }
component = message == null ? Component.empty() : Component.text(message); component = message == null ? Component.empty() : Component.text(message);

View File

@ -24,35 +24,20 @@ public class PluginMessage implements PluginMessageListener {
} }
ByteArrayDataInput in = ByteStreams.newDataInput(bytes); ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
String subChannel = in.readUTF(); String subChannel = in.readUTF();
UUID uuid;String target; Player p;
switch (subChannel) { switch (subChannel) {
case "privatemessagesend": case "privatemessage":
uuid = UUID.fromString(in.readUTF()); UUID uuid = UUID.fromString(in.readUTF());
target = in.readUTF(); String target = in.readUTF();
p = Bukkit.getPlayer(uuid); Player p = Bukkit.getPlayer(uuid);
if(p != null) { if(p != null) {
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
ChatUser user = ChatUserManager.getChatUser(uuid); ChatUser user = ChatUserManager.getChatUser(uuid);
user.setReplyTarget(target); user.setReplyTarget(target);
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
Component spymessage = GsonComponentSerializer.gson().deserialize(in.readUTF());
for(Player pl : Bukkit.getOnlinePlayers()) {
if(pl.hasPermission("chat.social-spy")) { // todo add a toggle for social spy
pl.sendMessage(spymessage);
}
}
}
break;
case "privatemessagesreceived":
uuid = UUID.fromString(in.readUTF());
target = in.readUTF();
p = Bukkit.getPlayer(uuid);
if(p != null) {
ChatUser user = ChatUserManager.getChatUser(uuid);
user.setReplyTarget(target);
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
} }
break; break;
case "globalchat": case "globalchat":
if(ChatPlugin.getInstance().serverGlobalChatEnabled())
Bukkit.broadcast(GsonComponentSerializer.gson().deserialize(in.readUTF()), Config.GCPERMISSION);
break; break;
default: default:
break; break;

View File

@ -0,0 +1,30 @@
package com.alttd.chat.util;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class Utils {
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
MiniMessage miniMessage = MiniMessage.get();
Bukkit.getOnlinePlayers().forEach(a ->{
Component blockedNotification = miniMessage.parse("<red>[" + prefix + "] "
+ Utility.getDisplayName(player.getUniqueId())
+ (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")
+ input + "</red>");
if (a.hasPermission("chat.alert-blocked")) {
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
}
});
player.sendMessage(miniMessage.parse("<red>The language you used in your message is not allowed, " +
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
}
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
sendBlockedNotification(prefix, player, PlainComponentSerializer.plain().serialize(input), target);
}
}

View File

@ -47,24 +47,23 @@ public class ChatHandler {
ServerConnection serverConnection; ServerConnection serverConnection;
if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) { if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
// redirect to the sender // redirect to the sender
String spyMessage = GsonComponentSerializer.gson().serialize(miniMessage.parse(Config.MESSAGESPY, templates));
serverConnection = player.getCurrentServer().get(); serverConnection = player.getCurrentServer().get();
Component component = miniMessage.parse(Config.MESSAGESENDER, templates); Component component = miniMessage.parse(Config.MESSAGESENDER, templates);
ByteArrayDataOutput buf = ByteStreams.newDataOutput(); ByteArrayDataOutput buf = ByteStreams.newDataOutput();
buf.writeUTF("privatemessagesend"); buf.writeUTF("privatemessage");
buf.writeUTF(player.getUniqueId().toString()); buf.writeUTF(player.getUniqueId().toString());
buf.writeUTF(player2.getUsername()); buf.writeUTF(player2.getUsername());
buf.writeUTF(GsonComponentSerializer.gson().serialize(component)); buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
buf.writeUTF(spyMessage);
serverConnection.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray()); serverConnection.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray());
//redirect to the receiver //redirect to the receiver
serverConnection = player2.getCurrentServer().get(); serverConnection = player2.getCurrentServer().get();
component = miniMessage.parse(Config.MESSAGERECIEVER, templates); component = miniMessage.parse(Config.MESSAGERECIEVER, templates);
buf = ByteStreams.newDataOutput(); buf = ByteStreams.newDataOutput();
buf.writeUTF("privatemessagesreceived"); buf.writeUTF("privatemessage");
buf.writeUTF(player2.getUniqueId().toString()); buf.writeUTF(player2.getUniqueId().toString());
buf.writeUTF(player.getUsername()); buf.writeUTF(player.getUsername());
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
serverConnection.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray()); serverConnection.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray());
} }

View File

@ -3,6 +3,8 @@ package com.alttd.chat.handlers;
import com.alttd.chat.VelocityChat; import com.alttd.chat.VelocityChat;
import com.alttd.chat.config.ServerConfig; import com.alttd.chat.config.ServerConfig;
import com.alttd.chat.data.ServerWrapper; import com.alttd.chat.data.ServerWrapper;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -38,11 +40,18 @@ public class ServerHandler {
} }
public void sendGlobalChat(String message) { public void sendGlobalChat(String message) {
Component component = GsonComponentSerializer.gson().deserialize(message); // Component component = GsonComponentSerializer.gson().deserialize(message);
servers.stream() servers.stream()
.filter(serverWrapper -> serverWrapper.globalChat()) .map(ServerWrapper::getRegisteredServer)
.forEach(serverWrapper -> serverWrapper.getRegisteredServer().sendMessage(component)); .forEach(registeredServer -> {
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
buf.writeUTF("globalchat");
buf.writeUTF(message);
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray());
});
// .filter(serverWrapper -> serverWrapper.globalChat())
// .forEach(serverWrapper -> serverWrapper.getRegisteredServer().sendMessage(component));
} }
public List<ServerWrapper> getServers() public List<ServerWrapper> getServers()