Merge Nicknames
This commit is contained in:
+17
-37
@@ -1,11 +1,8 @@
|
||||
package com.alttd.velocitychat.listeners;
|
||||
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
@@ -17,13 +14,10 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PluginMessageListener {
|
||||
|
||||
//todo add an extra listener for nicknames?
|
||||
private final ChannelIdentifier identifier;
|
||||
|
||||
public PluginMessageListener(ChannelIdentifier identifier){
|
||||
@@ -45,21 +39,16 @@ public class PluginMessageListener {
|
||||
String channel = in.readUTF();
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
switch (channel) {
|
||||
case "globalchat":
|
||||
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF(), in.readUTF());
|
||||
break;
|
||||
case "globaladminchat":
|
||||
VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
||||
break;
|
||||
case "privatemessage":
|
||||
VelocityChat.getPlugin().getChatHandler().privateMessage(in.readUTF(), in.readUTF(), in.readUTF());
|
||||
break;
|
||||
case "chatchannel": {
|
||||
case "globalchat" -> VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF(), in.readUTF());
|
||||
case "globaladminchat" -> VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
||||
case "privatemessage" ->
|
||||
VelocityChat.getPlugin().getChatHandler().privateMessage(in.readUTF(), in.readUTF(), in.readUTF());
|
||||
case "chatchannel" -> {
|
||||
String channelName = in.readUTF();
|
||||
CustomChannel chatChannel = (CustomChannel) CustomChannel.getChatChannel(channelName);
|
||||
|
||||
if (chatChannel == null) {
|
||||
ALogger.warn("Received non existent channel" + channelName +".");
|
||||
ALogger.warn("Received non existent channel" + channelName + ".");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -68,7 +57,7 @@ public class PluginMessageListener {
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData())));
|
||||
break;
|
||||
}
|
||||
case "party": {
|
||||
case "party" -> {
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(
|
||||
UUID.fromString(in.readUTF()),
|
||||
in.readUTF(),
|
||||
@@ -76,30 +65,21 @@ public class PluginMessageListener {
|
||||
serverConnection);
|
||||
break;
|
||||
}
|
||||
case "NickNameAccepted": {
|
||||
try {
|
||||
short len = in.readShort();
|
||||
byte[] msgbytes = new byte[len];
|
||||
in.readFully(msgbytes);
|
||||
|
||||
DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
|
||||
UUID uuid = UUID.fromString(msgin.readUTF());
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
chatUser.reloadDisplayName();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
default:
|
||||
// nicknames WIP
|
||||
// case "NickNameRequest", "NickNameAccepted", "NickNameSet", "NickNameDenied" -> {
|
||||
// ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
// proxy.getAllServers().forEach(registeredServer ->
|
||||
// registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData()));
|
||||
// break;
|
||||
// }
|
||||
default -> {
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
|
||||
for (RegisteredServer registeredServer : proxy.getAllServers()) {
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user