Skip to content

Commit

Permalink
Separate the packet id from the rest of the packet data
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Dec 16, 2021
1 parent a68f400 commit b234fbe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 19 additions & 2 deletions api/src/main/java/org/geysermc/floodgate/api/unsafe/Unsafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@
import org.geysermc.floodgate.api.player.FloodgatePlayer;

public interface Unsafe {
void sendPacket(UUID bedrockPlayer, byte[] packetData);
void sendPacket(FloodgatePlayer player, byte[] packetData);
/**
* Send a raw Bedrock packet to the given online Bedrock player.
*
* @param bedrockPlayer the uuid of the online Bedrock player
* @param packetId the id of the packet to send
* @param packetData the raw packet data
*/
void sendPacket(UUID bedrockPlayer, int packetId, byte[] packetData);

/**
* Send a raw Bedrock packet to the given online Bedrock player.
*
* @param player the Bedrock player to send the packet to
* @param packetId the id of the packet to send
* @param packetData the raw packet data
*/
default void sendPacket(FloodgatePlayer player, int packetId, byte[] packetData) {
sendPacket(player.getCorrectUniqueId(), packetId, packetData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package org.geysermc.floodgate.api;

import java.util.UUID;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.geysermc.floodgate.api.unsafe.Unsafe;
import org.geysermc.floodgate.pluginmessage.PluginMessageManager;
import org.geysermc.floodgate.pluginmessage.channel.PacketChannel;
Expand All @@ -44,12 +43,11 @@ public final class UnsafeFloodgateApi implements Unsafe {
}

@Override
public void sendPacket(UUID bedrockPlayer, byte[] packetData) {
packetChannel.sendPacket(bedrockPlayer, packetData, this);
}
public void sendPacket(UUID bedrockPlayer, int packetId, byte[] packetData) {
byte[] fullData = new byte[packetData.length + 1];
fullData[0] = (byte) packetId;
System.arraycopy(packetData, 0, fullData, 1, packetData.length);

@Override
public void sendPacket(FloodgatePlayer player, byte[] packetData) {
sendPacket(player.getCorrectUniqueId(), packetData);
packetChannel.sendPacket(bedrockPlayer, fullData, this);
}
}

0 comments on commit b234fbe

Please sign in to comment.