mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Add cross server whispering
This commit is contained in:
1 parent
faf3f34f0d
commit
16d98d35cc
3 files changed
+53
-25
No files matched your search
@@ -70,10 +70,6 @@
|
|||||||
<pattern>org.checkerframework</pattern>
|
<pattern>org.checkerframework</pattern>
|
||||||
<shadedPattern>net.draycia.simplechat.libs.checkerframework</shadedPattern>
|
<shadedPattern>net.draycia.simplechat.libs.checkerframework</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
|
||||||
<pattern>org.apache</pattern>
|
|
||||||
<shadedPattern>net.draycia.simplechat.libs.apache</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
@@ -156,6 +152,12 @@
|
|||||||
<url>https://dl.bintray.com/ichbinjoe/public/</url>
|
<url>https://dl.bintray.com/ichbinjoe/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<!-- BungeeChannelAPI -->
|
||||||
|
<repository>
|
||||||
|
<id>codemc-repo</id>
|
||||||
|
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
<!-- mcMMO and MiniMessage must be compiled locally -->
|
<!-- mcMMO and MiniMessage must be compiled locally -->
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
@@ -262,5 +264,11 @@
|
|||||||
<artifactId>HikariCP</artifactId>
|
<artifactId>HikariCP</artifactId>
|
||||||
<version>2.4.1</version>
|
<version>2.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.leonardosnt</groupId>
|
||||||
|
<artifactId>bungeechannelapi</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -3,6 +3,7 @@ package net.draycia.simplechat.managers;
|
|||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
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 io.github.leonardosnt.bungeechannelapi.BungeeChannelApi;
|
||||||
import net.draycia.simplechat.SimpleChat;
|
import net.draycia.simplechat.SimpleChat;
|
||||||
import net.draycia.simplechat.channels.ChatChannel;
|
import net.draycia.simplechat.channels.ChatChannel;
|
||||||
import net.draycia.simplechat.storage.ChatUser;
|
import net.draycia.simplechat.storage.ChatUser;
|
||||||
@@ -18,12 +19,15 @@ import java.util.UUID;
|
|||||||
public class PluginMessageManager implements PluginMessageListener {
|
public class PluginMessageManager implements PluginMessageListener {
|
||||||
|
|
||||||
private SimpleChat simpleChat;
|
private SimpleChat simpleChat;
|
||||||
|
private BungeeChannelApi api;
|
||||||
|
|
||||||
public PluginMessageManager(SimpleChat simpleChat) {
|
public PluginMessageManager(SimpleChat simpleChat) {
|
||||||
this.simpleChat = simpleChat;
|
this.simpleChat = simpleChat;
|
||||||
|
|
||||||
simpleChat.getServer().getMessenger().registerOutgoingPluginChannel(simpleChat, "BungeeCord");
|
simpleChat.getServer().getMessenger().registerOutgoingPluginChannel(simpleChat, "BungeeCord");
|
||||||
simpleChat.getServer().getMessenger().registerIncomingPluginChannel(simpleChat, "BungeeCord", this);
|
simpleChat.getServer().getMessenger().registerIncomingPluginChannel(simpleChat, "BungeeCord", this);
|
||||||
|
|
||||||
|
api = BungeeChannelApi.of(simpleChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,6 +49,8 @@ public class PluginMessageManager implements PluginMessageListener {
|
|||||||
onMessageReceived(msg);
|
onMessageReceived(msg);
|
||||||
} else if (subchannel.equals("simplechat:component")) {
|
} else if (subchannel.equals("simplechat:component")) {
|
||||||
onComponentReceived(msg);
|
onComponentReceived(msg);
|
||||||
|
} else if (subchannel.equals("simplechat:whisper")) {
|
||||||
|
onWhisperReceived(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,41 +108,54 @@ public class PluginMessageManager implements PluginMessageListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onWhisperReceived(ByteArrayDataInput in) {
|
||||||
|
UUID targetUUID;
|
||||||
|
|
||||||
|
try {
|
||||||
|
targetUUID = UUID.fromString(in.readUTF());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String chatMessage = in.readUTF();
|
||||||
|
|
||||||
|
ChatUser target = simpleChat.getUserService().wrap(targetUUID);
|
||||||
|
target.sendMessage(MiniMessage.get().parse(chatMessage));
|
||||||
|
}
|
||||||
|
|
||||||
public void sendMessage(ChatChannel chatChannel, Player player, String message) {
|
public void sendMessage(ChatChannel chatChannel, Player player, String message) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
|
|
||||||
out.writeUTF("Forward");
|
|
||||||
out.writeUTF("ALL");
|
|
||||||
out.writeUTF("simplechat:message");
|
|
||||||
|
|
||||||
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
msg.writeUTF(chatChannel.getName());
|
msg.writeUTF(chatChannel.getName());
|
||||||
msg.writeUTF(player.getUniqueId().toString());
|
msg.writeUTF(player.getUniqueId().toString());
|
||||||
msg.writeUTF(message);
|
msg.writeUTF(message);
|
||||||
|
|
||||||
out.writeShort(msg.toByteArray().length);
|
api.forward("ALL", "simplechat:message", msg.toByteArray());
|
||||||
out.write(msg.toByteArray());
|
|
||||||
|
|
||||||
player.sendPluginMessage(simpleChat, "BungeeCord", out.toByteArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendComponent(ChatChannel chatChannel, Player player, Component component) {
|
public void sendComponent(ChatChannel chatChannel, Player player, Component component) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
|
|
||||||
out.writeUTF("Forward");
|
|
||||||
out.writeUTF("ALL");
|
|
||||||
out.writeUTF("simplechat:component");
|
|
||||||
|
|
||||||
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
msg.writeUTF(chatChannel.getName());
|
msg.writeUTF(chatChannel.getName());
|
||||||
msg.writeUTF(player.getUniqueId().toString());
|
msg.writeUTF(player.getUniqueId().toString());
|
||||||
msg.writeUTF(MiniMessage.get().serialize(component));
|
msg.writeUTF(MiniMessage.get().serialize(component));
|
||||||
|
|
||||||
out.writeShort(msg.toByteArray().length);
|
api.forward("ALL", "simplechat:component", msg.toByteArray());
|
||||||
out.write(msg.toByteArray());
|
}
|
||||||
|
|
||||||
player.sendPluginMessage(simpleChat, "BungeeCord", out.toByteArray());
|
public void sendComponentToPlayer(Player sender, ChatUser target, Component component) {
|
||||||
|
api.getPlayerList("ALL").whenComplete((result, error) -> {
|
||||||
|
if (!result.contains(target.asOfflinePlayer().getName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
|
msg.writeUTF(target.getUUID().toString());
|
||||||
|
msg.writeUTF(MiniMessage.get().serialize(component));
|
||||||
|
|
||||||
|
api.forward("ALL", "simplechat:whisper", msg.toByteArray());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import net.kyori.adventure.key.Key;
|
|||||||
import net.kyori.adventure.sound.Sound;
|
import net.kyori.adventure.sound.Sound;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -190,8 +191,8 @@ public class SimpleChatUser implements ChatUser, ForwardingAudience {
|
|||||||
|
|
||||||
this.playSound(Sound.of(key, source, volume, pitch));
|
this.playSound(Sound.of(key, source, volume, pitch));
|
||||||
}
|
}
|
||||||
} else {
|
} else if (sender.isOnline()) {
|
||||||
// TODO: cross server msg support, don't forget to include /ignore support
|
simpleChat.getPluginMessageManager().sendComponentToPlayer(sender.asPlayer(), this, fromPlayerComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user