mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Tweak bungee handling a little
This commit is contained in:
1 parent
ccaabf4d32
commit
a156eb1973
1 file changed
+15
-23
+15
-23
@@ -8,8 +8,6 @@ import net.draycia.carbon.CarbonChat;
|
|||||||
import net.draycia.carbon.messaging.MessageService;
|
import net.draycia.carbon.messaging.MessageService;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -17,13 +15,13 @@ import java.util.UUID;
|
|||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class BungeeMessageService implements PluginMessageListener, MessageService {
|
public class BungeeMessageService implements MessageService {
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
private final BungeeChannelApi api;
|
private final BungeeChannelApi api;
|
||||||
|
|
||||||
private Map<String, BiConsumer<ChatUser, ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
private final Map<String, BiConsumer<ChatUser, ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||||
private Map<String, BiConsumer<UUID, ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
private final Map<String, BiConsumer<UUID, ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
private final UUID serverUUID = UUID.randomUUID();
|
private final UUID serverUUID = UUID.randomUUID();
|
||||||
|
|
||||||
@@ -31,35 +29,29 @@ public class BungeeMessageService implements PluginMessageListener, MessageServi
|
|||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
|
carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
|
||||||
carbonChat.getServer().getMessenger().registerIncomingPluginChannel(carbonChat, "BungeeCord", this);
|
|
||||||
|
|
||||||
api = BungeeChannelApi.of(carbonChat);
|
api = BungeeChannelApi.of(carbonChat);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
api.registerForwardListener((String channel, Player player, byte[] bytes) -> {
|
||||||
public void onPluginMessageReceived(String channel, @NotNull Player player, @NotNull byte[] message) {
|
ByteArrayDataInput input = ByteStreams.newDataInput(bytes);
|
||||||
if (!channel.equals("BungeeCord")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteArrayDataInput input = ByteStreams.newDataInput(message);
|
// Separated out for ease of debugging.
|
||||||
|
long mostServer = input.readLong();
|
||||||
|
long leastServer = input.readLong();
|
||||||
|
|
||||||
String key = input.readUTF();
|
UUID messageUUID = new UUID(mostServer, leastServer);
|
||||||
short length = input.readShort();
|
|
||||||
byte[] msgbytes = new byte[length];
|
|
||||||
input.readFully(msgbytes);
|
|
||||||
|
|
||||||
ByteArrayDataInput msg = ByteStreams.newDataInput(msgbytes);
|
|
||||||
|
|
||||||
UUID messageUUID = new UUID(msg.readLong(), msg.readLong());
|
|
||||||
|
|
||||||
if (messageUUID.equals(serverUUID)) {
|
if (messageUUID.equals(serverUUID)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = new UUID(msg.readLong(), msg.readLong());
|
long mostUser = input.readLong();
|
||||||
|
long leastUser = input.readLong();
|
||||||
|
|
||||||
this.receiveMessage(uuid, key, msg);
|
UUID userUUID = new UUID(mostUser, leastUser);
|
||||||
|
|
||||||
|
this.receiveMessage(userUUID, channel, input);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void receiveMessage(UUID uuid, String key, ByteArrayDataInput value) {
|
private void receiveMessage(UUID uuid, String key, ByteArrayDataInput value) {
|
||||||
|
|||||||
Reference in new issue
Block a user