mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
Finish up message sending
This commit is contained in:
1 parent
db2a2325fc
commit
d7910751be
4 files changed
+68
-44
No files matched your search
@@ -232,7 +232,10 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageToBungee(Player player, Component component) {
|
public void sendMessageToBungee(Player player, Component component) {
|
||||||
carbonChat.getPluginMessageManager().sendComponent(this, player, component);
|
carbonChat.getMessageManager().sendMessage("whisper-component", player.getUniqueId(), (byteArray) -> {
|
||||||
|
byteArray.writeUTF(this.getKey());
|
||||||
|
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(component));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean canPlayerSee(ChatUser target, boolean checkSpying) {
|
public Boolean canPlayerSee(ChatUser target, boolean checkSpying) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.draycia.carbon.messaging;
|
package net.draycia.carbon.messaging;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import net.draycia.carbon.CarbonChat;
|
import net.draycia.carbon.CarbonChat;
|
||||||
import net.draycia.carbon.channels.ChatChannel;
|
import net.draycia.carbon.channels.ChatChannel;
|
||||||
import net.draycia.carbon.messaging.impl.BungeeMessageService;
|
import net.draycia.carbon.messaging.impl.BungeeMessageService;
|
||||||
@@ -9,6 +10,7 @@ import net.kyori.adventure.text.format.TextColor;
|
|||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class MessageManager {
|
public class MessageManager {
|
||||||
|
|
||||||
@@ -125,4 +127,8 @@ public class MessageManager {
|
|||||||
return messageService;
|
return messageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String key, UUID uuid, Consumer<ByteArrayDataOutput> consumer) {
|
||||||
|
getMessageService().sendMessage(key, uuid, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -82,21 +82,24 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
nickname = CarbonChat.LEGACY.serialize(component);
|
nickname = CarbonChat.LEGACY.serialize(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nickname = nickname;
|
final String newNickname = nickname;
|
||||||
|
this.nickname = newNickname;
|
||||||
|
|
||||||
if (isOnline()) {
|
if (isOnline()) {
|
||||||
this.asPlayer().setDisplayName(nickname);
|
this.asPlayer().setDisplayName(newNickname);
|
||||||
|
|
||||||
if (carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
if (carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
||||||
this.asPlayer().setPlayerListName(nickname);
|
this.asPlayer().setPlayerListName(newNickname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromRemote) {
|
if (!fromRemote) {
|
||||||
if (nickname == null) {
|
if (nickname == null) {
|
||||||
this.publishChangeToRedis("nickname-reset", "true");
|
carbonChat.getMessageManager().sendMessage("nickname-reset", this.getUUID(), (byteArray) -> {});
|
||||||
} else {
|
} else {
|
||||||
this.publishChangeToRedis("nickname", nickname);
|
carbonChat.getMessageManager().sendMessage("nickname", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeUTF(newNickname);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +127,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
this.selectedChannel = chatChannel.getKey();
|
this.selectedChannel = chatChannel.getKey();
|
||||||
|
|
||||||
if (!fromRemote) {
|
if (!fromRemote) {
|
||||||
this.publishChangeToRedis("selected-channel", chatChannel.getKey());
|
carbonChat.getMessageManager().sendMessage("selected-channel", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeUTF(chatChannel.getKey());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,18 +146,18 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
@Override
|
@Override
|
||||||
public void setIgnoringUser(UUID uuid, boolean ignoring, boolean fromRemote) {
|
public void setIgnoringUser(UUID uuid, boolean ignoring, boolean fromRemote) {
|
||||||
if (ignoring) {
|
if (ignoring) {
|
||||||
if (!fromRemote) {
|
|
||||||
this.publishChangeToRedis("ignoring-user", uuid.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
ignoredUsers.add(uuid);
|
ignoredUsers.add(uuid);
|
||||||
} else {
|
} else {
|
||||||
if (!fromRemote) {
|
|
||||||
this.publishChangeToRedis("unignoring-user", uuid.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
ignoredUsers.remove(uuid);
|
ignoredUsers.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fromRemote) {
|
||||||
|
carbonChat.getMessageManager().sendMessage("ignoring-user", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeLong(uuid.getMostSignificantBits());
|
||||||
|
byteArray.writeLong(uuid.getLeastSignificantBits());
|
||||||
|
byteArray.writeBoolean(ignoring);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> getIgnoredUsers() {
|
public List<UUID> getIgnoredUsers() {
|
||||||
@@ -164,7 +169,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
this.muted = muted;
|
this.muted = muted;
|
||||||
|
|
||||||
if (!fromRemote) {
|
if (!fromRemote) {
|
||||||
this.publishChangeToRedis("muted", muted ? "true" : "false");
|
carbonChat.getMessageManager().sendMessage("muted", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeBoolean(muted);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +185,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
this.shadowMuted = shadowMuted;
|
this.shadowMuted = shadowMuted;
|
||||||
|
|
||||||
if (!fromRemote) {
|
if (!fromRemote) {
|
||||||
this.publishChangeToRedis("shadow-muted", shadowMuted ? "true" : "false");
|
carbonChat.getMessageManager().sendMessage("shadow-muted", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeBoolean(shadowMuted);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +207,10 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
this.replyTarget = target;
|
this.replyTarget = target;
|
||||||
|
|
||||||
if (!fromRemote) {
|
if (!fromRemote) {
|
||||||
this.publishChangeToRedis("reply-target", target.toString());
|
carbonChat.getMessageManager().sendMessage("reply-target", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeLong(target.getMostSignificantBits());
|
||||||
|
byteArray.writeLong(target.getLeastSignificantBits());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +230,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
this.spyingWhispers = spyingWhispers;
|
this.spyingWhispers = spyingWhispers;
|
||||||
|
|
||||||
if (!fromRemote) {
|
if (!fromRemote) {
|
||||||
this.publishChangeToRedis("spying-whispers", spyingWhispers ? "true" : "false");
|
carbonChat.getMessageManager().sendMessage("spying-whispers", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeBoolean(spyingWhispers);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +304,14 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (sender.isOnline()) {
|
} else if (sender.isOnline()) {
|
||||||
carbonChat.getPluginMessageManager().sendComponentToPlayer(sender, this, toPlayerComponent, fromPlayerComponent);
|
sender.sendMessage(toPlayerComponent);
|
||||||
|
|
||||||
|
// TODO: make sure this works lol
|
||||||
|
carbonChat.getMessageManager().sendMessage("whisper-component", sender.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeLong(this.getUUID().getMostSignificantBits());
|
||||||
|
byteArray.writeLong(this.getUUID().getLeastSignificantBits());
|
||||||
|
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(fromPlayerComponent));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
@@ -310,12 +331,4 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
"target", targetName, "sender", senderName));
|
"target", targetName, "sender", senderName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void publishChangeToRedis(String key, String value) {
|
|
||||||
if (carbonChat.getRedisManager() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
carbonChat.getRedisManager().publishChange(uuid, key, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+18
-16
@@ -17,14 +17,16 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
|||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
private final String channel;
|
private final String channel;
|
||||||
|
|
||||||
|
private transient CarbonChat carbonChat;
|
||||||
|
|
||||||
public SimpleUserChannelSettings(UUID uuid, String channel) {
|
public SimpleUserChannelSettings(UUID uuid, String channel) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
||||||
|
carbonChat = (CarbonChat)Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
}
|
}
|
||||||
|
|
||||||
private CarbonChatUser getUser() {
|
private CarbonChatUser getUser() {
|
||||||
CarbonChat carbonChat = (CarbonChat)Bukkit.getPluginManager().getPlugin("CarbonChat");
|
|
||||||
|
|
||||||
return (CarbonChatUser)carbonChat.getUserService().wrap(uuid);
|
return (CarbonChatUser)carbonChat.getUserService().wrap(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,12 +39,11 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
|||||||
public void setSpying(boolean spying, boolean fromRemote) {
|
public void setSpying(boolean spying, boolean fromRemote) {
|
||||||
this.spying = spying;
|
this.spying = spying;
|
||||||
|
|
||||||
if (fromRemote) {
|
if (!fromRemote) {
|
||||||
if (spying) {
|
carbonChat.getMessageManager().sendMessage("spying-channel", uuid, (byteArray) -> {
|
||||||
getUser().publishChangeToRedis("spying-channel", channel);
|
byteArray.writeUTF(channel);
|
||||||
} else {
|
byteArray.writeBoolean(spying);
|
||||||
getUser().publishChangeToRedis("unspying-channel", channel);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,12 +56,11 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
|||||||
public void setIgnoring(boolean ignored, boolean fromRemote) {
|
public void setIgnoring(boolean ignored, boolean fromRemote) {
|
||||||
this.ignored = ignored;
|
this.ignored = ignored;
|
||||||
|
|
||||||
if (fromRemote) {
|
if (!fromRemote) {
|
||||||
if (spying) {
|
carbonChat.getMessageManager().sendMessage("ignoring-channel", uuid, (byteArray) -> {
|
||||||
getUser().publishChangeToRedis("ignoring-channel", channel);
|
byteArray.writeUTF(channel);
|
||||||
} else {
|
byteArray.writeBoolean(ignored);
|
||||||
getUser().publishChangeToRedis("unignoring-channel", channel);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +81,10 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
|||||||
this.color = color.asHexString();
|
this.color = color.asHexString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromRemote) {
|
if (!fromRemote) {
|
||||||
getUser().publishChangeToRedis("channel-color", this.color);
|
carbonChat.getMessageManager().sendMessage("channel-color", uuid, (byteArray) -> {
|
||||||
|
byteArray.writeUTF(color.asHexString());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user