|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.bedrock; |
|
|
|
import com.nukkitx.nbt.NbtMap; |
|
import com.nukkitx.nbt.NbtMapBuilder; |
|
import com.nukkitx.nbt.NbtType; |
|
import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBClientRequestPacket; |
|
import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBServerBroadcastPacket; |
|
import it.unimi.dsi.fastutil.ints.IntArrayList; |
|
import it.unimi.dsi.fastutil.ints.IntList; |
|
import org.geysermc.connector.network.session.GeyserSession; |
|
import org.geysermc.connector.network.translators.PacketTranslator; |
|
import org.geysermc.connector.network.translators.Translator; |
|
import org.geysermc.connector.utils.DimensionUtils; |
|
import org.geysermc.connector.utils.LoadstoneTracker; |
|
|
|
@Translator(packet = PositionTrackingDBClientRequestPacket.class) |
|
public class BedrockPositionTrackingDBClientRequestTranslator extends PacketTranslator<PositionTrackingDBClientRequestPacket> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void translate(GeyserSession session, PositionTrackingDBClientRequestPacket packet) { |
|
PositionTrackingDBServerBroadcastPacket broadcastPacket = new PositionTrackingDBServerBroadcastPacket(); |
|
broadcastPacket.setTrackingId(packet.getTrackingId()); |
|
|
|
|
|
LoadstoneTracker.LoadstonePos pos = LoadstoneTracker.getPos(packet.getTrackingId()); |
|
|
|
|
|
if (pos == null) { |
|
broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.NOT_FOUND); |
|
session.sendUpstreamPacket(broadcastPacket); |
|
return; |
|
} |
|
|
|
broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.UPDATE); |
|
|
|
|
|
NbtMapBuilder builder = NbtMap.builder(); |
|
builder.putInt("dim", DimensionUtils.javaToBedrock(pos.getDimension())); |
|
builder.putString("id", String.format("%08X", packet.getTrackingId())); |
|
|
|
builder.putByte("version", (byte) 1); |
|
builder.putByte("status", (byte) 0); |
|
|
|
|
|
IntList posList = new IntArrayList(); |
|
posList.add(pos.getX()); |
|
posList.add(pos.getY()); |
|
posList.add(pos.getZ()); |
|
builder.putList("pos", NbtType.INT, posList); |
|
broadcastPacket.setTag(builder.build()); |
|
|
|
session.sendUpstreamPacket(broadcastPacket); |
|
} |
|
} |
|
|